-
-
Notifications
You must be signed in to change notification settings - Fork 671
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stock_move_line_change_lot: add hooks before/after moves reservation
- Loading branch information
Showing
1 changed file
with
16 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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): | ||
|
@@ -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) | ||
|
@@ -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 |