From 55b8a454c97020fa52799651c3312fcebb3ee5d3 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Thu, 7 Sep 2017 14:30:52 +0200 Subject: [PATCH] [FIX] mrp: Unbuild order with serial number When unbuilding an order with serial number, the quant with the right serial number must be found in the system either it raises an UserError explaining what's the problem. PS: A problem was found when we tried to unbuild two times the same MO. After the first unbuild, we deleted it and recreated the same one. opw:748472 --- addons/mrp/i18n/mrp.pot | 12 ++++++++++++ addons/mrp/models/mrp_unbuild.py | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/addons/mrp/i18n/mrp.pot b/addons/mrp/i18n/mrp.pot index d79fdaeb329..f5d87479f26 100644 --- a/addons/mrp/i18n/mrp.pot +++ b/addons/mrp/i18n/mrp.pot @@ -3266,6 +3266,18 @@ msgstr "" msgid "You cannot use the same serial number in two different lines." msgstr "" +#. module: mrp +#: code:addons/mrp/models/mrp_unbuild.py:110 +#, python-format +msgid "You don't have in the stock the lot %s." +msgstr "" + +#. module: mrp +#: code:addons/mrp/models/mrp_unbuild.py:125 +#, python-format +msgid "You don't have in the stock the required lot/serial number for %s ." +msgstr "" + #. module: mrp #: code:addons/mrp/wizard/change_production_qty.py:44 #, python-format diff --git a/addons/mrp/models/mrp_unbuild.py b/addons/mrp/models/mrp_unbuild.py index dc22a8e87f1..d73466ed2bb 100644 --- a/addons/mrp/models/mrp_unbuild.py +++ b/addons/mrp/models/mrp_unbuild.py @@ -106,6 +106,8 @@ class MrpUnbuild(models.Model): self.env['stock.quant'].quants_reserve(quants, consume_move) if consume_move.has_tracking != 'none': + if not quants[0][0]: + raise UserError(_("You don't have in the stock the lot %s.") % (self.lot_id.name,)) self.env['stock.move.lots'].create({ 'move_id': consume_move.id, 'lot_id': self.lot_id.id, @@ -119,6 +121,8 @@ class MrpUnbuild(models.Model): for produce_move in produce_moves: if produce_move.has_tracking != 'none': original = original_quants.filtered(lambda quant: quant.product_id == produce_move.product_id) + if not original.lot_id: + raise UserError(_("You don't have in the stock the required lot/serial number for %s .") % (produce_move.product_id.name,)) self.env['stock.move.lots'].create({ 'move_id': produce_move.id, 'lot_id': original.lot_id.id,