Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
AungKoKoLin1997 committed Nov 14, 2024
1 parent b46045f commit f50674f
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import fields, models
from odoo.tools.float_utils import float_round


class AccountBilling(models.Model):
Expand Down Expand Up @@ -58,6 +59,10 @@ def _get_calculated_tax_summary(self):
tax_amount = tax.compute_all(subtotal, self.currency_id)["taxes"][0][
"amount"
]
if self.env.company.tax_calculation_rounding_method == "round_globally":
tax_amount = float_round(
tax_amount, precision_rounding=self.currency_id.rounding
)
calculated_tax_summary[tax] = tax_amount
return calculated_tax_summary

Expand Down
1 change: 1 addition & 0 deletions l10n_jp_account_billing_tax_adjustment/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_account_billing_tax_adjustment
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Copyright 2024 Quartile
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo.tests.common import TransactionCase


class AccountBillingTaxAdjustment(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.partner = cls.env["res.partner"].create(
{
"name": "Test Partner",
}
)
cls.product = cls.env["product.product"].create(
{
"name": "Test Product",
}
)
cls.journal = cls.env["account.journal"].search(
[("company_id", "=", cls.env.company.id), ("type", "=", "general")], limit=1
)
cls.tax_15 = cls.env["account.tax"].search([("amount", "=", 15.0)], limit=1)
cls.tax_10 = cls.env["account.tax"].create(
{"name": "Test Tax 10%", "amount": 10.0, "type_tax_use": "sale"}
)
cls.billing_model = cls.env["account.billing"]

def create_invoice(self, amount, partner, tax):
"""Utility method to create an invoice with a specific amount and tax"""
invoice = self.env["account.move"].create(
{
"move_type": "out_invoice",
"partner_id": partner,
"invoice_line_ids": [
(
0,
0,
{
"product_id": self.product.id,
"quantity": 1,
"price_unit": amount,
"tax_ids": [(6, 0, tax.ids)],
},
)
],
}
)
invoice.action_post()
return invoice

def test_account_billing_tax_adjustments(self):
inv_1_15 = self.create_invoice(
amount=200.5, partner=self.partner.id, tax=self.tax_15
)
inv_2_15 = self.create_invoice(
amount=100.5, partner=self.partner.id, tax=self.tax_15
)
inv_1_10 = self.create_invoice(
amount=101.25, partner=self.partner.id, tax=self.tax_10
)
inv_2_10 = self.create_invoice(
amount=203.25, partner=self.partner.id, tax=self.tax_10
)
invoices = inv_1_15 + inv_2_15 + inv_1_10 + inv_2_10
self.assertEqual(inv_1_15.invoice_line_ids.tax_ids.amount, 15.0)
self.assertEqual(inv_2_15.invoice_line_ids.tax_ids.amount, 15.0)
self.assertEqual(inv_1_10.invoice_line_ids.tax_ids.amount, 10.0)
self.assertEqual(inv_2_10.invoice_line_ids.tax_ids.amount, 10.0)
action = invoices.action_create_billing()
billing = self.billing_model.browse(action["res_id"])
self.assertEqual(billing.state, "draft")
billing.tax_entry_journal_id = self.journal
billing.validate_billing()
tax_adjustment_entry = billing.tax_adjustment_entry_id
self.assertTrue(
tax_adjustment_entry, "Tax adjustment journal entry should be created."
)
tax_adjustment_lines = tax_adjustment_entry.line_ids.filtered(
lambda line: line.tax_ids
)
self.assertEqual(
len(tax_adjustment_lines),
2,
"There should be two tax adjustment lines, one for each tax rate.",
)

0 comments on commit f50674f

Please sign in to comment.