diff --git a/sale_stock_release_channel_partner_by_date_delivery/models/sale_order.py b/sale_stock_release_channel_partner_by_date_delivery/models/sale_order.py index acd0291f78..dc7ea9f248 100644 --- a/sale_stock_release_channel_partner_by_date_delivery/models/sale_order.py +++ b/sale_stock_release_channel_partner_by_date_delivery/models/sale_order.py @@ -22,12 +22,15 @@ def _get_release_channel_id_depends(self): def _get_release_channel_partner_date_domain(self): domain = super()._get_release_channel_partner_date_domain() - if domain and self.carrier_id: - carrier_domain = [ - "|", - ("release_channel_id.carrier_ids", "in", self.carrier_id.ids), - ("release_channel_id.carrier_ids", "=", False), - ] + if domain: + if self.carrier_id: + carrier_domain = [ + ("release_channel_id.carrier_ids", "in", self.carrier_id.ids), + ] + else: + carrier_domain = [ + ("release_channel_id.carrier_ids", "=", False), + ] domain = expression.AND([domain, carrier_domain]) return domain diff --git a/sale_stock_release_channel_partner_by_date_delivery/tests/test_sale_release_channel.py b/sale_stock_release_channel_partner_by_date_delivery/tests/test_sale_release_channel.py index 08b91d7860..ecfcb8373d 100644 --- a/sale_stock_release_channel_partner_by_date_delivery/tests/test_sale_release_channel.py +++ b/sale_stock_release_channel_partner_by_date_delivery/tests/test_sale_release_channel.py @@ -34,10 +34,9 @@ def setUpClass(cls): def test_sale_order_without_carrier_with_channel_date(self): delivery_date = fields.Datetime.now() - # Create one specific channel that is matching the SO even if no carrier is set - # FIXME: not sure about this one, to check how it should behave + # Create one specific channel not matching the SO regarding the carrier channel_date_model = self.env["stock.release.channel.partner.date"] - channel_date = channel_date_model.create( + channel_date_model.create( { "partner_id": self.customer.id, "release_channel_id": self.carrier_channel.id, @@ -46,14 +45,13 @@ def test_sale_order_without_carrier_with_channel_date(self): ) order = self._create_sale_order(date=delivery_date) self.assertFalse(order.carrier_id) - self.assertEqual(order.release_channel_id, self.carrier_channel) + self.assertFalse(order.release_channel_id) order.action_confirm() - self.assertEqual(order.release_channel_id, self.carrier_channel) - self.assertEqual(order._get_release_channel_partner_date(), channel_date) + self.assertFalse(order.release_channel_id) + self.assertFalse(order._get_release_channel_partner_date()) picking_out = order.picking_ids self.assertFalse(picking_out.release_channel_id) # Then delivery gets the default channel - # FIXME it's not the expected channel from the user POV self.env["stock.release.channel"].assign_release_channel(picking_out) self.assertEqual(picking_out.release_channel_id, self.default_channel) @@ -114,7 +112,9 @@ def test_sale_order_with_incompatible_channel_and_carrier_1(self): "date": delivery_date.date(), } ) - order = self._create_sale_order(date=delivery_date) + order = self._create_sale_order( + date=delivery_date, channel=self.carrier_channel + ) self.assertEqual(order.release_channel_id, self.carrier_channel) # => select a carrier order.carrier_id = self.carrier2 @@ -144,7 +144,9 @@ def test_sale_order_with_incompatible_channel_and_carrier_2(self): "date": delivery_date.date(), } ) - order = self._create_sale_order(date=delivery_date) + order = self._create_sale_order( + date=delivery_date, channel=self.carrier_channel + ) self.assertEqual(order.release_channel_id, self.carrier_channel) channel_date_model = self.env["stock.release.channel.partner.date"] channel_date = channel_date_model.create(