From 27f656a23e92df52b2f78fdd7c31b8c045b1f39b Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Mon, 13 Mar 2017 10:59:59 +0100 Subject: [PATCH] [FIX] mrp: duplicated raw materials - Create Product A with a BOM which depends on a product with tracking "By Unique Serial Number" (Product B). - Create a MO for Product A - In the "Register lots" wizard, add two lines for "Product B", with the same serial number. Nothing prevents the user to do it, even when the inventory is posted. opw-709888 --- addons/mrp/i18n/mrp.pot | 6 ++++++ addons/mrp/models/stock_move.py | 10 ++++++++++ addons/mrp/wizard/mrp_product_produce.py | 4 ++-- 3 files changed, 18 insertions(+), 2 deletions(-) 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})