diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 408f70d58b3..9bef34a2730 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -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) diff --git a/addons/account/tests/test_invoice_taxes.py b/addons/account/tests/test_invoice_taxes.py index f963070e31c..5bd499e3253 100644 --- a/addons/account/tests/test_invoice_taxes.py +++ b/addons/account/tests/test_invoice_taxes.py @@ -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 + }])