Skip to content

Commit

Permalink
fixup! sale_stock_release_channel_partner_by_date_delivery: fix compu…
Browse files Browse the repository at this point in the history
…tation of release channel
  • Loading branch information
sebalix committed Nov 29, 2024
1 parent c2196c5 commit be46bf4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit be46bf4

Please sign in to comment.