[FIX] account: fix rounding error in is_valid_balance_start check

Field is_valid_balance_check is used to display a warning in case
starting balance of a bank statement is not the same as ending balance
of the previous statement. However the check was done without rounding
resulting in some error in the following casse:
starting_balance = 10.00000001
previous_ending_balance = 10

X-original-commit: 6673d23cfdee97b1e5e6368bc527a9a784578977
This commit is contained in:
Cedric Snauwaert
2020-03-19 10:30:42 +00:00
parent 3590efa478
commit eee8ecdc02
2 changed files with 9 additions and 1 deletions
@@ -201,7 +201,7 @@ class AccountBankStatement(models.Model):
@api.depends('balance_start', 'previous_statement_id')
def _compute_is_valid_balance_start(self):
for bnk in self:
bnk.is_valid_balance_start = bnk.balance_start == bnk.previous_statement_id.balance_end_real
bnk.is_valid_balance_start = float_is_zero(bnk.balance_start - bnk.previous_statement_id.balance_end_real, precision_digits=bnk.currency_id.decimal_places)
@api.depends('date', 'journal_id')
def _get_previous_statement(self):
@@ -191,6 +191,14 @@ class TestBankStatement(AccountTestCommon):
self.assertEqual(cash2.balance_start, 200)
self.assertEqual(cash2.balance_end_real, 1000)
def test_is_valid_balance_start(self):
bnk1 = self.create_bank_statement('2019-01-01', 100, 100.0000001)
bnk2 = self.create_bank_statement('2019-01-10', 50)
bnk2.write({'balance_start': 100})
self.assertTrue(bnk2.is_valid_balance_start)
bnk2.write({'balance_start': 100.01})
self.assertFalse(bnk2.is_valid_balance_start)
def test_unlink_bank_statement(self):
bnk1 = self.create_bank_statement('2019-01-02', 100)
bnk2 = self.create_bank_statement('2019-01-10', 50)