[FIX] account: Fix lost constraint during the account-pocalypse

A journal entry must always have the same currency as the account when
a secondary currency is set on this one.

closes odoo/odoo#39844

Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
This commit is contained in:
Laurent Smet
2019-11-12 14:33:52 +00:00
parent afee07cb91
commit 2a875a404a
7 changed files with 111 additions and 110 deletions
+7
View File
@@ -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
+4
View File
@@ -2978,6 +2978,10 @@ class AccountMoveLine(models.Model):
if account.deprecated:
raise UserError(_('The account %s (%s) is deprecated.') % (account.name, account.code))
account_currency = account.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.'))
control_journal_failed = account.allowed_journal_ids and journal not in account.allowed_journal_ids
control_type_failed = journal.type_control_ids and account.user_type_id not in journal.type_control_ids
control_account_failed = journal.account_control_ids and account not in journal.account_control_ids
@@ -49,6 +49,22 @@ class TestAccountMove(AccountTestInvoicingCommon):
]
})
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()
@@ -3,7 +3,7 @@ from odoo.addons.account.tests.common import AccountTestInvoicingCommon
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')
@@ -625,49 +625,44 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon):
})
def test_in_invoice_line_onchange_currency_1(self):
# New journal having a foreign currency set.
journal = self.company_data['default_journal_purchase'].copy()
journal.currency_id = self.currency_data['currency']
move_form = Form(self.invoice)
move_form.journal_id = journal
move_form.currency_id = self.currency_data['currency']
move_form.save()
self.assertInvoiceValues(self.invoice, [
{
**self.product_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 800.0,
'debit': 400.0,
},
{
**self.product_line_vals_2,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 160.0,
'debit': 80.0,
},
{
**self.tax_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 144.0,
'debit': 72.0,
},
{
**self.tax_line_vals_2,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 24.0,
'debit': 12.0,
},
{
**self.term_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -1128.0,
'credit': 564.0,
},
], {
**self.move_vals,
'currency_id': journal.currency_id.id,
'journal_id': journal.id,
'currency_id': self.currency_data['currency'].id,
})
move_form = Form(self.invoice)
@@ -678,38 +673,37 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon):
self.assertInvoiceValues(self.invoice, [
{
**self.product_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 800.0,
'debit': 266.67,
},
{
**self.product_line_vals_2,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 160.0,
'debit': 53.33,
},
{
**self.tax_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 144.0,
'debit': 48.0,
},
{
**self.tax_line_vals_2,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 24.0,
'debit': 8.0,
},
{
**self.term_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -1128.0,
'credit': 376.0,
},
], {
**self.move_vals,
'currency_id': journal.currency_id.id,
'journal_id': journal.id,
'currency_id': self.currency_data['currency'].id,
'date': fields.Date.from_string('2016-01-01'),
})
@@ -728,13 +722,13 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon):
'price_unit': 0.05,
'price_subtotal': 0.005,
'price_total': 0.006,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 0.005,
'debit': 0.0,
},
{
**self.product_line_vals_2,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 160.0,
'debit': 53.33,
},
@@ -743,19 +737,19 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon):
'price_unit': 24.0,
'price_subtotal': 24.001,
'price_total': 24.001,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 24.001,
'debit': 8.0,
},
{
**self.tax_line_vals_2,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 24.0,
'debit': 8.0,
},
{
**self.term_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'price_unit': -208.01,
'price_subtotal': -208.006,
'price_total': -208.006,
@@ -764,14 +758,14 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon):
},
], {
**self.move_vals,
'currency_id': journal.currency_id.id,
'journal_id': journal.id,
'currency_id': self.currency_data['currency'].id,
'date': fields.Date.from_string('2016-01-01'),
'amount_untaxed': 160.005,
'amount_tax': 48.001,
'amount_total': 208.006,
})
# Exit the multi-currencies.
move_form = Form(self.invoice)
move_form.currency_id = self.company_data['currency']
move_form.save()
@@ -804,7 +798,6 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon):
], {
**self.move_vals,
'currency_id': self.company_data['currency'].id,
'journal_id': journal.id,
'date': fields.Date.from_string('2016-01-01'),
'amount_untaxed': 160.01,
'amount_tax': 48.0,
@@ -2,6 +2,7 @@
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
from odoo.tests.common import Form
from odoo.tests import tagged
from odoo.exceptions import UserError
from odoo import fields
@@ -624,49 +625,44 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon):
})
def test_in_refund_line_onchange_currency_1(self):
# New journal having a foreign currency set.
journal = self.company_data['default_journal_purchase'].copy()
journal.currency_id = self.currency_data['currency']
move_form = Form(self.invoice)
move_form.journal_id = journal
move_form.currency_id = self.currency_data['currency']
move_form.save()
self.assertInvoiceValues(self.invoice, [
{
**self.product_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -800.0,
'credit': 400.0,
},
{
**self.product_line_vals_2,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -160.0,
'credit': 80.0,
},
{
**self.tax_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -144.0,
'credit': 72.0,
},
{
**self.tax_line_vals_2,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -24.0,
'credit': 12.0,
},
{
**self.term_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 1128.0,
'debit': 564.0,
},
], {
**self.move_vals,
'currency_id': journal.currency_id.id,
'journal_id': journal.id,
'currency_id': self.currency_data['currency'].id,
})
move_form = Form(self.invoice)
@@ -677,38 +673,37 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon):
self.assertInvoiceValues(self.invoice, [
{
**self.product_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -800.0,
'credit': 266.67,
},
{
**self.product_line_vals_2,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -160.0,
'credit': 53.33,
},
{
**self.tax_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -144.0,
'credit': 48.0,
},
{
**self.tax_line_vals_2,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -24.0,
'credit': 8.0,
},
{
**self.term_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 1128.0,
'debit': 376.0,
},
], {
**self.move_vals,
'currency_id': journal.currency_id.id,
'journal_id': journal.id,
'currency_id': self.currency_data['currency'].id,
'date': fields.Date.from_string('2016-01-01'),
})
@@ -727,13 +722,13 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon):
'price_unit': 0.05,
'price_subtotal': 0.005,
'price_total': 0.006,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -0.005,
'credit': 0.0,
},
{
**self.product_line_vals_2,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -160.0,
'credit': 53.33,
},
@@ -742,19 +737,19 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon):
'price_unit': 24.0,
'price_subtotal': 24.001,
'price_total': 24.001,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -24.001,
'credit': 8.0,
},
{
**self.tax_line_vals_2,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -24.0,
'credit': 8.0,
},
{
**self.term_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'price_unit': -208.01,
'price_subtotal': -208.006,
'price_total': -208.006,
@@ -763,14 +758,14 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon):
},
], {
**self.move_vals,
'currency_id': journal.currency_id.id,
'journal_id': journal.id,
'currency_id': self.currency_data['currency'].id,
'date': fields.Date.from_string('2016-01-01'),
'amount_untaxed': 160.005,
'amount_tax': 48.001,
'amount_total': 208.006,
})
# Exit the multi-currencies.
move_form = Form(self.invoice)
move_form.currency_id = self.company_data['currency']
move_form.save()
@@ -803,7 +798,6 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon):
], {
**self.move_vals,
'currency_id': self.company_data['currency'].id,
'journal_id': journal.id,
'date': fields.Date.from_string('2016-01-01'),
'amount_untaxed': 160.01,
'amount_tax': 48.0,
@@ -769,49 +769,44 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon):
})
def test_out_invoice_line_onchange_currency_1(self):
# New journal having a foreign currency set.
journal = self.company_data['default_journal_sale'].copy()
journal.currency_id = self.currency_data['currency']
move_form = Form(self.invoice)
move_form.journal_id = journal
move_form = Form(self.invoice.with_context(dudu=True))
move_form.currency_id = self.currency_data['currency']
move_form.save()
self.assertInvoiceValues(self.invoice, [
{
**self.product_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -1000.0,
'credit': 500.0,
},
{
**self.product_line_vals_2,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -200.0,
'credit': 100.0,
},
{
**self.tax_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -180.0,
'credit': 90.0,
},
{
**self.tax_line_vals_2,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -30.0,
'credit': 15.0,
},
{
**self.term_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 1410.0,
'debit': 705.0,
},
], {
**self.move_vals,
'currency_id': journal.currency_id.id,
'journal_id': journal.id,
'currency_id': self.currency_data['currency'].id,
})
move_form = Form(self.invoice)
@@ -822,38 +817,37 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon):
self.assertInvoiceValues(self.invoice, [
{
**self.product_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -1000.0,
'credit': 333.33,
},
{
**self.product_line_vals_2,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -200.0,
'credit': 66.67,
},
{
**self.tax_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -180.0,
'credit': 60.0,
},
{
**self.tax_line_vals_2,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -30.0,
'credit': 10.0,
},
{
**self.term_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 1410.0,
'debit': 470.0,
},
], {
**self.move_vals,
'currency_id': journal.currency_id.id,
'journal_id': journal.id,
'currency_id': self.currency_data['currency'].id,
'date': fields.Date.from_string('2016-01-01'),
})
@@ -872,13 +866,13 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon):
'price_unit': 0.05,
'price_subtotal': 0.005,
'price_total': 0.006,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -0.005,
'credit': 0.0,
},
{
**self.product_line_vals_2,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -200.0,
'credit': 66.67,
},
@@ -887,19 +881,19 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon):
'price_unit': 30.0,
'price_subtotal': 30.001,
'price_total': 30.001,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -30.001,
'credit': 10.0,
},
{
**self.tax_line_vals_2,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -30.0,
'credit': 10.0,
},
{
**self.term_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'price_unit': -260.01,
'price_subtotal': -260.006,
'price_total': -260.006,
@@ -908,14 +902,14 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon):
},
], {
**self.move_vals,
'currency_id': journal.currency_id.id,
'journal_id': journal.id,
'currency_id': self.currency_data['currency'].id,
'date': fields.Date.from_string('2016-01-01'),
'amount_untaxed': 200.005,
'amount_tax': 60.001,
'amount_total': 260.006,
})
# Exit the multi-currencies.
move_form = Form(self.invoice)
move_form.currency_id = self.company_data['currency']
move_form.save()
@@ -948,7 +942,6 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon):
], {
**self.move_vals,
'currency_id': self.company_data['currency'].id,
'journal_id': journal.id,
'date': fields.Date.from_string('2016-01-01'),
'amount_untaxed': 200.01,
'amount_tax': 60.0,
@@ -2,6 +2,7 @@
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
from odoo.tests.common import Form
from odoo.tests import tagged
from odoo.exceptions import UserError
from odoo import fields
@@ -624,49 +625,44 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon):
})
def test_out_refund_line_onchange_currency_1(self):
# New journal having a foreign currency set.
journal = self.company_data['default_journal_sale'].copy()
journal.currency_id = self.currency_data['currency']
move_form = Form(self.invoice)
move_form.journal_id = journal
move_form.currency_id = self.currency_data['currency']
move_form.save()
self.assertInvoiceValues(self.invoice, [
{
**self.product_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 1000.0,
'debit': 500.0,
},
{
**self.product_line_vals_2,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 200.0,
'debit': 100.0,
},
{
**self.tax_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 180.0,
'debit': 90.0,
},
{
**self.tax_line_vals_2,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 30.0,
'debit': 15.0,
},
{
**self.term_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -1410.0,
'credit': 705.0,
},
], {
**self.move_vals,
'currency_id': journal.currency_id.id,
'journal_id': journal.id,
'currency_id': self.currency_data['currency'].id,
})
move_form = Form(self.invoice)
@@ -677,38 +673,37 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon):
self.assertInvoiceValues(self.invoice, [
{
**self.product_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 1000.0,
'debit': 333.33,
},
{
**self.product_line_vals_2,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 200.0,
'debit': 66.67,
},
{
**self.tax_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 180.0,
'debit': 60.0,
},
{
**self.tax_line_vals_2,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 30.0,
'debit': 10.0,
},
{
**self.term_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': -1410.0,
'credit': 470.0,
},
], {
**self.move_vals,
'currency_id': journal.currency_id.id,
'journal_id': journal.id,
'currency_id': self.currency_data['currency'].id,
'date': fields.Date.from_string('2016-01-01'),
})
@@ -727,13 +722,13 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon):
'price_unit': 0.05,
'price_subtotal': 0.005,
'price_total': 0.006,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 0.005,
'debit': 0.0,
},
{
**self.product_line_vals_2,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 200.0,
'debit': 66.67,
},
@@ -742,19 +737,19 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon):
'price_unit': 30.0,
'price_subtotal': 30.001,
'price_total': 30.001,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 30.001,
'debit': 10.0,
},
{
**self.tax_line_vals_2,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'amount_currency': 30.0,
'debit': 10.0,
},
{
**self.term_line_vals_1,
'currency_id': journal.currency_id.id,
'currency_id': self.currency_data['currency'].id,
'price_unit': -260.01,
'price_subtotal': -260.006,
'price_total': -260.006,
@@ -763,14 +758,14 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon):
},
], {
**self.move_vals,
'currency_id': journal.currency_id.id,
'journal_id': journal.id,
'currency_id': self.currency_data['currency'].id,
'date': fields.Date.from_string('2016-01-01'),
'amount_untaxed': 200.005,
'amount_tax': 60.001,
'amount_total': 260.006,
})
# Exit the multi-currencies.
move_form = Form(self.invoice)
move_form.currency_id = self.company_data['currency']
move_form.save()
@@ -803,7 +798,6 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon):
], {
**self.move_vals,
'currency_id': self.company_data['currency'].id,
'journal_id': journal.id,
'date': fields.Date.from_string('2016-01-01'),
'amount_untaxed': 200.01,
'amount_tax': 60.0,