diff --git a/l10n_jp_summary_invoice/models/account_billing.py b/l10n_jp_summary_invoice/models/account_billing.py index f9e140a1..61452bb3 100644 --- a/l10n_jp_summary_invoice/models/account_billing.py +++ b/l10n_jp_summary_invoice/models/account_billing.py @@ -154,7 +154,7 @@ def _get_tax_amount_groups_from_invoices(self): ("display_type", "=", "rounding"), ("tax_repartition_line_id", "!=", False), ], - fields=["tax_group_id", "balance"], + fields=["tax_group_id", "amount_currency:sum"], groupby=["tax_group_id"], ) return tax_amount_groups @@ -190,7 +190,7 @@ def validate_billing(self): tax_group_diff_dict = {} for tax_amount_group in tax_amount_groups_invoices: tax_group_id = tax_amount_group["tax_group_id"][0] - tax_amount_invoices = tax_amount_group["balance"] + tax_amount_invoices = tax_amount_group["amount_currency"] tax_amount_bill = tax_group_amount_dict.get(tax_group_id, 0) tax_diff = tax_amount_invoices - tax_amount_bill if tax_diff: diff --git a/l10n_jp_summary_invoice/tests/test_l10n_jp_summary_invoice.py b/l10n_jp_summary_invoice/tests/test_l10n_jp_summary_invoice.py index 086cd7c8..1dd06378 100644 --- a/l10n_jp_summary_invoice/tests/test_l10n_jp_summary_invoice.py +++ b/l10n_jp_summary_invoice/tests/test_l10n_jp_summary_invoice.py @@ -58,7 +58,9 @@ def setUpClass(cls): } ) - def _create_invoice(self, amount, tax, move_type="out_invoice", bank=None): + def _create_invoice( + self, amount, tax, move_type="out_invoice", bank=None, currency_id=None + ): invoice = ( self.env["account.move"] .with_company(self.company) @@ -66,6 +68,7 @@ def _create_invoice(self, amount, tax, move_type="out_invoice", bank=None): { "move_type": move_type, "partner_id": self.partner.id, + "currency_id": currency_id or self.company.currency_id.id, "partner_bank_id": bank and bank.id, "invoice_line_ids": [ Command.create( @@ -194,3 +197,20 @@ def test_create_tax_adjustment_entry(self): # The total tax amount should be 20 (204 * 0.1) self.assertEqual(abs(billing_tax_amount), 20) self.assertFalse(billing.tax_adjustment_entry_id) + + def test_check_tax_adjustment_entry_with_different_currency(self): + self.assertEqual(self.env.company.currency_id, self.env.ref("base.JPY")) + currency_usd = self.env.ref("base.USD") + currency_usd.active = True + out_inv_1 = self._create_invoice(100, self.tax_10, currency_id=currency_usd.id) + out_inv_2 = self._create_invoice(100, self.tax_10, currency_id=currency_usd.id) + out_inv_3 = self._create_invoice(100, self.tax_10, currency_id=currency_usd.id) + invoices = out_inv_1 + out_inv_2 + out_inv_3 + action = invoices.action_create_billing() + billing = self.env["account.billing"].browse(action["res_id"]) + self.assertEqual(billing.state, "draft") + self.assertEqual(billing.currency_id, currency_usd) + billing.with_company(self.company).validate_billing() + billing_tax_amount = self._get_billing_tax_amount(billing) + self.assertEqual(abs(billing_tax_amount), 30) + self.assertFalse(billing.tax_adjustment_entry_id)