[FIX] account: Fix taxes computation in multi-currency
Steps to reproduce: - On a company with multi currency - Set the company currency rate to 1, and the foreign currency to 0.273748 - Create a vendor bill - Set first the foreign currency, then select a product with a tax to 21% and a price unit of 155.32 - Go to 'Journal Items', the 'tax paid' line debit is computed to 119.15 - Reselect the foreign currency on form. - Now the 'tax paid' line debit is computed to 119.16 The total is also impacted as the tax changed. Explanation: Before this commit, the taxes was both computed in foreign currency and company currency. However, when setting a new currency or changing the date, the taxes wasn't recomputed but the new conversion rate was applied. This commit is fixing the issue by applying the same logic as in 14.0: the taxes are always computed only the foreign currency, then the conversion rate is applied to get the accounting balance. opw-2569668 closes odoo/odoo#79618 X-original-commit: 11f5fcfb577b117b279f5d96095e9c0798d78bbd Signed-off-by: Laurent Smet <las@openerp.com> Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
committed by
Laurent Smet
parent
33f8c747b3
commit
6200696ecc
@@ -646,14 +646,10 @@ class AccountMove(models.Model):
|
||||
return taxes_map
|
||||
|
||||
def _recompute_tax_lines(self, recompute_tax_base_amount=False):
|
||||
''' Compute the dynamic tax lines of the journal entry.
|
||||
""" Compute the dynamic tax lines of the journal entry.
|
||||
|
||||
:param lines_map: The line_ids dispatched by type containing:
|
||||
* base_lines: The lines having a tax_ids set.
|
||||
* tax_lines: The lines having a tax_line_id set.
|
||||
* terms_lines: The lines generated by the payment terms of the invoice.
|
||||
* rounding_lines: The cash rounding lines of the invoice.
|
||||
'''
|
||||
:param recompute_tax_base_amount: Flag forcing only the recomputation of the `tax_base_amount` field.
|
||||
"""
|
||||
self.ensure_one()
|
||||
in_draft_mode = self != self._origin
|
||||
|
||||
@@ -795,6 +791,7 @@ class AccountMove(models.Model):
|
||||
# Update an existing tax line.
|
||||
taxes_map_entry['tax_line'].update(to_write_on_line)
|
||||
else:
|
||||
# Create a new tax line.
|
||||
create_method = in_draft_mode and self.env['account.move.line'].new or self.env['account.move.line'].create
|
||||
tax_repartition_line_id = taxes_map_entry['grouping_dict']['tax_repartition_line_id']
|
||||
tax_repartition_line = self.env['account.tax.repartition.line'].browse(tax_repartition_line_id)
|
||||
|
||||
@@ -669,3 +669,47 @@ class TestInvoiceTaxes(AccountTestInvoicingCommon):
|
||||
(50, self.percent_tax_3_incl),
|
||||
], currency_id=self.currency_data['currency'], invoice_payment_term_id=self.pay_terms_a)
|
||||
invoice.action_post()
|
||||
|
||||
def test_tax_calculation_multi_currency(self):
|
||||
self.env['res.currency.rate'].create({
|
||||
'name': '2018-01-01',
|
||||
'rate': 0.273748,
|
||||
'currency_id': self.currency_data['currency'].id,
|
||||
'company_id': self.env.company.id,
|
||||
})
|
||||
self.currency_data['currency'].rounding = 0.01
|
||||
|
||||
invoice = self.env['account.move'].create({
|
||||
'move_type': 'out_invoice',
|
||||
'partner_id': self.partner_a.id,
|
||||
'currency_id': self.currency_data['currency'].id,
|
||||
'invoice_date': '2018-01-01',
|
||||
'date': '2018-01-01',
|
||||
'invoice_line_ids': [(0, 0, {
|
||||
'name': 'xxxx',
|
||||
'quantity': 1,
|
||||
'price_unit': 155.32,
|
||||
'tax_ids': [(6, 0, self.percent_tax_1.ids)],
|
||||
})]
|
||||
})
|
||||
|
||||
self.assertRecordValues(invoice.line_ids.filtered('tax_line_id'), [{
|
||||
'tax_base_amount': 567.38, # 155.32 * 1 / (1 / 0.273748)
|
||||
'balance': -119.16, # tax_base_amount * 0.21
|
||||
}])
|
||||
|
||||
self.assertRecordValues(invoice.line_ids.filtered(lambda l: not l.name), [{
|
||||
'balance': 686.54
|
||||
}])
|
||||
|
||||
with Form(invoice) as invoice_form:
|
||||
invoice_form.currency_id = self.currency_data['currency']
|
||||
|
||||
self.assertRecordValues(invoice.line_ids.filtered('tax_line_id'), [{
|
||||
'tax_base_amount': 567.38,
|
||||
'balance': -119.16,
|
||||
}])
|
||||
|
||||
self.assertRecordValues(invoice.line_ids.filtered(lambda l: l.account_id.internal_type == 'receivable'), [{
|
||||
'balance': 686.54
|
||||
}])
|
||||
|
||||
Reference in New Issue
Block a user