feat: Add automatic lot number generation for stock picking move lines based on product template sequences.
This commit is contained in:
parent
78da69b5dd
commit
4666a8c117
@ -2,4 +2,5 @@ from . import product_template
|
||||
from . import stock_move
|
||||
from . import stock_lot
|
||||
from . import stock_move_line
|
||||
from . import mrp_production
|
||||
from . import mrp_production
|
||||
from . import stock_picking
|
||||
34
models/stock_picking.py
Normal file
34
models/stock_picking.py
Normal file
@ -0,0 +1,34 @@
|
||||
from odoo import models
|
||||
|
||||
class StockPicking(models.Model):
|
||||
_inherit = 'stock.picking'
|
||||
|
||||
def action_auto_generate_lots_subcontract(self):
|
||||
"""
|
||||
Auto-generate lot names for move lines in this picking that:
|
||||
1. Have a product with tracking enabled (serial or lot).
|
||||
2. Have an empty 'lot_name' and no 'lot_id'.
|
||||
3. Have a product template with a configured 'lot_sequence_id'.
|
||||
"""
|
||||
for picking in self:
|
||||
# We iterate over move_line_ids (operations)
|
||||
# Filter for lines that need a lot generated
|
||||
lines_to_process = picking.move_line_ids.filtered(
|
||||
lambda ml: (
|
||||
ml.product_id
|
||||
and ml.product_id.tracking in ('serial', 'lot')
|
||||
and not ml.lot_name
|
||||
and not ml.lot_id
|
||||
and getattr(ml.product_id.product_tmpl_id, 'lot_sequence_id', False)
|
||||
)
|
||||
)
|
||||
|
||||
for line in lines_to_process:
|
||||
# Get the sequence from the product template
|
||||
seq = line.product_id.product_tmpl_id.lot_sequence_id
|
||||
if seq:
|
||||
# strict=True ensures we skip if next_by_id fails, though usually it returns None/False
|
||||
new_lot_name = seq.next_by_id()
|
||||
if new_lot_name:
|
||||
line.lot_name = new_lot_name
|
||||
return True
|
||||
Loading…
Reference in New Issue
Block a user