improved_spped

bzr revid: fp@tinyerp.com-20081218193918-zgfe299e76ljku6q
This commit is contained in:
Fabien Pinckaers 2008-12-18 20:39:18 +01:00
parent 6cede6020b
commit 242b3c53c2
4 changed files with 27 additions and 13 deletions

View File

@ -109,17 +109,20 @@ class product_uom(osv.osv):
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):

View File

@ -57,11 +57,13 @@ class product_product(osv.osv):
_pricelist_calculate,
method=True,
string='Sale Pricelists',
store=True,
type="text"),
'pricelist_purchase':fields.function(
_pricelist_calculate,
method=True,
string='Purchase Pricelists',
store=True,
type="text"),
}

View File

@ -71,9 +71,11 @@ class product_product(osv.osv):
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))
@ -115,13 +117,22 @@ class product_product(osv.osv):
)
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

View File

@ -67,8 +67,6 @@
<separator string="Stocks" colspan="4"/>
<field name="qty_available"/>
<field name="virtual_available"/>
<field name="incoming_qty"/>
<field name="outgoing_qty"/>
</group>
<group colspan="2" col="2" name="lot" groups="base.group_extended">
<separator string="Lots" colspan="4"/>