diff --git a/addons/mrp/tests/test_traceability.py b/addons/mrp/tests/test_traceability.py index 946d4ef98b3..221c31b8aa8 100644 --- a/addons/mrp/tests/test_traceability.py +++ b/addons/mrp/tests/test_traceability.py @@ -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)) diff --git a/addons/stock/models/stock_lot.py b/addons/stock/models/stock_lot.py index 0a7edbba7e5..7edcb7e15cd 100644 --- a/addons/stock/models/stock_lot.py +++ b/addons/stock/models/stock_lot.py @@ -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')