From 8eae018b278f12185455bf38c32d365ce55c9256 Mon Sep 17 00:00:00 2001
From: Holger Brunn <hbrunn@therp.nl>
Date: Wed, 3 Dec 2014 15:12:01 +0100
Subject: [PATCH] [FIX] mrp: keep traceability of procurement.group

Pass group_id information when a manufacturing order is created from
a procurement to keep a better traceability and know the reason of stock.move
creation.
Fixes #4019
---
 addons/mrp/mrp.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py
index 5a257f298618..d1746dc705ac 100644
--- a/addons/mrp/mrp.py
+++ b/addons/mrp/mrp.py
@@ -1041,7 +1041,8 @@ class mrp_production(osv.osv):
         source_location_id = production.product_id.property_stock_production.id
         destination_location_id = production.location_dest_id.id
         procs = proc_obj.search(cr, uid, [('production_id', '=', production.id)], context=context)
-        procurement_id = procs and procs[0] or False
+        procurement = procs and\
+            proc_obj.browse(cr, uid, procs[0], context=context) or False
         data = {
             'name': production.name,
             'date': production.date_planned,
@@ -1053,10 +1054,11 @@ class mrp_production(osv.osv):
             'location_id': source_location_id,
             'location_dest_id': destination_location_id,
             'move_dest_id': production.move_prod_id.id,
-            'procurement_id': procurement_id,
+            'procurement_id': procurement and procurement.id,
             'company_id': production.company_id.id,
             'production_id': production.id,
             'origin': production.name,
+            'group_id': procurement and procurement.group_id.id,
         }
         move_id = stock_move.create(cr, uid, data, context=context)
         #a phantom bom cannot be used in mrp order so it's ok to assume the list returned by action_confirm
@@ -1141,6 +1143,7 @@ class mrp_production(osv.osv):
             'price_unit': product.standard_price,
             'origin': production.name,
             'warehouse_id': loc_obj.get_warehouse(cr, uid, production.location_src_id, context=context),
+            'group_id': production.move_prod_id.group_id.id,
         }, context=context)
         
         if prev_move:
-- 
GitLab