Revert "fix: patch, item tax template showing 'Untitled' in the name"

This commit is contained in:
rohitwaghchaure 2019-10-30 17:37:22 +05:30 committed by GitHub
parent 1545ee914a
commit 6bd6039496
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,5 @@
import frappe
import json
from frappe.model.naming import make_autoname
from six import iteritems
def execute():
@ -8,6 +7,7 @@ def execute():
return
old_item_taxes = {}
item_tax_templates = {}
rename_template_to_untitled = []
for d in frappe.db.sql("""select parent as item_code, tax_type, tax_rate from `tabItem Tax`""", as_dict=1):
old_item_taxes.setdefault(d.item_code, [])
@ -34,7 +34,7 @@ def execute():
for d in old_item_taxes[item_code]:
item_tax_map[d.tax_type] = d.tax_rate
item_tax_template_name = get_item_tax_template(item_tax_templates,
item_tax_template_name = get_item_tax_template(item_tax_templates, rename_template_to_untitled,
item_tax_map, item_code)
# update the item tax table
@ -53,19 +53,26 @@ def execute():
for d in frappe.db.sql("""select name, parent, item_code, item_tax_rate from `tab{0} Item`
where ifnull(item_tax_rate, '') not in ('', '{{}}')""".format(dt), as_dict=1):
item_tax_map = json.loads(d.item_tax_rate)
item_tax_template = get_item_tax_template(item_tax_templates,
item_tax_template = get_item_tax_template(item_tax_templates, rename_template_to_untitled,
item_tax_map, d.item_code, d.parent)
frappe.db.set_value(dt + " Item", d.name, "item_tax_template", item_tax_template)
idx = 1
for oldname in rename_template_to_untitled:
frappe.rename_doc("Item Tax Template", oldname, "Untitled {}".format(idx))
idx += 1
settings = frappe.get_single("Accounts Settings")
settings.add_taxes_from_item_tax_template = 0
settings.determine_address_tax_category_from = "Billing Address"
settings.save()
def get_item_tax_template(item_tax_templates, item_tax_map, item_code, parent=None):
def get_item_tax_template(item_tax_templates, rename_template_to_untitled, item_tax_map, item_code, parent=None):
# search for previously created item tax template by comparing tax maps
for template, item_tax_template_map in iteritems(item_tax_templates):
if item_tax_map == item_tax_template_map:
if not parent:
rename_template_to_untitled.append(template)
return template
# if no item tax template found, create one
@ -90,11 +97,5 @@ def get_item_tax_template(item_tax_templates, item_tax_map, item_code, parent=No
item_tax_template.append("taxes", {"tax_type": tax_type, "tax_rate": tax_rate})
item_tax_templates.setdefault(item_tax_template.title, {})
item_tax_templates[item_tax_template.title][tax_type] = tax_rate
try:
item_tax_template.save()
except frappe.DuplicateEntryError:
item_tax_template.name = make_autoname(item_tax_template.title + "/.###")
item_tax_template.save()
return item_tax_template.name