-
-
Notifications
You must be signed in to change notification settings - Fork 707
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prod_lot_seq: Fix sequence incrementation opening detailed operations
When opening the detailed operations view of a stock move, Odoo is calling stock.production.lot._get_next_serial to set stock.move.next_serial field anytime the product is tracked by serial and the move is assigned. If we use this module with product or global policy, the respective sequence will therefore be called and incremented anytime this view is open, even if the picking is not creating lots (e.g. delivery orders or internal transfers) To avoid incrementing the sequence unnecessarily, we only allow to get the next sequence number the first time this view is opened and if the move has to create new serial numbers. Otherwise, we force the value to be set to stock.move.next_serial field to an empty string if no serial has to be created through this move, or to the next_serial value assigned on the first opening of the view.
- Loading branch information
1 parent
5ec1421
commit ca381bd
Showing
4 changed files
with
75 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from . import product | ||
from . import stock_production_lot | ||
from . import stock_move |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright 2023 Camptocamp SA | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
from odoo import models | ||
|
||
|
||
class StockMove(models.Model): | ||
_inherit = "stock.move" | ||
|
||
def action_show_details(self): | ||
"""Avoid calling and incrementing the sequence if not needed or already done""" | ||
seq_policy = self.env["stock.production.lot"]._get_sequence_policy() | ||
if seq_policy in ("product", "global"): | ||
# If move is not supposed to assign serial pass empty string for next serial | ||
if not self.display_assign_serial: | ||
return super( | ||
StockMove, self.with_context(force_next_serial="") | ||
).action_show_details() | ||
# If the sequence was already called once, avoid calling it another time | ||
elif self.next_serial: | ||
return super( | ||
StockMove, self.with_context(force_next_serial=self.next_serial) | ||
).action_show_details() | ||
return super().action_show_details() |
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
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