fix: update item_tax_rate in backend

This commit is contained in:
ljain112
2024-12-24 15:15:30 +05:30
parent a515a399cf
commit de54c0b41f
2 changed files with 24 additions and 1 deletions

View File

@@ -43,6 +43,7 @@ from erpnext.stock.doctype.stock_entry.test_stock_entry import (
from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import ( from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import (
create_stock_reconciliation, 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 from erpnext.stock.utils import get_incoming_rate, get_stock_balance
@@ -2871,13 +2872,26 @@ class TestSalesInvoice(IntegrationTestCase):
item.save() item.save()
sales_invoice = create_sales_invoice(item="T Shirt", rate=700, do_not_submit=True) 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_template, "_Test Account Excise Duty @ 12 - _TC")
self.assertEqual(sales_invoice.items[0].item_tax_rate, item_tax_map)
# Apply discount # Apply discount
sales_invoice.apply_discount_on = "Net Total" sales_invoice.apply_discount_on = "Net Total"
sales_invoice.discount_amount = 300 sales_invoice.discount_amount = 300
sales_invoice.save() 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_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}) @IntegrationTestCase.change_settings("Selling Settings", {"enable_discount_accounting": 1})
def test_sales_invoice_with_discount_accounting_enabled(self): def test_sales_invoice_with_discount_accounting_enabled(self):

View File

@@ -18,7 +18,7 @@ from erpnext.controllers.accounts_controller import (
validate_taxes_and_charges, validate_taxes_and_charges,
) )
from erpnext.deprecation_dumpster import deprecated 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 from erpnext.utilities.regional import temporary_flag
logger = frappe.logger(__name__) logger = frappe.logger(__name__)
@@ -74,6 +74,7 @@ class calculate_taxes_and_totals:
self.validate_conversion_rate() self.validate_conversion_rate()
self.calculate_item_values() self.calculate_item_values()
self.validate_item_tax_template() self.validate_item_tax_template()
self.update_item_tax_map()
self.initialize_taxes() self.initialize_taxes()
self.determine_exclusive_rate() self.determine_exclusive_rate()
self.calculate_net_total() self.calculate_net_total()
@@ -140,6 +141,14 @@ class calculate_taxes_and_totals:
) )
) )
def update_item_tax_map(self):
for item in self.doc.items:
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): def validate_conversion_rate(self):
# validate conversion rate # validate conversion rate
company_currency = erpnext.get_company_currency(self.doc.company) company_currency = erpnext.get_company_currency(self.doc.company)