diff --git a/addons/account/i18n/account.pot b/addons/account/i18n/account.pot index 03689429028dc21afceb18c101e003b75b013d87..ac0c84436062b0ea01f31e2736a736b17b9dd6b3 100644 --- a/addons/account/i18n/account.pot +++ b/addons/account/i18n/account.pot @@ -2500,6 +2500,13 @@ msgid "" "Please go to Account Configuration." msgstr "" +#. module: account +#: code:addons/account/models/account_move.py:0 +#, python-format +msgid "" +"The account selected on your journal entry forces to provide a secondary currency. You should remove the secondary currency on the account." +msgstr "" + #. module: account #: code:addons/account/models/account.py:0 #: code:addons/account/models/chart_template.py:0 diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index 85d0f4ecb036dfc2f16dc5a670f852225c6d7999..b69e5e5cebc8968f71297fcf47dfc6801d749338 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -235,6 +235,7 @@ class AccountBankStatement(models.Model): return True def unlink(self): + for statement in self: if statement.state != 'open': raise UserError(_('In order to delete a bank statement, you must first cancel it to delete related journal items.')) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index d7340ab82fc0f879b1fbd3639bff221e5948a849..2080604a38a1183c3a537cf6c20279f5f0f93a73 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -2979,6 +2979,13 @@ class AccountMoveLine(models.Model): # CONSTRAINT METHODS # ------------------------------------------------------------------------- + @api.constrains('currency_id', 'account_id') + def _check_account_currency(self): + for line in self: + account_currency = line.account_id.currency_id + if account_currency and account_currency != line.company_currency_id and account_currency != line.currency_id: + raise UserError(_('The account selected on your journal entry forces to provide a secondary currency. You should remove the secondary currency on the account.')) + @api.constrains('account_id') def _check_constrains_account_id(self): for line in self: diff --git a/addons/account/tests/test_account_move_entry.py b/addons/account/tests/test_account_move_entry.py index 841f97f5276cc9ebd9d60626233eff14418fc84c..7366880992cdfa9d591f3af302f3e8a3e4302fd2 100644 --- a/addons/account/tests/test_account_move_entry.py +++ b/addons/account/tests/test_account_move_entry.py @@ -47,6 +47,22 @@ class TestAccountMove(InvoiceTestCommon): ] }) + def test_custom_currency_on_account_1(self): + custom_account = self.company_data['default_account_revenue'].copy() + + # The currency set on the account is not the same as the one set on the company. + # It should raise an error. + custom_account.currency_id = self.currency_data['currency'] + + with self.assertRaises(UserError), self.cr.savepoint(): + self.test_move.line_ids[0].account_id = custom_account + + # The currency set on the account is the same as the one set on the company. + # It should not raise an error. + custom_account.currency_id = self.company_data['currency'] + + self.test_move.line_ids[0].account_id = custom_account + def test_misc_fiscalyear_lock_date_1(self): self.test_move.post() diff --git a/addons/account/tests/test_account_move_in_invoice.py b/addons/account/tests/test_account_move_in_invoice.py index fe6692d99d8e38467a0b3f0b0d72fb234cc6f6f3..14f4bf98313064f5b0e09106ba1beeb939c4354b 100644 --- a/addons/account/tests/test_account_move_in_invoice.py +++ b/addons/account/tests/test_account_move_in_invoice.py @@ -3,7 +3,7 @@ from odoo.addons.account.tests.invoice_test_common import InvoiceTestCommon from odoo.tests.common import Form from odoo.tests import tagged from odoo import fields -from odoo.exceptions import ValidationError +from odoo.exceptions import UserError, ValidationError @tagged('post_install', '-at_install') @@ -772,6 +772,14 @@ class TestAccountMoveInInvoiceOnchanges(InvoiceTestCommon): 'amount_total': 208.006, }) + # The journal forces you to provide a secondary currency. + with self.assertRaises(UserError), self.cr.savepoint(): + move_form = Form(self.invoice) + move_form.currency_id = self.company_data['currency'] + move_form.save() + + # Exit the multi-currencies. + journal.currency_id = False move_form = Form(self.invoice) move_form.currency_id = self.company_data['currency'] move_form.save() diff --git a/addons/account/tests/test_account_move_in_refund.py b/addons/account/tests/test_account_move_in_refund.py index e89b81c98a7c101084134258309bbced2bbbe1aa..0ee0c02b64d0804f3f9e547b81a22ee449039563 100644 --- a/addons/account/tests/test_account_move_in_refund.py +++ b/addons/account/tests/test_account_move_in_refund.py @@ -2,6 +2,7 @@ from odoo.addons.account.tests.invoice_test_common import InvoiceTestCommon from odoo.tests.common import Form from odoo.tests import tagged +from odoo.exceptions import UserError from odoo import fields @@ -771,6 +772,14 @@ class TestAccountMoveInRefundOnchanges(InvoiceTestCommon): 'amount_total': 208.006, }) + # The journal forces you to provide a secondary currency. + with self.assertRaises(UserError), self.cr.savepoint(): + move_form = Form(self.invoice) + move_form.currency_id = self.company_data['currency'] + move_form.save() + + # Exit the multi-currencies. + journal.currency_id = False move_form = Form(self.invoice) move_form.currency_id = self.company_data['currency'] move_form.save() diff --git a/addons/account/tests/test_account_move_out_invoice.py b/addons/account/tests/test_account_move_out_invoice.py index 38a54508910e283d5c12a7bd08deaee84e631eaf..caf1d997790b344fe91344c5a86bacba5eb78f5c 100644 --- a/addons/account/tests/test_account_move_out_invoice.py +++ b/addons/account/tests/test_account_move_out_invoice.py @@ -916,6 +916,14 @@ class TestAccountMoveOutInvoiceOnchanges(InvoiceTestCommon): 'amount_total': 260.006, }) + # The journal forces you to provide a secondary currency. + with self.assertRaises(UserError), self.cr.savepoint(): + move_form = Form(self.invoice) + move_form.currency_id = self.company_data['currency'] + move_form.save() + + # Exit the multi-currencies. + journal.currency_id = False move_form = Form(self.invoice) move_form.currency_id = self.company_data['currency'] move_form.save() diff --git a/addons/account/tests/test_account_move_out_refund.py b/addons/account/tests/test_account_move_out_refund.py index 5d446553d61982c72d7ec6ea8573869e7b1105c1..35e5c92dccfb77861d6d027fcd849ff2cf4f18aa 100644 --- a/addons/account/tests/test_account_move_out_refund.py +++ b/addons/account/tests/test_account_move_out_refund.py @@ -2,6 +2,7 @@ from odoo.addons.account.tests.invoice_test_common import InvoiceTestCommon from odoo.tests.common import Form from odoo.tests import tagged +from odoo.exceptions import UserError from odoo import fields @@ -771,6 +772,14 @@ class TestAccountMoveOutRefundOnchanges(InvoiceTestCommon): 'amount_total': 260.006, }) + # The journal forces you to provide a secondary currency. + with self.assertRaises(UserError), self.cr.savepoint(): + move_form = Form(self.invoice) + move_form.currency_id = self.company_data['currency'] + move_form.save() + + # Exit the multi-currencies. + journal.currency_id = False move_form = Form(self.invoice) move_form.currency_id = self.company_data['currency'] move_form.save()