diff --git a/stock_picking_location_check/models/__init__.py b/stock_picking_location_check/models/__init__.py index ae4c2722..3c71fd1b 100644 --- a/stock_picking_location_check/models/__init__.py +++ b/stock_picking_location_check/models/__init__.py @@ -1 +1,2 @@ from . import stock_picking +from . import stock_move diff --git a/stock_picking_location_check/models/stock_move.py b/stock_picking_location_check/models/stock_move.py new file mode 100644 index 00000000..42f766c0 --- /dev/null +++ b/stock_picking_location_check/models/stock_move.py @@ -0,0 +1,60 @@ +# Copyright 2024 Quartile Limited +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) + +import logging + +from odoo import fields, models + +_logger = logging.getLogger(__name__) + + +class StockMove(models.Model): + _inherit = "stock.move" + + allow_location_inconsistency = fields.Boolean( + compute="_compute_allow_location_inconsistency" + ) + + def _compute_allow_location_inconsistency(self): + for move in self: + move.allow_location_inconsistency = False + domain = [ + ("location_dest_id", "=", move.location_dest_id.id), + ("action", "in", ("push", "pull_push")), + ] + warehouse_id = ( + move.warehouse_id or move.picking_id.picking_type_id.warehouse_id + ) + if move.location_dest_id.company_id == self.env.company: + rule = self.env["procurement.group"]._search_rule( + move.route_ids, + move.product_packaging_id, + move.product_id, + warehouse_id, + domain, + ) + else: + move_with_context = move.with_context( + allowed_companies=self.env.user.company_ids.ids + ) + rule = ( + self.env["procurement.group"] + .sudo() + ._search_rule( + move_with_context.route_ids, + move_with_context.product_packaging_id, + move_with_context.product_id, + False, + domain, + ) + ) + if ( + rule + and ( + not move.origin_returned_move_id + or move.origin_returned_move_id.location_dest_id.id + != rule.location_dest_id.id + ) + and rule.auto == "transparent" + ): + move.allow_location_inconsistency = True diff --git a/stock_picking_location_check/models/stock_picking.py b/stock_picking_location_check/models/stock_picking.py index 32b37887..9550da88 100644 --- a/stock_picking_location_check/models/stock_picking.py +++ b/stock_picking_location_check/models/stock_picking.py @@ -41,7 +41,10 @@ def _action_done(self): if not getattr(line.move_id, "is_subcontract", False) ] pick._check_location_consistency(pick.location_id, line_source_locations) - pick._check_location_consistency( - pick.location_dest_id, pick.move_line_ids.location_dest_id - ) + line_dest_locations = [ + line.location_dest_id + for line in pick.move_line_ids + if not line.move_id.allow_location_inconsistency + ] + pick._check_location_consistency(pick.location_dest_id, line_dest_locations) return super()._action_done()