diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 13aac4c6683..0ea7685d0ea 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -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()