summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Martinelli <nim@odoo.com>2020-04-10 08:24:44 +0000
committerNicolas Martinelli <nim@odoo.com>2020-04-10 12:16:26 +0000
commit0a1ed9be1e3757ed0fc7a8f52e382f77dfb4cd8e (patch)
tree4637dcaae6a5a2a45538aacbbddafdd2fb1e50a0
parentd71d074082172e841dd38632f9debd11a75abe59 (diff)
[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>
-rw-r--r--addons/stock/models/stock_move.py5
-rw-r--r--addons/stock/tests/test_generate_serial_numbers.py25
2 files changed, 28 insertions, 2 deletions
diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py
index 5df92d3ffb6..f59e96f08c9 100644
--- a/addons/stock/models/stock_move.py
+++ b/addons/stock/models/stock_move.py
@@ -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 = []
diff --git a/addons/stock/tests/test_generate_serial_numbers.py b/addons/stock/tests/test_generate_serial_numbers.py
index 1c3e79454f1..42e678a3a3e 100644
--- a/addons/stock/tests/test_generate_serial_numbers.py
+++ b/addons/stock/tests/test_generate_serial_numbers.py
@@ -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.
"""