From 20e3f33ebd861909d78f38b9bfa0f08f19475c93 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Fri, 13 Feb 2015 12:40:52 +0530 Subject: [PATCH] [FIX] purchase: get supplier from the procurement company The seller_id field is a related that is read administrator so it would fetch the first line, whatever the company specified. Setting related_sudo=False would not be enough as creating purchase orders through the scheduler makes the computation done as administrator. Use the company of the procurement (required) to search for a supplier. If no result, fallback on the first one as before. Fixes #3833, opw 618809 --- addons/purchase/purchase.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 47528a44f22..abca85df6ef 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -1276,6 +1276,11 @@ class procurement_order(osv.osv): def _get_product_supplier(self, cr, uid, procurement, context=None): ''' returns the main supplier of the procurement's product given as argument''' + supplierinfo = self.pool['product.supplierinfo'] + company_supplier = supplierinfo.search(cr, uid, + [('product_tmpl_id', '=', procurement.product_id.product_tmpl_id.id), ('company_id', '=', procurement.company_id.id)], limit=1, context=context) + if company_supplier: + return supplierinfo.browse(cr, uid, company_supplier[0], context=context).name return procurement.product_id.seller_id def _get_po_line_values_from_proc(self, cr, uid, procurement, partner, company, schedule_date, context=None):