Skip to content

[16.0][FIX] stock_release_channel_partner_by_date: properly detect the exception #999

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

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
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ class TestSaleReleaseChannel(SaleReleaseChannelCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.wh = cls.env.ref("stock.warehouse0")
cls.carrier = cls.env.ref("delivery.delivery_carrier")
cls.carrier2 = cls.env.ref("delivery.delivery_local_delivery")
cls.carrier_channel = cls.default_channel.copy(
{
"name": "Test with carrier",
"sequence": 10,
"warehouse_id": cls.wh.id,
"carrier_ids": [(6, 0, cls.carrier.ids)],
}
)
Expand Down
18 changes: 16 additions & 2 deletions stock_release_channel/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,33 @@ def _find_release_channel_possible_candidate(self):
)

def _get_release_channel_possible_candidate_domain_channel(self):
"""Domain for finding channel candidates based on channel.

The condition is defined by the channel.
"""
return [
("is_manual_assignment", "=", False),
("state", "!=", "asleep"),
"|",
("picking_type_ids", "=", False),
("picking_type_ids", "in", self.picking_type_id.ids),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it expected to use picking data in _get_release_channel_possible_candidate_domain_channel domain hook? I thought we designed it for basic criteria selection of the channel (like the ones already defined) without relying on current picking. For that we have _get_release_channel_possible_candidate_domain_picking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a domain to find out that the exception is valid for that warehouse & carrier but not picking type as it could be recomputed by the warehouse flow module.
I'll add docstring to those methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the docstrings

]

def _get_release_channel_possible_candidate_domain_picking(self):
"""Domain for finding channel candidates based on picking.

The condition is defined by the picking.
"""
# when a warehouse is defined on the channel, it must always match
# otherwise fallback on the picking type
return [
("company_id", "=", self.company_id.id),
"|",
"&",
("warehouse_id", "=", False),
"|",
("picking_type_ids", "=", False),
("picking_type_ids", "in", self.picking_type_id.ids),
"|",
("warehouse_id", "=", False),
("warehouse_id", "=", self.picking_type_id.warehouse_id.id),
]

Expand Down
30 changes: 30 additions & 0 deletions stock_release_channel_partner_by_date/tests/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2024 Camptocamp SA
# Copyright 2024 Jacques-Etienne Baudoux (BCIM) <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)


from odoo.addons.stock_release_channel.tests.test_release_channel_partner import (
ReleaseChannelPartnerCommon,
)


class ReleaseChannelPartnerDateCommon(ReleaseChannelPartnerCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.delivery_date_channel = cls.partner_channel.copy(
{
"name": "Specific Date Channel",
"warehouse_id": cls.wh.id,
}
)

def _create_channel_partner_date(self, channel, partner, date):
rc_date_model = self.env["stock.release.channel.partner.date"]
return rc_date_model.create(
{
"partner_id": partner.id,
"release_channel_id": channel.id,
"date": date,
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,10 @@

from odoo import fields

from odoo.addons.stock_release_channel.tests.test_release_channel_partner import (
ReleaseChannelPartnerCommon,
)
from .common import ReleaseChannelPartnerDateCommon


class TestReleaseChannelPartnerDate(ReleaseChannelPartnerCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.delivery_date_channel = cls.partner_channel.copy(
{"name": "Specific Date Channel"}
)

def _create_channel_partner_date(self, channel, partner, date):
rc_date_model = self.env["stock.release.channel.partner.date"]
return rc_date_model.create(
{
"partner_id": partner.id,
"release_channel_id": channel.id,
"date": date,
}
)

class TestReleaseChannelPartnerDate(ReleaseChannelPartnerDateCommon):
def test_release_channel_on_specific_date(self):
"""partner specific date release channel is higher priority than other channels"""
self.delivery_date_channel.action_wake_up()
Expand All @@ -53,3 +34,21 @@ def test_release_channel_sleep_archive_specific_date(self):
self.assertTrue(channel_date.active)
self.delivery_date_channel.action_sleep()
self.assertFalse(channel_date.active)

def test_release_channel_on_specific_date_not_available(self):
"""Test that when no release channel is available to satisfy
a specific partner date,no fallback release channel is
proposed."""
# Exclude delivery channel from possible candidates
self.delivery_date_channel.picking_type_ids = self.env[
"stock.picking.type"
].search([("id", "!=", self.move.picking_id.picking_type_id.id)], limit=1)
scheduled_date = fields.Datetime.now()
self._create_channel_partner_date(
self.delivery_date_channel,
self.partner,
scheduled_date,
)
self.move.picking_id.scheduled_date = scheduled_date
self.move.picking_id.assign_release_channel()
self.assertFalse(self.move.picking_id.release_channel_id)
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
class StockPicking(models.Model):
_inherit = "stock.picking"

def _get_release_channel_possible_candidate_domain_picking(self):
def _get_release_channel_possible_candidate_domain_channel(self):
# Exclude deliveries (OUT pickings) when the date_deadline is after the shipment date
domain = super()._get_release_channel_possible_candidate_domain_picking()
domain = super()._get_release_channel_possible_candidate_domain_channel()

date = self.date_deadline
if date:
Expand Down