fix(patch): do not append taxes to template if account name is not set (#20310)

This commit is contained in:
sahil28297
2020-01-15 18:57:08 +05:30
committed by Nabin Hait
parent b65b525c44
commit dc0ea3fdb0

View File

@@ -49,12 +49,13 @@ def execute():
item_tax_template_name = get_item_tax_template(item_tax_templates, item_tax_map, item_code) item_tax_template_name = get_item_tax_template(item_tax_templates, item_tax_map, item_code)
# update the item tax table # update the item tax table
item = frappe.get_doc("Item", item_code)
item.set("taxes", [])
item.append("taxes", {"item_tax_template": item_tax_template_name, "tax_category": ""})
frappe.db.sql("delete from `tabItem Tax` where parent=%s and parenttype='Item'", item_code) frappe.db.sql("delete from `tabItem Tax` where parent=%s and parenttype='Item'", item_code)
for d in item.taxes: if item_tax_template_name:
d.db_insert() item = frappe.get_doc("Item", item_code)
item.set("taxes", [])
item.append("taxes", {"item_tax_template": item_tax_template_name, "tax_category": ""})
for d in item.taxes:
d.db_insert()
doctypes = [ doctypes = [
'Quotation', 'Sales Order', 'Delivery Note', 'Sales Invoice', 'Quotation', 'Sales Order', 'Delivery Note', 'Sales Invoice',
@@ -95,30 +96,35 @@ def get_item_tax_template(item_tax_templates, item_tax_map, item_code, parenttyp
else: else:
parts = tax_type.strip().split(" - ") parts = tax_type.strip().split(" - ")
account_name = " - ".join(parts[:-1]) account_name = " - ".join(parts[:-1])
company = get_company(parts[-1], parenttype, parent) if not account_name:
parent_account = frappe.db.get_value("Account", tax_type = None
filters={"account_type": "Tax", "root_type": "Liability", "is_group": 0, "company": company}, fieldname="parent_account") else:
if not parent_account: company = get_company(parts[-1], parenttype, parent)
parent_account = frappe.db.get_value("Account", parent_account = frappe.db.get_value("Account",
filters={"account_type": "Tax", "root_type": "Liability", "is_group": 1, "company": company}) filters={"account_type": "Tax", "root_type": "Liability", "is_group": 0, "company": company}, fieldname="parent_account")
filters = { if not parent_account:
"account_name": account_name, parent_account = frappe.db.get_value("Account",
"company": company, filters={"account_type": "Tax", "root_type": "Liability", "is_group": 1, "company": company})
"account_type": "Tax", filters = {
"parent_account": parent_account "account_name": account_name,
} "company": company,
tax_type = frappe.db.get_value("Account", filters) "account_type": "Tax",
if not tax_type: "parent_account": parent_account
account = frappe.new_doc("Account") }
account.update(filters) tax_type = frappe.db.get_value("Account", filters)
account.insert() if not tax_type:
tax_type = account.name account = frappe.new_doc("Account")
account.update(filters)
account.insert()
tax_type = account.name
item_tax_template.append("taxes", {"tax_type": tax_type, "tax_rate": tax_rate}) if tax_type:
item_tax_templates.setdefault(item_tax_template.title, {}) item_tax_template.append("taxes", {"tax_type": tax_type, "tax_rate": tax_rate})
item_tax_templates[item_tax_template.title][tax_type] = tax_rate item_tax_templates.setdefault(item_tax_template.title, {})
item_tax_template.save() item_tax_templates[item_tax_template.title][tax_type] = tax_rate
return item_tax_template.name if item_tax_template.get("taxes"):
item_tax_template.save()
return item_tax_template.name
def get_company(company_abbr, parenttype=None, parent=None): def get_company(company_abbr, parenttype=None, parent=None):
if parenttype and parent: if parenttype and parent: