Skip to content

Commit

Permalink
stock_move_line_change_lot: add hooks before/after moves reservation
Browse files Browse the repository at this point in the history
Port of hooks that were added in `shopfloor` 14.0 after that this module
was extracted from `shopfloor` during migration to 16.0:

- OCA/wms/pull/712/commits/c296499726f0f95082bfe40bfb0c137dfd2fb690
- OCA/wms/pull/945/commits/28d4a0116e9c891cd1f37e794e3a7643798260ac
  • Loading branch information
sebalix committed Jan 8, 2025
1 parent fa2bd36 commit 24fecbc
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion stock_move_line_change_lot/models/stock_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Copyright 2024 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from collections import defaultdict

from odoo import _, models
from odoo.exceptions import UserError
from odoo.tools.float_utils import float_compare
Expand Down Expand Up @@ -69,6 +71,7 @@ def write(self, vals):
res = True
already_processed = self.browse()
to_reassign_moves = self.env["stock.move"]
moves_by_previous_lot = defaultdict(self.env["stock.move"].browse)
lot = self.env["stock.lot"].browse(vals["lot_id"])
for move_line in self:
if move_line.move_id._should_bypass_reservation(move_line.location_id):
Expand All @@ -87,6 +90,7 @@ def write(self, vals):
package = move_line.package_id.browse(
vals.get("package_id", move_line.package_id)
)
moves_by_previous_lot[move_line.lot_id] |= move_line.move_id

available_quantity = 0
# Collect new lot inside or outside a package (strict=False)
Expand Down Expand Up @@ -161,6 +165,25 @@ def write(self, vals):
res &= super(StockMoveLine, self - already_processed).write(vals)

if to_reassign_moves:
to_reassign_moves._action_assign()
self._handle_change_lot_reassign(
lot, to_reassign_moves, moves_by_previous_lot
)

return res

def _handle_change_lot_reassign(
self, lot, to_reassign_moves, moves_by_previous_lot
):
for previous_lot, moves in moves_by_previous_lot.items():
moves &= to_reassign_moves
self._hook_change_lot_before_assign(previous_lot, lot, moves)
to_reassign_moves._action_assign()
for previous_lot, moves in moves_by_previous_lot.items():
moves &= to_reassign_moves
self._hook_change_lot_after_assign(previous_lot, lot, moves)

def _hook_change_lot_before_assign(self, previous_lot, lot, moves):
pass

def _hook_change_lot_after_assign(self, previous_lot, lot, moves):
pass

0 comments on commit 24fecbc

Please sign in to comment.