[FIX] mrp: SN sequence
Since commit[1] Serial number sequence rule takes priority over already existing Serial numbers Bug: when disabling default Serial number sequence rule a validation error is thrown since lot name is now empty Fix: fall back on the previous behaviour (get next SerialNumber) if sequence is not set (also added a clearer user error if neither is set) note also updated the .pot file opw-3514794 [1]:https://github.com/odoo/odoo/pull/134187 closes odoo/odoo#137756 X-original-commit: 68d670a27be7baaaf53b0cf491234f8e0453d7f2 Signed-off-by: William Henrotin (whe) <whe@odoo.com> Signed-off-by: Walid Hanniche (waha) <waha@odoo.com>
This commit is contained in:
@@ -3581,6 +3581,13 @@ msgstr ""
|
||||
msgid "Plastic Laminate"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp
|
||||
#. odoo-python
|
||||
#: code:addons/mrp/models/mrp_production.py:0
|
||||
#, python-format
|
||||
msgid "Please set the first Serial Number or a default sequence"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp
|
||||
#: model:product.template,name:mrp.product_product_wood_ply_product_template
|
||||
msgid "Ply Layer"
|
||||
|
||||
@@ -1351,13 +1351,15 @@ class MrpProduction(models.Model):
|
||||
def _prepare_stock_lot_values(self):
|
||||
self.ensure_one()
|
||||
name = self.env['ir.sequence'].next_by_code('stock.lot.serial')
|
||||
exist_lot = self.env['stock.lot'].search([
|
||||
exist_lot = not name or 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)
|
||||
if not name:
|
||||
raise UserError(_("Please set the first Serial Number or a default sequence"))
|
||||
return {
|
||||
'product_id': self.product_id.id,
|
||||
'company_id': self.company_id.id,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
from odoo.tests import Form
|
||||
from odoo.addons.mrp.tests.common import TestMrpCommon
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
from datetime import datetime
|
||||
import logging
|
||||
@@ -639,15 +640,26 @@ class TestTraceability(TestMrpCommon):
|
||||
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')
|
||||
|
||||
seq.active = False
|
||||
# No initial serial and No default sequence
|
||||
with self.assertRaises(UserError):
|
||||
mo.action_generate_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
|
||||
|
||||
# generate serial lot_2 from the MO (next_serial)
|
||||
mo.action_generate_serial()
|
||||
self.assertEqual(mo.lot_producing_id.name, "test_001")
|
||||
|
||||
seq.active = True
|
||||
seq.prefix = 'xx%(doy)sxx'
|
||||
# generate serial lot_3 from the MO (next from sequence)
|
||||
mo.action_generate_serial()
|
||||
self.assertIn(datetime.now().strftime('%j'), mo.lot_producing_id.name)
|
||||
|
||||
Reference in New Issue
Block a user