[IMP] Optimize stock valuation report more
bzr revid: jco@openerp.com-20140314111632-59lzfrboz6kpd94y
This commit is contained in:
parent
13566b866e
commit
0645597438
|
@ -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 _('Products: ') + self.pool.get('product.category').browse(cr, uid, context['categ_id'], context=context).name
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_history_price(self, cr, uid, product_id, company_id, context=None):
|
def get_history_price(self, cr, uid, product_id, company_id, context=None):
|
||||||
if context is None:
|
if context is None:
|
||||||
context = {}
|
context = {}
|
||||||
|
|
|
@ -36,6 +36,7 @@ class wizard_valuation_history(osv.osv_memory):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class stock_history(osv.osv):
|
class stock_history(osv.osv):
|
||||||
_name = 'stock.history'
|
_name = 'stock.history'
|
||||||
_auto = False
|
_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):
|
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)
|
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:
|
if 'inventory_value' in fields:
|
||||||
for line in res:
|
for line in res:
|
||||||
if '__domain' in line:
|
if '__domain' in line:
|
||||||
lines = self.search(cr, uid, line['__domain'], context=context)
|
lines = self.search(cr, uid, line['__domain'], context=context)
|
||||||
inv_value = 0.0
|
inv_value = 0.0
|
||||||
product_obj = self.pool.get("product.product")
|
product_obj = self.pool.get("product.product")
|
||||||
print time.time()
|
lines_rec = self.browse(cr, uid, lines, context=context)
|
||||||
for line_rec in self.browse(cr, uid, lines, context=context):
|
for line_rec in lines_rec:
|
||||||
inv_value += line_rec.quantity * product_obj.get_history_price(cr, uid, line_rec.product_id.id, line_rec.company_id.id, context=context)
|
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
|
line['inventory_value'] = inv_value
|
||||||
print "end", time.time()
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
def _get_inventory_value(self, cr, uid, ids, name, attr, context=None):
|
def _get_inventory_value(self, cr, uid, ids, name, attr, context=None):
|
||||||
print "pass"
|
|
||||||
product_obj = self.pool.get("product.product")
|
product_obj = self.pool.get("product.product")
|
||||||
res = {}
|
res = {}
|
||||||
for line in self.browse(cr, uid, ids, context=context):
|
for line in self.browse(cr, uid, ids, context=context):
|
||||||
|
|
Loading…
Reference in New Issue