From b7fdbe87a5f1feb4d936271d256158f22a4b0fad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 8 Aug 2008 15:17:33 +0200 Subject: [PATCH] Improve get_purchase_price --- purchase.py | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/purchase.py b/purchase.py index f50066c389..ba90ea05e7 100644 --- a/purchase.py +++ b/purchase.py @@ -834,16 +834,39 @@ class Product(OSV): def get_purchase_price(self, cursor, user, ids, quantity=0, context=None): ''' - Return price for product ids. - context can have : - - uom - - supplier - - currency + Return purchase price for product ids. + + :param cursor: the database cursor + :param user: the user id + :param ids: the product ids + :param quantity: the quantity of products + :param context: the context that can have as keys: + uom: the unit of measure + supplier: the supplier party id + currency: the currency id for the returned price + :return: a dictionary with for each product ids keys the computed price ''' uom_obj = self.pool.get('product.uom') user_obj = self.pool.get('res.user') currency_obj = self.pool.get('currency.currency') + + if context is None: + context = {} + res = {} + + uom = None + if context.get('uom'): + uom = uom_obj.browse(cursor, user, context['uom'], + context=context) + + currency = None + if context.get('currency'): + currency = currency_obj.browse(cursor, user, context['currency'], + context=context) + + user2 = user_obj.browse(cursor, user, user, context=context) + for product in self.browse(cursor, user, ids, context=context): res[product.id] = product.cost_price if context.get('supplier') and product.product_suppliers: @@ -854,16 +877,11 @@ class Product(OSV): if price.quantity <= quantity: res[product.id] = price.price break - if context.get('uom'): - uom = uom_obj.browse(cursor, user, context['uom'], - context=context) + if uom: res[product.id] = uom_obj.compute_price(cursor, user, product.default_uom, res[product.id], uom, context=context) - if context.get('currency'): - currency = currency_obj.browse(cursor, user, - context['currency'], context=context) - user2 = user_obj.browse(cursor, user, user, context=context) + if currency: if user2.company.currency.id != currency.id: res[product.id] = currency_obj.compute(cursor, user, user2.company.currency, res[product.id],