summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Martinelli <nim@odoo.com>2020-09-29 10:39:56 +0000
committerNicolas Martinelli <nim@odoo.com>2020-10-14 14:43:19 +0000
commitdad5e2a575448b68cc1b59880fecfe48dbe30a4e (patch)
tree6bd76323aca8a08d7f0f41a095afd0b6fcef3124
parent94353ebd6b47a286157f0559b194ff03ea49ff68 (diff)
[FIX] account: wrong rounding with multi-currency
- Create a tax: 5% Included in price - Set the company currency to USD - Set the currency rounding of CHF to 0.05 - Set the rate for CHF to 0.654065014 - Create the following invoice in CHF: Set a payment term Prod 1, 1 unit, 5.0 CHF, tax 5% Prod 2, 1 unit, 10.0 CHF, tax 5% Prod 3, 1 unit, 50.0 CHF, tax 5% It is not possible to save the invoice because of an unbalanced journal entry. Indeed, the Receivable line is $99.30 while it should be $99.29. This happens because we round the `total_balance` with the rounding precision of the invoice currency while it is in the company currency. closes odoo/odoo#58798 closes odoo/odoo#59978 Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
-rw-r--r--addons/account/models/account_move.py2
-rw-r--r--addons/account/tests/test_invoice_taxes.py49
2 files changed, 47 insertions, 4 deletions
diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py
index 7a2e8e41ee4..d62a5236cb5 100644
--- a/addons/account/models/account_move.py
+++ b/addons/account/models/account_move.py
@@ -890,7 +890,7 @@ class AccountMove(models.Model):
:return: A list <to_pay_company_currency, to_pay_invoice_currency, due_date>.
'''
if self.invoice_payment_term_id:
- to_compute = self.invoice_payment_term_id.compute(total_balance, date_ref=date, currency=self.currency_id)
+ to_compute = self.invoice_payment_term_id.compute(total_balance, date_ref=date, currency=self.company_id.currency_id)
if self.currency_id == self.company_id.currency_id:
# Single-currency.
return [(b[0], b[1], b[1]) for b in to_compute]
diff --git a/addons/account/tests/test_invoice_taxes.py b/addons/account/tests/test_invoice_taxes.py
index 757cc1cefd2..72579ded89f 100644
--- a/addons/account/tests/test_invoice_taxes.py
+++ b/addons/account/tests/test_invoice_taxes.py
@@ -32,6 +32,14 @@ class TestInvoiceTaxes(AccountTestInvoicingCommon):
'amount': 12,
'sequence': 30,
})
+ cls.percent_tax_3_incl = cls.env['account.tax'].create({
+ 'name': '5% incl',
+ 'amount_type': 'percent',
+ 'amount': 5,
+ 'price_include': True,
+ 'include_base_amount': True,
+ 'sequence': 40,
+ })
cls.group_tax = cls.env['account.tax'].create({
'name': 'group 12% + 21%',
'amount_type': 'group',
@@ -65,12 +73,12 @@ class TestInvoiceTaxes(AccountTestInvoicingCommon):
cls.base_tag_pos = cls.base_tax_report_line.tag_ids.filtered(lambda x: not x.tax_negate)
cls.base_tag_neg = cls.base_tax_report_line.tag_ids.filtered(lambda x: x.tax_negate)
- def _create_invoice(self, taxes_per_line, inv_type='out_invoice'):
+ def _create_invoice(self, taxes_per_line, inv_type='out_invoice', currency_id=False, invoice_payment_term_id=False):
''' Create an invoice on the fly.
:param taxes_per_line: A list of tuple (price_unit, account.tax recordset)
'''
- return self.env['account.move'].create({
+ vals = {
'move_type': inv_type,
'partner_id': self.partner_a.id,
'invoice_line_ids': [(0, 0, {
@@ -79,7 +87,12 @@ class TestInvoiceTaxes(AccountTestInvoicingCommon):
'price_unit': amount,
'tax_ids': [(6, 0, taxes.ids)],
}) for amount, taxes in taxes_per_line],
- })
+ }
+ if currency_id:
+ vals['currency_id'] = currency_id.id
+ if invoice_payment_term_id:
+ vals['invoice_payment_term_id'] = invoice_payment_term_id.id
+ return self.env['account.move'].create(vals)
def test_one_tax_per_line(self):
''' Test:
@@ -477,3 +490,33 @@ class TestInvoiceTaxes(AccountTestInvoicingCommon):
'tax_ids': []
},
])
+
+ def test_foreign_currency_01(self):
+ ''' Test:
+ Foreign currency with rate of 0.654065014 with currency rounding set to 0.05.
+
+ price_unit | Taxes
+ ------------------
+ 5 | 5% incl
+ 10 | 5% incl
+ 50 | 5% incl
+
+ '''
+ company = self.env.ref('base.main_company')
+ currency_usd_id = self.env.ref("base.USD")
+ currency_chf_id = self.env.ref("base.CHF")
+ self.cr.execute("UPDATE res_company SET currency_id = %s WHERE id = %s", [currency_usd_id.id, company.id])
+ currency_chf_id.rounding = 0.05
+
+ self.env['res.currency.rate'].search([]).unlink()
+ self.env['res.currency.rate'].create({
+ 'currency_id': currency_chf_id.id,
+ 'rate': 0.654065014,
+ 'name': '2001-01-01'})
+
+ invoice = self._create_invoice([
+ (5, self.percent_tax_3_incl),
+ (10, self.percent_tax_3_incl),
+ (50, self.percent_tax_3_incl),
+ ], currency_id=currency_chf_id, invoice_payment_term_id=self.pay_terms_a)
+ invoice.action_post()