diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index 052d8017b6f..3fc682f7dd5 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -771,6 +771,8 @@ class AccountBankStatementLine(models.Model): raise ValidationError(_("The foreign currency must be different than the journal one: %s", st_line.currency_id.name)) 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.")) + if not st_line.amount_currency and st_line.foreign_currency_id: + raise ValidationError(_("You can't provide a foreign currency without specifying an amount in 'Amount in Currency' field.")) # ------------------------------------------------------------------------- # LOW-LEVEL METHODS diff --git a/addons/account/tests/test_account_bank_statement.py b/addons/account/tests/test_account_bank_statement.py index 8589cf00b7c..05a8a9f334e 100644 --- a/addons/account/tests/test_account_bank_statement.py +++ b/addons/account/tests/test_account_bank_statement.py @@ -596,31 +596,6 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon): {'debit': 0.0, 'credit': 0.0, 'amount_currency': -10.0, 'currency_id': self.currency_2.id}, ]) - 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'].create({ - 'name': 'test_statement', - 'date': '2019-01-01', - 'journal_id': self.bank_journal_2.id, - 'line_ids': [ - (0, 0, { - 'date': '2019-01-01', - 'payment_ref': 'line_1', - 'partner_id': self.partner_a.id, - 'foreign_currency_id': self.currency_2.id, - 'amount': 10.0, - 'amount_currency': 0.0, - }), - ], - }) - - self.assertRecordValues(statement.line_ids.move_id.line_ids, [ - # pylint: disable=C0326 - {'debit': 10.0, 'credit': 0.0, 'amount_currency': 10.0, 'currency_id': self.currency_1.id}, - {'debit': 0.0, 'credit': 10.0, 'amount_currency': 0.0, 'currency_id': self.currency_2.id}, - ]) - def test_zero_amount_journal_curr_2_statement_curr_1(self): self.bank_journal_2.currency_id = self.currency_2 @@ -645,30 +620,6 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon): {'debit': 0.0, 'credit': 10.0, 'amount_currency': -10.0, 'currency_id': self.currency_1.id}, ]) - 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'].create({ - 'name': 'test_statement', - 'date': '2019-01-01', - 'journal_id': self.bank_journal_2.id, - 'line_ids': [ - (0, 0, { - 'date': '2019-01-01', - 'payment_ref': 'line_1', - 'partner_id': self.partner_a.id, - 'foreign_currency_id': self.currency_1.id, - 'amount': 10.0, - 'amount_currency': 0.0, - }), - ], - }) - - self.assertRecordValues(statement.line_ids.move_id.line_ids, [ - {'debit': 0.0, 'credit': 0.0, 'amount_currency': 10.0, 'currency_id': self.currency_2.id}, - {'debit': 0.0, 'credit': 0.0, 'amount_currency': 0.0, 'currency_id': self.currency_1.id}, - ]) - def test_zero_amount_journal_curr_2_statement_curr_3(self): self.bank_journal_2.currency_id = self.currency_2 @@ -693,30 +644,6 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon): {'debit': 0.0, 'credit': 0.0, 'amount_currency': -10.0, 'currency_id': self.currency_3.id}, ]) - 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'].create({ - 'name': 'test_statement', - 'date': '2019-01-01', - 'journal_id': self.bank_journal_2.id, - 'line_ids': [ - (0, 0, { - 'date': '2019-01-01', - 'payment_ref': 'line_1', - 'partner_id': self.partner_a.id, - 'foreign_currency_id': self.currency_3.id, - 'amount': 10.0, - 'amount_currency': 0.0, - }), - ], - }) - - self.assertRecordValues(statement.line_ids.move_id.line_ids, [ - {'debit': 5.0, 'credit': 0.0, 'amount_currency': 10.0, 'currency_id': self.currency_2.id}, - {'debit': 0.0, 'credit': 5.0, 'amount_currency': 0.0, 'currency_id': self.currency_3.id}, - ]) - def test_constraints(self): def assertStatementLineConstraint(statement_vals, statement_line_vals): with self.assertRaises(Exception), self.cr.savepoint(): @@ -753,6 +680,12 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon): 'amount_currency': 10.0, }) + # Can't have a foreign currency set without amount in foreign currency. + assertStatementLineConstraint(statement_vals, { + **statement_line_vals, + 'foreign_currency_id': self.currency_2.id, + }) + # ==== Test constraints at edition ==== statement = self.env['account.bank.statement'].create({