[FIX] mrp: duplicate lot when auto-generate serial
Previous commit 1b840d066999bde1f05563567f439967770701ca tried to fix the issue action_generate_serial may try to generate a existing lot. But it made the lot number completely product specific. This change is too big for stable, we revert the change in this commit. Also to fix the issue, when action_generate_serial tries to generate a lot, we always try the result from ir.sequence frist, only when the lot already exists, we then try create one based on the product's lastest lot number. Task-3187003 closes odoo/odoo#121214 X-original-commit: 95214ab6c133553371926804e788766edab2b8ca Signed-off-by: Arnold Moyaux (arm) <arm@odoo.com> Signed-off-by: Yuchen Huang (yhu) <yhu@odoo.com>
This commit is contained in:
@@ -1211,10 +1211,21 @@ class MrpProduction(models.Model):
|
||||
|
||||
def action_generate_serial(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')
|
||||
self.lot_producing_id = self.env['stock.lot'].create({
|
||||
'product_id': self.product_id.id,
|
||||
'company_id': self.company_id.id,
|
||||
'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': name,
|
||||
})
|
||||
if self.product_id.tracking == 'serial':
|
||||
self._set_qty_producing()
|
||||
|
||||
Reference in New Issue
Block a user