From 06455974383ad26114fceaae3e5e30961b2d89a3 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Fri, 14 Mar 2014 12:16:32 +0100 Subject: [PATCH] [IMP] Optimize stock valuation report more bzr revid: jco@openerp.com-20140314111632-59lzfrboz6kpd94y --- addons/product/product.py | 2 ++ .../wizard/stock_valuation_history.py | 17 +++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/addons/product/product.py b/addons/product/product.py index 9169ec99ead..18c5ecb4c9b 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -574,6 +574,8 @@ class product_product(osv.osv): return _('Products: ') + self.pool.get('product.category').browse(cr, uid, context['categ_id'], context=context).name return res + + def get_history_price(self, cr, uid, product_id, company_id, context=None): if context is None: context = {} diff --git a/addons/stock_account/wizard/stock_valuation_history.py b/addons/stock_account/wizard/stock_valuation_history.py index b46a215b957..8e92f8b8e33 100644 --- a/addons/stock_account/wizard/stock_valuation_history.py +++ b/addons/stock_account/wizard/stock_valuation_history.py @@ -36,6 +36,7 @@ class wizard_valuation_history(osv.osv_memory): } + class stock_history(osv.osv): _name = 'stock.history' _auto = False @@ -43,22 +44,26 @@ class stock_history(osv.osv): def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False): res = super(stock_history, self).read_group(cr, uid, domain, fields, groupby, offset=offset, limit=limit, context=context, orderby=orderby) - import time + prod_dict= {} if 'inventory_value' in fields: for line in res: if '__domain' in line: lines = self.search(cr, uid, line['__domain'], context=context) inv_value = 0.0 product_obj = self.pool.get("product.product") - print time.time() - for line_rec in self.browse(cr, uid, lines, context=context): - inv_value += line_rec.quantity * product_obj.get_history_price(cr, uid, line_rec.product_id.id, line_rec.company_id.id, context=context) + lines_rec = self.browse(cr, uid, lines, context=context) + for line_rec in lines_rec: + if not line_rec.product_id.id in prod_dict: + if line_rec.product_id.cost_method == 'real': + prod_dict[line_rec.product_id.id] = line_rec.price_unit_on_quant + else: + prod_dict[line_rec.product_id.id] = product_obj.get_history_price(cr, uid, line_rec.product_id.id, line_rec.company_id.id, context=context) + inv_value += prod_dict[line_rec.product_id.id] line['inventory_value'] = inv_value - print "end", time.time() return res + def _get_inventory_value(self, cr, uid, ids, name, attr, context=None): - print "pass" product_obj = self.pool.get("product.product") res = {} for line in self.browse(cr, uid, ids, context=context):