diff --git a/addons/mrp/i18n/mrp.pot b/addons/mrp/i18n/mrp.pot index 5123568e86d..c85998a4bc1 100644 --- a/addons/mrp/i18n/mrp.pot +++ b/addons/mrp/i18n/mrp.pot @@ -3249,6 +3249,12 @@ msgstr "" msgid "You cannot cancel a move move having already consumed material" msgstr "" +#. module: mrp +#: code:addons/mrp/models/stock_move.py:40 +#, python-format +msgid "You cannot use the same serial number in two different lines." +msgstr "" + #. module: mrp #: code:addons/mrp/wizard/change_production_qty.py:44 #, python-format diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py index 3c6a99fa6eb..608d11e9bce 100644 --- a/addons/mrp/models/stock_move.py +++ b/addons/mrp/models/stock_move.py @@ -28,6 +28,16 @@ class StockMoveLots(models.Model): done_move = fields.Boolean('Move Done', related='move_id.is_done', store=True) # TDE FIXME: naming plus_visible = fields.Boolean("Plus Visible", compute='_compute_plus') + @api.one + @api.constrains('lot_id') + def _check_lot_id(self): + if self.move_id.product_id.tracking == 'serial': + lots = set([]) + for move_lot in self.move_id.move_lot_ids.filtered(lambda r: not r.lot_produced_id): + if move_lot.lot_id in lots: + raise exceptions.UserError(_('You cannot use the same serial number in two different lines.')) + lots.add(move_lot.lot_id) + def _compute_plus(self): for movelot in self: if movelot.move_id.product_id.tracking == 'serial': diff --git a/addons/mrp/wizard/mrp_product_produce.py b/addons/mrp/wizard/mrp_product_produce.py index f6a70c4a1f6..b7cd863a5fc 100644 --- a/addons/mrp/wizard/mrp_product_produce.py +++ b/addons/mrp/wizard/mrp_product_produce.py @@ -125,8 +125,8 @@ class MrpProductProduce(models.TransientModel): #Possibly the entire move is selected remaining_qty = movelots.quantity - movelots.quantity_done if remaining_qty > 0: - new_move_lot = movelots.copy() - new_move_lot.write({'quantity':movelots.quantity_done, 'lot_produced_id': self.lot_id.id}) + default = {'quantity': movelots.quantity_done, 'lot_produced_id': self.lot_id.id} + new_move_lot = movelots.copy(default=default) movelots.write({'quantity': remaining_qty, 'quantity_done': 0}) else: movelots.write({'lot_produced_id': self.lot_id.id})