[MERGE] forward port of branch 7.0 up to de07c64
This commit is contained in:
commit
ec30b21336
|
@ -178,10 +178,7 @@ class product_uom(osv.osv):
|
|||
raise osv.except_osv(_('Error!'), _('Conversion from Product UoM %s to Default UoM %s is not possible as they both belong to different Category!.') % (from_unit.name,to_unit.name,))
|
||||
else:
|
||||
return qty
|
||||
# First round to the precision of the original unit, so that
|
||||
# float representation errors do not bias the following ceil()
|
||||
# e.g. with 1 / (1/12) we could get 12.0000048, ceiling to 13!
|
||||
amount = float_round(qty/from_unit.factor, precision_rounding=from_unit.rounding)
|
||||
amount = qty/from_unit.factor
|
||||
if to_unit:
|
||||
amount = ceiling(amount * to_unit.factor, to_unit.rounding)
|
||||
return amount
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
<field name="category_id" ref="product_uom_categ_kgm"/>
|
||||
<field name="name">kg</field>
|
||||
<field name="factor" eval="1"/>
|
||||
<field name="rounding" eval="0.001"/>
|
||||
</record>
|
||||
<record id="product_uom_gram" model="product.uom">
|
||||
<field name="category_id" ref="product_uom_categ_kgm"/>
|
||||
|
|
|
@ -12,7 +12,10 @@ class TestUom(TransactionCase):
|
|||
def test_10_conversion(self):
|
||||
cr, uid = self.cr, self.uid
|
||||
gram_id = self.imd.get_object_reference(cr, uid, 'product', 'product_uom_gram')[1]
|
||||
kg_id = self.imd.get_object_reference(cr, uid, 'product', 'product_uom_kgm')[1]
|
||||
tonne_id = self.imd.get_object_reference(cr, uid, 'product', 'product_uom_ton')[1]
|
||||
unit_id = self.imd.get_object_reference(cr, uid, 'product','product_uom_unit')[1]
|
||||
dozen_id = self.imd.get_object_reference(cr, uid, 'product','product_uom_dozen')[1]
|
||||
|
||||
qty = self.uom._compute_qty(cr, uid, gram_id, 1020000, tonne_id)
|
||||
self.assertEquals(qty, 1.02, "Converted quantity does not correspond.")
|
||||
|
@ -20,6 +23,20 @@ class TestUom(TransactionCase):
|
|||
price = self.uom._compute_price(cr, uid, gram_id, 2, tonne_id)
|
||||
self.assertEquals(price, 2000000.0, "Converted price does not correspond.")
|
||||
|
||||
# If the conversion factor for Dozens (1/12) is not stored with sufficient precision,
|
||||
# the conversion of 1 Dozen into Units will give e.g. 12.00000000000047 Units
|
||||
# and the Unit rounding will round that up to 13.
|
||||
# This is a partial regression test for rev. 311c77bb, which is further improved
|
||||
# by rev. fa2f7b86.
|
||||
qty = self.uom._compute_qty(cr, uid, dozen_id, 1, unit_id)
|
||||
self.assertEquals(qty, 12.0, "Converted quantity does not correspond.")
|
||||
|
||||
# Regression test for side-effect of commit 311c77bb - converting 1234 Grams
|
||||
# into Kilograms should work even if grams are rounded to 1.
|
||||
self.uom.write(cr, uid, gram_id, {'rounding': 1})
|
||||
qty = self.uom._compute_qty(cr, uid, gram_id, 1234, kg_id)
|
||||
self.assertEquals(qty, 1.234, "Converted quantity does not correspond.")
|
||||
|
||||
def test_20_rounding(self):
|
||||
cr, uid = self.cr, self.uid
|
||||
unit_id = self.imd.get_object_reference(cr, uid, 'product', 'product_uom_unit')[1]
|
||||
|
|
|
@ -524,6 +524,14 @@ class res_partner(osv.osv, format_address):
|
|||
if not parent.is_company:
|
||||
parent.write({'is_company': True})
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
orphan_contact_ids = self.search(cr, uid,
|
||||
[('parent_id', 'in', ids), ('id', 'not in', ids), ('use_parent_address', '=', True)], context=context)
|
||||
if orphan_contact_ids:
|
||||
# no longer have a parent address
|
||||
self.write(cr, uid, orphan_contact_ids, {'use_parent_address': False}, context=context)
|
||||
return super(res_partner, self).unlink(cr, uid, ids, context=context)
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
if isinstance(ids, (int, long)):
|
||||
ids = [ids]
|
||||
|
|
Loading…
Reference in New Issue