From ec05e72dcf40afe3fdb496166343114ede48f36a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Voet=20=28ryv=29?= Date: Fri, 8 Oct 2021 14:41:25 +0000 Subject: [PATCH] [FIX] stock: fix blocking generate lots name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue, to reproduce: - Create a product A tracked by serial - Reciept one product A with a lot without digit - validate this receipt, Ok - Create a other receipt for product A, - You cannot anymore open the detail wizard to enter a SN/lot : get 'The lot name must contain at least one digit.' Fix: Remove the constraint and fallback by adding "0" at the end. task-2652292 closes odoo/odoo#80104 X-original-commit: 5f75d5b1c8d5d4f37cbdc34daa79514226a17855 Signed-off-by: Arnold Moyaux Signed-off-by: Rémy Voet --- addons/stock/models/stock_production_lot.py | 4 ++-- addons/stock/tests/test_generate_serial_numbers.py | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) 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