Skip to content

Commit

Permalink
fix: update item_tax_rate in backend
Browse files Browse the repository at this point in the history
  • Loading branch information
ljain112 committed Dec 24, 2024
1 parent a515a39 commit 165906b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
44 changes: 44 additions & 0 deletions erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import (
create_stock_reconciliation,
)
from erpnext.stock.get_item_details import get_item_tax_map
from erpnext.stock.utils import get_incoming_rate, get_stock_balance


Expand Down Expand Up @@ -2879,6 +2880,49 @@ def test_item_tax_net_range(self):
sales_invoice.save()
self.assertEqual(sales_invoice.items[0].item_tax_template, "_Test Account Excise Duty @ 10 - _TC")

def test_item_tax_rate(self):
item = create_item("T Shirt")

item.set("taxes", [])
item.append(
"taxes",
{
"item_tax_template": "_Test Account Excise Duty @ 10 - _TC",
"minimum_net_rate": 0,
"maximum_net_rate": 500,
},
)

item.append(
"taxes",
{
"item_tax_template": "_Test Account Excise Duty @ 12 - _TC",
"minimum_net_rate": 501,
"maximum_net_rate": 1000,
},
)

item.save()

sales_invoice = create_sales_invoice(item="T Shirt", rate=700, do_not_submit=True)
item_tax_map = get_item_tax_map(
doc=sales_invoice,
tax_template=sales_invoice.items[0].item_tax_template,
)
self.assertEqual(sales_invoice.items[0].item_tax_template, "_Test Account Excise Duty @ 12 - _TC")
self.assertEqual(sales_invoice.items[0].item_tax_rate, item_tax_map)

# Apply discount
sales_invoice.apply_discount_on = "Net Total"
sales_invoice.discount_amount = 300
sales_invoice.save()
item_tax_map = get_item_tax_map(
doc=sales_invoice,
tax_template=sales_invoice.items[0].item_tax_template,
)
self.assertEqual(sales_invoice.items[0].item_tax_template, "_Test Account Excise Duty @ 10 - _TC")
self.assertEqual(sales_invoice.items[0].item_tax_rate, item_tax_map)

@IntegrationTestCase.change_settings("Selling Settings", {"enable_discount_accounting": 1})
def test_sales_invoice_with_discount_accounting_enabled(self):
discount_account = create_account(
Expand Down
15 changes: 14 additions & 1 deletion erpnext/controllers/taxes_and_totals.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
validate_taxes_and_charges,
)
from erpnext.deprecation_dumpster import deprecated
from erpnext.stock.get_item_details import ItemDetailsCtx, _get_item_tax_template
from erpnext.stock.get_item_details import ItemDetailsCtx, _get_item_tax_template, get_item_tax_map
from erpnext.utilities.regional import temporary_flag

logger = frappe.logger(__name__)
Expand Down Expand Up @@ -74,6 +74,7 @@ def _calculate(self):
self.validate_conversion_rate()
self.calculate_item_values()
self.validate_item_tax_template()
self.update_item_tax_map()
self.initialize_taxes()
self.determine_exclusive_rate()
self.calculate_net_total()
Expand Down Expand Up @@ -140,6 +141,18 @@ def validate_item_tax_template(self):
)
)

def update_item_tax_map(self):
for item in self.doc.items:
if not item.get("item_tax_template"):
item.item_tax_rate = None
continue

item.item_tax_rate = get_item_tax_map(
doc=self.doc,
tax_template=item.item_tax_template,
as_json=True,
)

def validate_conversion_rate(self):
# validate conversion rate
company_currency = erpnext.get_company_currency(self.doc.company)
Expand Down

0 comments on commit 165906b

Please sign in to comment.