From ee8fbcbeae43998fb04275d0bae53f50243b8465 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Mon, 27 Mar 2017 18:07:42 +0200 Subject: [PATCH] [FIX] mrp: same unique SN - Create a product with unique SN, create a BOM for this product - Create a MO to produce 2 units - Produce the first unit, create a lot number - Produce the second unit, use the previously created lot number Nothing prevents the user to do this. However, the user won't be able to set the MO as "Done", but it is better to prevent the issue as soon as possible. opw-724944 --- addons/mrp/i18n/mrp.pot | 8 +++++++- addons/mrp/models/stock_move.py | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/addons/mrp/i18n/mrp.pot b/addons/mrp/i18n/mrp.pot index c85998a4bc1..5e0eaf9128d 100644 --- a/addons/mrp/i18n/mrp.pot +++ b/addons/mrp/i18n/mrp.pot @@ -3244,7 +3244,13 @@ msgid "You can not delete a Bill of Material with running manufacturing orders.\ msgstr "" #. module: mrp -#: code:addons/mrp/models/stock_move.py:123 +#: code:addons/mrp/models/stock_move.py:40 +#, python-format +msgid "You can only produce 1.0 %s for products with unique serial number." +msgstr "" + +#. module: mrp +#: code:addons/mrp/models/stock_move.py:135 #, python-format msgid "You cannot cancel a move move having already consumed material" msgstr "" diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py index 608d11e9bce..5cb92a5025c 100644 --- a/addons/mrp/models/stock_move.py +++ b/addons/mrp/models/stock_move.py @@ -29,13 +29,15 @@ class StockMoveLots(models.Model): plus_visible = fields.Boolean("Plus Visible", compute='_compute_plus') @api.one - @api.constrains('lot_id') + @api.constrains('lot_id', 'quantity_done') 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.')) + if float_compare(move_lot.quantity_done, 1.0, precision_rounding=move_lot.product_id.uom_id.rounding) == 1: + raise exceptions.UserError(_('You can only produce 1.0 %s for products with unique serial number.') % move_lot.product_id.uom_id.name) lots.add(move_lot.lot_id) def _compute_plus(self):