From f4e9e15618ae2b11ebcdd6777e88fc97a3f6ac12 Mon Sep 17 00:00:00 2001 From: "Touati Djamel (otd)" Date: Fri, 29 Jul 2022 11:40:00 +0000 Subject: [PATCH] [FIX] mrp: avoid a traceback when using SN in a transfer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce the bug: - Go to Inventory→ Configuration→ Warehouse Management →Operations Types - Go inside “Receipts”, and enable the checkbox “Create New Lots/Serial Numbers for Components” and `Use Existing Lots/Serial Numbers`under the traceability section - Create a receipt transfers with a traceable product - Mark as to do the transfer - Try to add a SN for the product Problem: Traceback is triggered: “key error: raw_material_production_id” because we use this field to add it in the context from the parent in the `stock.move.line` view: https://github.com/odoo/odoo/blob/15.0/addons/mrp/views/stock_move_views .xml#L53 But this field is not present in all views of the `stock.move` model Solution: To avoid adding this field in all the `stock.move` views, it is better to add it in the context from the `python` code closes odoo/odoo#98110 X-original-commit: 545713ae0a559e7f2747dd3cb4211ab752e1ef0c Signed-off-by: Arnold Moyaux (arm) Signed-off-by: Adrien Widart --- addons/mrp/models/stock_move.py | 1 + addons/mrp/views/stock_move_views.xml | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py index 1eaa53799e1..b236c62652f 100644 --- a/addons/mrp/models/stock_move.py +++ b/addons/mrp/models/stock_move.py @@ -357,6 +357,7 @@ class StockMove(models.Model): action['views'] = [(self.env.ref('mrp.view_stock_move_operations_raw').id, 'form')] action['context']['show_destination_location'] = False action['context']['force_manual_consumption'] = True + action['context']['active_mo_id'] = self.raw_material_production_id.id elif self.production_id: action['views'] = [(self.env.ref('mrp.view_stock_move_operations_finished').id, 'form')] action['context']['show_source_location'] = False diff --git a/addons/mrp/views/stock_move_views.xml b/addons/mrp/views/stock_move_views.xml index c86cc44561e..ca508b99849 100644 --- a/addons/mrp/views/stock_move_views.xml +++ b/addons/mrp/views/stock_move_views.xml @@ -21,9 +21,6 @@ Consumed - - - @@ -50,7 +47,7 @@ { - 'active_mo_id': parent.raw_material_production_id, + 'active_mo_id': context.get('active_mo_id'), 'active_picking_id': picking_id, 'default_company_id': parent.company_id, 'default_product_id': parent.product_id,