diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index 8ae5aef3cca..bf095c2a430 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -813,18 +813,12 @@ class AccountBankStatementLine(models.Model): @api.constrains('amount', 'amount_currency', 'currency_id', 'foreign_currency_id', 'journal_id') def _check_amounts_currencies(self): ''' Ensure the consistency the specified amounts and the currencies. ''' - if self._context.get('skip_check_amounts_currencies'): - return for st_line in self: if st_line.journal_id != st_line.statement_id.journal_id: raise ValidationError(_('The journal of a statement line must always be the same as the bank statement one.')) - if st_line.currency_id.is_zero(st_line.amount): - raise ValidationError(_("The amount of a statement line can't be equal to zero.")) if st_line.foreign_currency_id == st_line.currency_id: raise ValidationError(_("The foreign currency must be different than the journal one: %s", st_line.currency_id.name)) - if st_line.foreign_currency_id and st_line.foreign_currency_id.is_zero(st_line.amount_currency): - raise ValidationError(_("The amount in foreign currency must be set if the amount is not equal to zero.")) if not st_line.foreign_currency_id and st_line.amount_currency: raise ValidationError(_("You can't provide an amount in foreign currency without specifying a foreign currency.")) diff --git a/addons/account/tests/test_account_bank_statement.py b/addons/account/tests/test_account_bank_statement.py index 8d3ba4983e0..db6dfc83d49 100644 --- a/addons/account/tests/test_account_bank_statement.py +++ b/addons/account/tests/test_account_bank_statement.py @@ -538,7 +538,7 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon): def test_zero_amount_journal_curr_1_statement_curr_2(self): self.bank_journal_2.currency_id = self.currency_1 - statement = self.env['account.bank.statement'].with_context(skip_check_amounts_currencies=True).create({ + statement = self.env['account.bank.statement'].create({ 'name': 'test_statement', 'date': '2019-01-01', 'journal_id': self.bank_journal_2.id, @@ -562,7 +562,7 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon): def test_zero_amount_currency_journal_curr_1_statement_curr_2(self): self.bank_journal_2.currency_id = self.currency_1 - statement = self.env['account.bank.statement'].with_context(skip_check_amounts_currencies=True).create({ + statement = self.env['account.bank.statement'].create({ 'name': 'test_statement', 'date': '2019-01-01', 'journal_id': self.bank_journal_2.id, @@ -586,7 +586,7 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon): def test_zero_amount_journal_curr_2_statement_curr_1(self): self.bank_journal_2.currency_id = self.currency_2 - statement = self.env['account.bank.statement'].with_context(skip_check_amounts_currencies=True).create({ + statement = self.env['account.bank.statement'].create({ 'name': 'test_statement', 'date': '2019-01-01', 'journal_id': self.bank_journal_2.id, @@ -610,7 +610,7 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon): def test_zero_amount_currency_journal_curr_2_statement_curr_1(self): self.bank_journal_2.currency_id = self.currency_2 - statement = self.env['account.bank.statement'].with_context(skip_check_amounts_currencies=True).create({ + statement = self.env['account.bank.statement'].create({ 'name': 'test_statement', 'date': '2019-01-01', 'journal_id': self.bank_journal_2.id, @@ -634,7 +634,7 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon): def test_zero_amount_journal_curr_2_statement_curr_3(self): self.bank_journal_2.currency_id = self.currency_2 - statement = self.env['account.bank.statement'].with_context(skip_check_amounts_currencies=True).create({ + statement = self.env['account.bank.statement'].create({ 'name': 'test_statement', 'date': '2019-01-01', 'journal_id': self.bank_journal_2.id, @@ -658,7 +658,7 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon): def test_zero_amount_currency_journal_curr_2_statement_curr_3(self): self.bank_journal_2.currency_id = self.currency_2 - statement = self.env['account.bank.statement'].with_context(skip_check_amounts_currencies=True).create({ + statement = self.env['account.bank.statement'].create({ 'name': 'test_statement', 'date': '2019-01-01', 'journal_id': self.bank_journal_2.id, @@ -703,25 +703,12 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon): # ==== Test constraints at creation ==== - # Amount can't be 0.0 on a statement line. - assertStatementLineConstraint(statement_vals, { - **statement_line_vals, - 'amount': 0.0, - }) - # Foreign currency must not be the same as the journal one. assertStatementLineConstraint(statement_vals, { **statement_line_vals, 'foreign_currency_id': self.currency_1.id, }) - # Can't have amount_currency = 0.0 with a specified foreign currency. - assertStatementLineConstraint(statement_vals, { - **statement_line_vals, - 'foreign_currency_id': self.currency_2.id, - 'amount_currency': 0.0, - }) - # Can't have a stand alone amount in foreign currency without foreign currency set. assertStatementLineConstraint(statement_vals, { **statement_line_vals,