from_unit, to_unit = uoms[0], uoms[-1]
else:
from_unit, to_unit = uoms[-1], uoms[0]
+ return self._compute_qty_obj(cr, uid, from_unit, qty, to_unit)
+
+ def _compute_qty_obj(self, cr, uid, from_unit, qty, to_unit, context={}):
if from_unit.category_id.id <> to_unit.category_id.id:
return qty
- if from_unit['factor_inv_data']:
- amount = qty * from_unit['factor_inv_data']
+ if from_unit.factor_inv_data:
+ amount = qty * from_unit.factor_inv_data
else:
- amount = qty / from_unit['factor']
- if to_uom_id:
- if to_unit['factor_inv_data']:
- amount = rounding(amount / to_unit['factor_inv_data'], to_unit['rounding'])
+ amount = qty / from_unit.factor
+ if to_unit:
+ if to_unit.factor_inv_data:
+ amount = rounding(amount / to_unit.factor_inv_data, to_unit.rounding)
else:
- amount = rounding(amount * to_unit['factor'], to_unit['rounding'])
+ amount = rounding(amount * to_unit.factor, to_unit.rounding)
return amount
def _compute_price(self, cr, uid, from_uom_id, price, to_uom_id=False):
states_str = ','.join(map(lambda s: "'%s'" % s, states))
+ uoms_o = {}
product2uom = {}
for product in self.browse(cr, uid, ids, context=context):
product2uom[product.id] = product.uom_id.id
+ uoms_o[product.uom_id.id] = product.uom_id
prod_ids_str = ','.join(map(str, ids))
location_ids_str = ','.join(map(str, location_ids))
)
results2 = cr.fetchall()
uom_obj = self.pool.get('product.uom')
+ uoms = map(lambda x: x[2], results) + map(lambda x: x[2], results2)
+ if context.get('uom', False):
+ uoms += [context['uom']]
+
+ uoms = filter(lambda x: x not in uoms_o.keys(), uoms)
+ if uoms:
+ uoms = uom_obj.browse(cr, uid, list(set(uoms)), context=context)
+ for o in uoms:
+ uoms_o[o.id] = o
for amount, prod_id, prod_uom in results:
- amount = uom_obj._compute_qty(cr, uid, prod_uom, amount,
- context.get('uom', False) or product2uom[prod_id])
+ amount = uom_obj._compute_qty_obj(cr, uid, uoms_o[prod_uom], amount,
+ uoms_o[context.get('uom', False) or product2uom[prod_id]])
res[prod_id] += amount
for amount, prod_id, prod_uom in results2:
- amount = uom_obj._compute_qty(cr, uid, prod_uom, amount,
- context.get('uom', False) or product2uom[prod_id])
+ amount = uom_obj._compute_qty_obj(cr, uid, uoms_o[prod_uom], amount,
+ uoms_o[context.get('uom', False) or product2uom[prod_id]])
res[prod_id] -= amount
return res