[FIX] mrp: duplicate lot when auto-generate serial.
To reproduce: 1. Manually create lot "0000001" for a lot product 2. Create a MO for this product and click generate-serial button. Validation error raised since we are trying to generate lot/sn "0000001" again. When useing action_generate_serial, ir.sequence always try create a lot/sn in form "00000dd". If user already created the same one, the generation will fail. We already tried to avoid this issue for sn in _get_next_serial() by finding the latest sn and create new one base on it. To fix, we also allow _get_next_serial to be applied to lot. Part of Tast-3187003 closes odoo/odoo#118481 X-original-commit: dc69748ea2698077782d839cf7da48e987f17ffc Signed-off-by: William Henrotin (whe) <whe@odoo.com> Signed-off-by: Yuchen Huang (yhu) <yhu@odoo.com>
This commit is contained in:
@@ -613,3 +613,25 @@ class TestTraceability(TestMrpCommon):
|
||||
{'product_id': self.bom_4.product_id.id, 'lot_id': False, 'qty_done': 1},
|
||||
{'product_id': component.id, 'lot_id': serial_number.id, 'qty_done': 1},
|
||||
])
|
||||
|
||||
def test_generate_serial_button(self):
|
||||
"""Test if lot in form "00000dd" is manually created, the generate serial
|
||||
button can skip it and create the next one.
|
||||
"""
|
||||
mo, _bom, p_final, _p1, _p2 = self.generate_mo(qty_base_1=1, qty_base_2=1, qty_final=1, tracking_final='lot')
|
||||
|
||||
# generate lot lot_0 on MO
|
||||
mo.action_generate_serial()
|
||||
lot_0 = mo.lot_producing_id.name
|
||||
# manually create lot_1 (lot_0 + 1)
|
||||
lot_1 = self.env['stock.lot'].create({
|
||||
'name': str(int(lot_0) + 1).zfill(7),
|
||||
'product_id': p_final.id,
|
||||
'company_id': self.env.company.id,
|
||||
}).name
|
||||
# generate lot lot_2 on a new MO
|
||||
mo = mo.copy()
|
||||
mo.action_confirm()
|
||||
mo.action_generate_serial()
|
||||
lot_2 = mo.lot_producing_id.name
|
||||
self.assertEqual(lot_2, str(int(lot_1) + 1).zfill(7))
|
||||
|
||||
@@ -63,7 +63,7 @@ class StockLot(models.Model):
|
||||
@api.model
|
||||
def _get_next_serial(self, company, product):
|
||||
"""Return the next serial number to be attributed to the product."""
|
||||
if product.tracking == "serial":
|
||||
if product.tracking != "none":
|
||||
last_serial = self.env['stock.lot'].search(
|
||||
[('company_id', '=', company.id), ('product_id', '=', product.id)],
|
||||
limit=1, order='id DESC')
|
||||
|
||||
Reference in New Issue
Block a user