2
0

[FIX] test floats with assertAlmostEqual

[UPD] add places arg in assertAlmostEqual tests

[UPD] flake clean
This commit is contained in:
Romain Deheele 2015-02-10 17:18:53 +01:00 committed by Rodrigo
parent 99560a0cb9
commit 7bd04de5ac
3 changed files with 34 additions and 18 deletions

View File

@ -826,8 +826,8 @@ class account_asset_asset(orm.Model):
for rec in record.child_ids: for rec in record.child_ids:
asset_value += \ asset_value += \
rec.type == 'normal' and \ rec.type == 'normal' and \
self._asset_value_compute(cr, uid, rec, context) or \ self._asset_value_compute(cr, uid, rec, context) \
_value_get(rec) or _value_get(rec)
return asset_value return asset_value
res[asset.id] = _value_get(asset) res[asset.id] = _value_get(asset)
return res return res

View File

@ -138,13 +138,20 @@ class TestAssetManagement(common.TransactionCase):
self.asset_model.compute_depreciation_board( self.asset_model.compute_depreciation_board(
self.cr, self.uid, [asset.id]) self.cr, self.uid, [asset.id])
asset.refresh() asset.refresh()
self.assertEquals(asset.depreciation_line_ids[1].amount, 47.33) self.assertAlmostEqual(asset.depreciation_line_ids[1].amount, 47.33,
self.assertEquals(asset.depreciation_line_ids[2].amount, 55.55) places=2)
self.assertEquals(asset.depreciation_line_ids[3].amount, 55.55) self.assertAlmostEqual(asset.depreciation_line_ids[2].amount, 55.55,
self.assertEquals(asset.depreciation_line_ids[4].amount, 55.55) places=2)
self.assertEquals(asset.depreciation_line_ids[5].amount, 55.55) self.assertAlmostEqual(asset.depreciation_line_ids[3].amount, 55.55,
self.assertEquals(asset.depreciation_line_ids[6].amount, 55.55) places=2)
self.assertEquals(asset.depreciation_line_ids[-1].amount, 8.22) self.assertAlmostEqual(asset.depreciation_line_ids[4].amount, 55.55,
places=2)
self.assertAlmostEqual(asset.depreciation_line_ids[5].amount, 55.55,
places=2)
self.assertAlmostEqual(asset.depreciation_line_ids[6].amount, 55.55,
places=2)
self.assertAlmostEqual(asset.depreciation_line_ids[-1].amount, 8.22,
places=2)
def test_3_proprata_init_prev_year(self): def test_3_proprata_init_prev_year(self):
"""Prorata temporis depreciation with init value in prev year.""" """Prorata temporis depreciation with init value in prev year."""
@ -174,11 +181,15 @@ class TestAssetManagement(common.TransactionCase):
self.cr, self.uid, [asset.id]) self.cr, self.uid, [asset.id])
asset.refresh() asset.refresh()
# I check the depreciated value is the initial value # I check the depreciated value is the initial value
self.assertEquals(asset.value_depreciated, 325.08) self.assertAlmostEqual(asset.value_depreciated, 325.08,
places=2)
# I check computed values in the depreciation board # I check computed values in the depreciation board
self.assertEquals(asset.depreciation_line_ids[2].amount, 55.55) self.assertAlmostEqual(asset.depreciation_line_ids[2].amount, 55.55,
self.assertEquals(asset.depreciation_line_ids[3].amount, 55.55) places=2)
self.assertEquals(asset.depreciation_line_ids[-1].amount, 8.22) self.assertAlmostEqual(asset.depreciation_line_ids[3].amount, 55.55,
places=2)
self.assertAlmostEqual(asset.depreciation_line_ids[-1].amount, 8.22,
places=2)
def test_4_prorata_init_cur_year(self): def test_4_prorata_init_cur_year(self):
"""Prorata temporis depreciation with init value in curent year.""" """Prorata temporis depreciation with init value in curent year."""
@ -206,8 +217,12 @@ class TestAssetManagement(common.TransactionCase):
self.cr, self.uid, [asset.id]) self.cr, self.uid, [asset.id])
asset.refresh() asset.refresh()
# I check the depreciated value is the initial value # I check the depreciated value is the initial value
self.assertEquals(asset.value_depreciated, 279.44) self.assertAlmostEqual(asset.value_depreciated, 279.44,
places=2)
# I check computed values in the depreciation board # I check computed values in the depreciation board
self.assertEquals(asset.depreciation_line_ids[2].amount, 45.64) self.assertAlmostEqual(asset.depreciation_line_ids[2].amount, 45.64,
self.assertEquals(asset.depreciation_line_ids[3].amount, 55.55) places=2)
self.assertEquals(asset.depreciation_line_ids[-1].amount, 8.22) self.assertAlmostEqual(asset.depreciation_line_ids[3].amount, 55.55,
places=2)
self.assertAlmostEqual(asset.depreciation_line_ids[-1].amount, 8.22,
places=2)

View File

@ -258,7 +258,8 @@ class account_asset_remove(orm.TransientModel):
} }
move_lines.append((0, 0, move_line_vals)) move_lines.append((0, 0, move_line_vals))
balance = wiz_data.sale_value - residual_value balance = wiz_data.sale_value - residual_value
account_id = balance > 0 and wiz_data.account_plus_value_id.id \ account_id = balance > 0 \
and wiz_data.account_plus_value_id.id \
or wiz_data.account_min_value_id.id or wiz_data.account_min_value_id.id
move_line_vals = { move_line_vals = {
'name': asset.name, 'name': asset.name,