From 235cd2d015980265dbf8de5cff7caa50d1ce543b Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Mon, 18 May 2015 17:13:40 +0200 Subject: [PATCH] [FIX] mrp: find company bom when MO created from procurement through cron Manufacturing Orders can be created from procurements, as SUPERUSER_ID, since the procurements can be processed through the WH scheduler, which is always ran as SUPERUSER_ID In such a case, the record rules are ignored, and a BOM normally not accessible to a user thanks to the multi-company record rule could be chosen as the BOM of the MO. This revision forces to find a BOM from a specific company in such a case. opw-640120 --- addons/mrp/mrp.py | 4 ++++ addons/mrp/procurement.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 854349f110b..7ca680ad762 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -212,6 +212,8 @@ class mrp_bom(osv.osv): @param properties: List of related properties. @return: False or BoM id. """ + if not context: + context = {} if properties is None: properties = [] if product_id: @@ -229,6 +231,8 @@ class mrp_bom(osv.osv): else: # neither product nor template, makes no sense to search return False + if context.get('company_id'): + domain = domain + [('company_id', '=', context['company_id'])] domain = domain + [ '|', ('date_start', '=', False), ('date_start', '<=', time.strftime(DEFAULT_SERVER_DATE_FORMAT)), '|', ('date_stop', '=', False), ('date_stop', '>=', time.strftime(DEFAULT_SERVER_DATE_FORMAT))] # order to prioritize bom with product_id over the one without diff --git a/addons/mrp/procurement.py b/addons/mrp/procurement.py index dd14cd89c93..bbcfbedb828 100644 --- a/addons/mrp/procurement.py +++ b/addons/mrp/procurement.py @@ -86,7 +86,7 @@ class procurement_order(osv.osv): else: properties = [x.id for x in procurement.property_ids] bom_id = bom_obj._bom_find(cr, uid, product_id=procurement.product_id.id, - properties=properties, context=context) + properties=properties, context=dict(context, company_id=procurement.company_id.id)) bom = bom_obj.browse(cr, uid, bom_id, context=context) routing_id = bom.routing_id.id return {