Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Item Tax template is not working for e-commerce (backport #39547) #39549

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions erpnext/controllers/accounts_controller.py
Expand Up @@ -21,6 +21,7 @@
get_link_to_form,
getdate,
nowdate,
parse_json,
today,
)

Expand Down Expand Up @@ -831,6 +832,37 @@ def append_taxes_from_master(self, tax_master_doctype=None):

self.extend("taxes", get_taxes_and_charges(tax_master_doctype, self.get("taxes_and_charges")))

def append_taxes_from_item_tax_template(self):
if not frappe.db.get_single_value("Accounts Settings", "add_taxes_from_item_tax_template"):
return

for row in self.items:
item_tax_rate = row.get("item_tax_rate")
if not item_tax_rate:
continue

if isinstance(item_tax_rate, str):
item_tax_rate = parse_json(item_tax_rate)

for account_head, rate in item_tax_rate.items():
row = self.get_tax_row(account_head)

if not row:
self.append(
"taxes",
{
"charge_type": "On Net Total",
"account_head": account_head,
"rate": 0,
"description": account_head,
},
)

def get_tax_row(self, account_head):
for row in self.taxes:
if row.account_head == account_head:
return row

def set_other_charges(self):
self.set("taxes", [])
self.set_taxes()
Expand Down
55 changes: 55 additions & 0 deletions erpnext/selling/doctype/quotation/test_quotation.py
Expand Up @@ -597,6 +597,61 @@ def test_uom_validation(self):
quotation.items[0].conversion_factor = 2.23
self.assertRaises(frappe.ValidationError, quotation.save)

def test_item_tax_template_for_quotation(self):
from erpnext.stock.doctype.item.test_item import make_item

if not frappe.db.exists("Account", {"account_name": "_Test Vat", "company": "_Test Company"}):
frappe.get_doc(
{
"doctype": "Account",
"account_name": "_Test Vat",
"company": "_Test Company",
"account_type": "Tax",
"root_type": "Asset",
"is_group": 0,
"parent_account": "Tax Assets - _TC",
"tax_rate": 10,
}
).insert()

if not frappe.db.exists("Item Tax Template", "Vat Template - _TC"):
doc = frappe.get_doc(
{
"doctype": "Item Tax Template",
"name": "Vat Template",
"title": "Vat Template",
"company": "_Test Company",
"taxes": [
{
"tax_type": "_Test Vat - _TC",
"tax_rate": 5,
}
],
}
).insert()

item_doc = make_item("_Test Item Tax Template QTN", {"is_stock_item": 1})
if not frappe.db.exists(
"Item Tax", {"parent": item_doc.name, "item_tax_template": "Vat Template - _TC"}
):
item_doc.append("taxes", {"item_tax_template": "Vat Template - _TC"})
item_doc.save()

quotation = make_quotation(
item_code="_Test Item Tax Template QTN", qty=1, rate=100, do_not_submit=1
)
self.assertFalse(quotation.taxes)

quotation.append_taxes_from_item_tax_template()
quotation.save()
self.assertTrue(quotation.taxes)
for row in quotation.taxes:
self.assertEqual(row.account_head, "_Test Vat - _TC")
self.assertAlmostEqual(row.base_tax_amount, quotation.total * 5 / 100)

item_doc.taxes = []
item_doc.save()


test_records = frappe.get_test_records("Quotation")

Expand Down