[FIX] stock: SN sequence
Steps to reproduce: - Create a serial tracked product - Update quantity add random SN - Edit "ir.sequence" for serial numbers (search sequence with dev mode enabled) - Add a prefix for exemple "xx%(doy)sxx" - Manufacture the product and generate new serial Bug: if a serial already exist next number in the sequence will be generated instead of using the sequence Fix: apply same logic than for lots i.e. first generate from sequence then take next number if it already exists opw-3291532 closes odoo/odoo#134879 X-original-commit: df96d9ca10c576981f6af79e330b5b46cdeea377 Signed-off-by: William Henrotin (whe) <whe@odoo.com> Signed-off-by: Walid Hanniche (waha) <waha@odoo.com>
This commit is contained in:
@@ -1306,17 +1306,14 @@ class MrpProduction(models.Model):
|
||||
|
||||
def _prepare_stock_lot_values(self):
|
||||
self.ensure_one()
|
||||
if self.product_id.tracking == 'lot':
|
||||
name = self.env['ir.sequence'].next_by_code('stock.lot.serial')
|
||||
exist_lot = self.env['stock.lot'].search([
|
||||
('product_id', '=', self.product_id.id),
|
||||
('company_id', '=', self.company_id.id),
|
||||
('name', '=', name),
|
||||
], limit=1)
|
||||
if exist_lot:
|
||||
name = self.env['stock.lot']._get_next_serial(self.company_id, self.product_id)
|
||||
else:
|
||||
name = self.env['stock.lot']._get_next_serial(self.company_id, self.product_id) or self.env['ir.sequence'].next_by_code('stock.lot.serial')
|
||||
name = self.env['ir.sequence'].next_by_code('stock.lot.serial')
|
||||
exist_lot = self.env['stock.lot'].search([
|
||||
('product_id', '=', self.product_id.id),
|
||||
('company_id', '=', self.company_id.id),
|
||||
('name', '=', name),
|
||||
], limit=1)
|
||||
if exist_lot:
|
||||
name = self.env['stock.lot']._get_next_serial(self.company_id, self.product_id)
|
||||
return {
|
||||
'product_id': self.product_id.id,
|
||||
'company_id': self.company_id.id,
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
from odoo.tests import Form
|
||||
from odoo.addons.mrp.tests.common import TestMrpCommon
|
||||
|
||||
from datetime import datetime
|
||||
import logging
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
@@ -631,3 +633,21 @@ class TestTraceability(TestMrpCommon):
|
||||
mo.action_generate_serial()
|
||||
lot_2 = mo.lot_producing_id.name
|
||||
self.assertEqual(lot_2, str(int(lot_1) + 1).zfill(7))
|
||||
|
||||
def test_generate_serial_button_sequence(self):
|
||||
"""Test if serial in form "00000dd" is manually created, the generate serial
|
||||
correctly create new serial from sequence.
|
||||
"""
|
||||
seq = self.env['ir.sequence'].search([('code', '=', 'stock.lot.serial')])
|
||||
seq.prefix = 'xx%(doy)sxx'
|
||||
mo, _bom, p_final, _p1, _p2 = self.generate_mo(qty_base_1=1, qty_base_2=1, qty_final=1, tracking_final='serial')
|
||||
|
||||
# manually create lot_1
|
||||
self.env['stock.lot'].create({
|
||||
'name': "test_000",
|
||||
'product_id': p_final.id,
|
||||
'company_id': self.env.company.id,
|
||||
})
|
||||
# generate serial lot_2 from the MO
|
||||
mo.action_generate_serial()
|
||||
self.assertIn(datetime.now().strftime('%j'), mo.lot_producing_id.name)
|
||||
|
||||
Reference in New Issue
Block a user