diff --git a/addons/stock/models/stock_production_lot.py b/addons/stock/models/stock_production_lot.py index 4a8068b2936..870d061f0fe 100644 --- a/addons/stock/models/stock_production_lot.py +++ b/addons/stock/models/stock_production_lot.py @@ -40,8 +40,8 @@ class ProductionLot(models.Model): # We look if the first lot contains at least one digit. caught_initial_number = regex_findall(r"\d+", first_lot) if not caught_initial_number: - raise UserError(_('The lot name must contain at least one digit.')) - # We base the serie on the last number found in the base lot. + return self.generate_lot_names(first_lot + "0", count) + # We base the series on the last number found in the base lot. initial_number = caught_initial_number[-1] padding = len(initial_number) # We split the lot name to get the prefix and suffix. diff --git a/addons/stock/tests/test_generate_serial_numbers.py b/addons/stock/tests/test_generate_serial_numbers.py index 07cb40cfaa7..ff1e25fc3fa 100644 --- a/addons/stock/tests/test_generate_serial_numbers.py +++ b/addons/stock/tests/test_generate_serial_numbers.py @@ -191,15 +191,17 @@ class StockGenerate(TransactionCase): default_move_id=move.id, default_next_serial_number='code-xxx', )) - wiz = form_wizard.save() - with self.assertRaises(UserError): - wiz.generate_serial_numbers() form_wizard.next_serial_count = 0 # Must raise an exception because `next_serial_count` must be greater than 0. with self.assertRaises(ValidationError): form_wizard.save() + form_wizard.next_serial_count = 3 + wiz = form_wizard.save() + wiz.generate_serial_numbers() + self.assertEqual(move.move_line_nosuggest_ids.mapped('lot_name'), ["code-xxx0", "code-xxx1", "code-xxx2"]) + def test_generate_04_generate_in_multiple_time(self): """ Generates a Serial Number for each move lines (except the last one) but with multiple assignments, and checks the generated Serial Numbers