Skip to content

[4613][FIX] stock_picking_location_check #149

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

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions stock_picking_location_check/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import stock_picking
from . import stock_move
60 changes: 60 additions & 0 deletions stock_picking_location_check/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -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
9 changes: 6 additions & 3 deletions stock_picking_location_check/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Loading