Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][FIX] delivery_multi_destination: Avoid error in creation of a multiple carrier with UX #636

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions delivery_multi_destination/models/delivery_carrier.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ class DeliveryCarrier(models.Model):
required=True,
)

@api.onchange("destination_type", "child_ids")
def _onchange_destination_type(self):
"""Define the corresponding value to avoid creation error with UX."""
if self.destination_type == "multi" and self.child_ids and not self.product_id:
self.product_id = fields.first(self.child_ids.product_id)

def search(self, args, offset=0, limit=None, order=None, count=False):
"""Don't show by default children carriers."""
if not self.env.context.get("show_children_carriers"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,13 @@ def test_picking_validation(self):
picking.move_lines.quantity_done = 1
picking._action_done()
self.assertAlmostEqual(picking.carrier_price, 50)

def test_delivery_carrier_multi_form(self):
carrier_form = Form(self.env["delivery.carrier"])
carrier_form.name = "Multi carrier"
carrier_form.destination_type = "multi"
with carrier_form.child_ids.new() as child_form:
child_form.name = "Child carrier"
child_form.product_id = self.product_child_1
carrier = carrier_form.save()
self.assertEqual(carrier.product_id, self.product_child_1)