From ce0027a6d0e3ef9ac549c165bd3870a8e9dd1569 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Wed, 1 Jul 2015 10:05:49 +0200 Subject: [PATCH] [FIX] stock_account: In stock valuation report, if all products real price, don't do the product history price query --- addons/stock_account/wizard/stock_valuation_history.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/stock_account/wizard/stock_valuation_history.py b/addons/stock_account/wizard/stock_valuation_history.py index 13e35c7b91d..9a12ff24e1f 100644 --- a/addons/stock_account/wizard/stock_valuation_history.py +++ b/addons/stock_account/wizard/stock_valuation_history.py @@ -65,8 +65,10 @@ class stock_history(osv.osv): products_rec = self.pool['product.product'].read(cr, uid, product_ids, ['cost_method', 'product_tmpl_id'], context=context) products_dict = dict((product['id'], product) for product in products_rec) cost_method_product_tmpl_ids = list(set(product['product_tmpl_id'][0] for product in products_rec if product['cost_method'] != 'real')) - cr.execute('SELECT DISTINCT ON (product_template_id, company_id) product_template_id, company_id, cost FROM product_price_history WHERE product_template_id in %s AND datetime <= %s ORDER BY product_template_id, company_id, datetime DESC', (tuple(cost_method_product_tmpl_ids), date)) - histories = cr.dictfetchall() + histories = [] + if cost_method_product_tmpl_ids: + cr.execute('SELECT DISTINCT ON (product_template_id, company_id) product_template_id, company_id, cost FROM product_price_history WHERE product_template_id in %s AND datetime <= %s ORDER BY product_template_id, company_id, datetime DESC', (tuple(cost_method_product_tmpl_ids), date)) + histories = cr.dictfetchall() histories_dict = {} for history in histories: histories_dict[(history['product_template_id'], history['company_id'])] = history['cost']