From 339496a1ac176b19701c728f8313ec66c6338eda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Tue, 2 May 2023 12:43:43 +0200 Subject: [PATCH] [FIX] delivery_multi_destination: Avoid error in creation of a multiple carrier with UX TT42837 --- delivery_multi_destination/models/delivery_carrier.py | 6 ++++++ .../tests/test_delivery_multi_destination.py | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/delivery_multi_destination/models/delivery_carrier.py b/delivery_multi_destination/models/delivery_carrier.py index c4a95146e4..2db9604809 100644 --- a/delivery_multi_destination/models/delivery_carrier.py +++ b/delivery_multi_destination/models/delivery_carrier.py @@ -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"): diff --git a/delivery_multi_destination/tests/test_delivery_multi_destination.py b/delivery_multi_destination/tests/test_delivery_multi_destination.py index 2ffd948dc6..4fc63f5d7a 100644 --- a/delivery_multi_destination/tests/test_delivery_multi_destination.py +++ b/delivery_multi_destination/tests/test_delivery_multi_destination.py @@ -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)