Hi everyone,
I'm working on adding a field to compute the average price of purchasing a product.( sum( price_subtotal ) / sum(qty) )
I inserted the field in the product template form view and it works fine for every single product. on the other hand, in the product template tree view the field shows the same value for all products ( value of sum(price_subtotal_of_all_products)/(sum(qty_of_all_prod) )
my question is, why does the field shows two different values even if it's calculated by one method ?
here is the method:
def _get_pmp(self, cr, uid, ids, name, arg, context=None):
pol_obj = self.pool.get('purchase.order.line')
res = {}
qty = 0.0
subtot = 0.0
pol_ids = pol_obj.search(cr, uid, [('product_id', 'in', ids)], context=context)
for product in self.browse(cr, uid, ids, context=context):
for line in pol_obj.browse(cr, uid, pol_ids, context):
qty += line.product_qty
subtot += line.price_subtotal
if qty:
res[product.id] = subtot/qty
return res