[FIX] stock: fix blocking generate lots name

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 <arm@odoo.com>
Signed-off-by: Rémy Voet <ryv@odoo.com>
This commit is contained in:
Rémy Voet (ryv)
2021-11-19 14:24:02 +00:00
parent 9ff1e76735
commit ec05e72dcf
2 changed files with 7 additions and 5 deletions
+2 -2
View File
@@ -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.
@@ -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