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
  • Loading branch information
sebalix committed Jan 8, 2025
1 parent fa2bd36 commit ba9cdd8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions 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) <[email protected]>
# 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,18 @@ def write(self, vals):
res &= super(StockMoveLine, self - already_processed).write(vals)

if to_reassign_moves:
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)

return res

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 ba9cdd8

Please sign in to comment.