Skip to content

Commit f963497

Browse files
victoralmauGabbasovDinar
authored andcommitted
[FIX] delivery_multi_destination: Avoid error in creation of a multiple carrier with UX
TT42837
1 parent 606a670 commit f963497

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

delivery_multi_destination/models/delivery_carrier.py

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ class DeliveryCarrier(models.Model):
2929
required=True,
3030
)
3131

32+
@api.onchange("destination_type", "child_ids")
33+
def _onchange_destination_type(self):
34+
"""Define the corresponding value to avoid creation error with UX."""
35+
if self.destination_type == "multi" and self.child_ids and not self.product_id:
36+
self.product_id = fields.first(self.child_ids.product_id)
37+
3238
def search(self, args, offset=0, limit=None, order=None, count=False):
3339
"""Don't show by default children carriers."""
3440
if not self.env.context.get("show_children_carriers"):

delivery_multi_destination/tests/test_delivery_multi_destination.py

+10
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,13 @@ def test_picking_validation(self):
166166
picking.move_lines.quantity_done = 1
167167
picking._action_done()
168168
self.assertAlmostEqual(picking.carrier_price, 50)
169+
170+
def test_delivery_carrier_multi_form(self):
171+
carrier_form = Form(self.env["delivery.carrier"])
172+
carrier_form.name = "Multi carrier"
173+
carrier_form.destination_type = "multi"
174+
with carrier_form.child_ids.new() as child_form:
175+
child_form.name = "Child carrier"
176+
child_form.product_id = self.product_child_1
177+
carrier = carrier_form.save()
178+
self.assertEqual(carrier.product_id, self.product_child_1)

0 commit comments

Comments
 (0)