[FIX] stock: SN generation

The generation of SN is incorrect with the following initial sequence:
`BAV023B00001S00001`.
Indeed, the sequence generated is: `BAV023B00001S`, `BAV023B00002S`.

This occurs because the same digits `00001` appear more than once.

opw-2230913

closes odoo/odoo#49408

X-original-commit: b3369bc230160d6cafec77eed0e756c6f1c576d9
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
Nicolas Martinelli
2020-04-10 12:16:26 +00:00
parent d71d074082
commit 0a1ed9be1e
2 changed files with 28 additions and 2 deletions
+3 -2
View File
@@ -638,8 +638,9 @@ class StockMove(models.Model):
padding = len(initial_number)
# We split the serial number to get the prefix and suffix.
splitted = regex_split(initial_number, self.next_serial)
prefix = splitted[0]
suffix = splitted[1]
# initial_number could appear several times in the SN, e.g. BAV023B00001S00001
prefix = initial_number.join(splitted[:-1])
suffix = splitted[-1]
initial_number = int(initial_number)
lot_names = []
@@ -158,6 +158,31 @@ class StockGenerate(SavepointCase):
generated_numbers.pop(0)
)
# Case #4: Prefix + suffix, identical number pattern
move = self.get_new_move(nbre_of_lines)
form_wizard = Form(self.env['stock.assign.serial'].with_context(
default_move_id=move.id,
default_next_serial_number='BAV023B00001S00001',
default_next_serial_count=nbre_of_lines,
))
wiz = form_wizard.save()
wiz.generate_serial_numbers()
# Checks all move lines have the right SN
generated_numbers = [
'BAV023B00001S00001', 'BAV023B00001S00002', 'BAV023B00001S00003',
'BAV023B00001S00004', 'BAV023B00001S00005', 'BAV023B00001S00006',
'BAV023B00001S00007', 'BAV023B00001S00008', 'BAV023B00001S00009',
'BAV023B00001S00010'
]
for move_line in move.move_line_nosuggest_ids:
# For a product tracked by SN, the `qty_done` is set on 1 when
# `lot_name` is set.
self.assertEqual(move_line.qty_done, 1)
self.assertEqual(
move_line.lot_name,
generated_numbers.pop(0)
)
def test_generate_03_raise_exception(self):
""" Tries to generate some SN but with invalid initial number.
"""