Skip to content

Commit

Permalink
[FIX] stock_picing_location_check
Browse files Browse the repository at this point in the history
  • Loading branch information
AungKoKoLin1997 committed Jul 11, 2024
1 parent e6f3c42 commit a2ed1ab
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
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()

0 comments on commit a2ed1ab

Please sign in to comment.