From 8467f7b9ffcb871fbc40cc2fa99ca87667ddc70d Mon Sep 17 00:00:00 2001 From: "Touati Djamel (otd)" Date: Mon, 27 Jun 2022 12:11:08 +0000 Subject: [PATCH] [FIX] mrp: allow selecting only the SNs linked to the MO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Stpes to reproduce the bug: - Create a storable product “P1”: - tracking: Serial number - BOM: 1 unit of C1 - Create the MO 1: - produce 1 unit of P1: - Create the SN1 - Create the MO 2: - produce 1 unit of P1: - Create the SN2 - Create an Unbuild order: - Select the MO1 Problem: You have the possibility to select any Serial number linked to the product “P1”, whereas only SNs created in this MO can be selected opw-2834529 closes odoo/odoo#95956 X-original-commit: 167b1668450c5af44bc1d36d1c7d59921bc2b811 Signed-off-by: William Henrotin (whe) Signed-off-by: Djamel Touati (otd) --- addons/mrp/i18n/mrp.pot | 9 +++++++++ addons/mrp/models/mrp_unbuild.py | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/addons/mrp/i18n/mrp.pot b/addons/mrp/i18n/mrp.pot index 7e3938949f6..b4c83f5050c 100644 --- a/addons/mrp/i18n/mrp.pot +++ b/addons/mrp/i18n/mrp.pot @@ -4600,6 +4600,15 @@ msgstr "" msgid "The record id this is attached to." msgstr "" +#. module: mrp +#: code:addons/mrp/models/mrp_unbuild.py:0 +#: code:addons/mrp/models/mrp_unbuild.py:0 +#, python-format +msgid "" +"The selected serial number does not correspond to the one used in the " +"manufacturing order, please select another one." +msgstr "" + #. module: mrp #: code:addons/mrp/models/mrp_production.py:0 #, python-format diff --git a/addons/mrp/models/mrp_unbuild.py b/addons/mrp/models/mrp_unbuild.py index 3defbd6c515..03158172d8c 100644 --- a/addons/mrp/models/mrp_unbuild.py +++ b/addons/mrp/models/mrp_unbuild.py @@ -106,6 +106,19 @@ class MrpUnbuild(models.Model): self.product_qty = 1 else: self.product_qty = self.mo_id.product_qty + if self.lot_id and self.lot_id not in self.mo_id.move_finished_ids.move_line_ids.lot_id: + return {'warning': { + 'title': _("Warning"), + 'message': _("The selected serial number does not correspond to the one used in the manufacturing order, please select another one.") + }} + + @api.onchange('lot_id') + def _onchange_lot_id(self): + if self.mo_id and self.lot_id and self.lot_id not in self.mo_id.move_finished_ids.move_line_ids.lot_id: + return {'warning': { + 'title': _("Warning"), + 'message': _("The selected serial number does not correspond to the one used in the manufacturing order, please select another one.") + }} @api.onchange('product_id') def _onchange_product_id(self):