Revert "fix: patch, item tax template showing 'Untitled' in the name"
This commit is contained in:
parent
1545ee914a
commit
6bd6039496
@ -1,6 +1,5 @@
|
|||||||
import frappe
|
import frappe
|
||||||
import json
|
import json
|
||||||
from frappe.model.naming import make_autoname
|
|
||||||
from six import iteritems
|
from six import iteritems
|
||||||
|
|
||||||
def execute():
|
def execute():
|
||||||
@ -8,6 +7,7 @@ def execute():
|
|||||||
return
|
return
|
||||||
old_item_taxes = {}
|
old_item_taxes = {}
|
||||||
item_tax_templates = {}
|
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):
|
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, [])
|
old_item_taxes.setdefault(d.item_code, [])
|
||||||
@ -34,7 +34,7 @@ def execute():
|
|||||||
for d in old_item_taxes[item_code]:
|
for d in old_item_taxes[item_code]:
|
||||||
item_tax_map[d.tax_type] = d.tax_rate
|
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)
|
item_tax_map, item_code)
|
||||||
|
|
||||||
# update the item tax table
|
# 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`
|
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):
|
where ifnull(item_tax_rate, '') not in ('', '{{}}')""".format(dt), as_dict=1):
|
||||||
item_tax_map = json.loads(d.item_tax_rate)
|
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)
|
item_tax_map, d.item_code, d.parent)
|
||||||
frappe.db.set_value(dt + " Item", d.name, "item_tax_template", item_tax_template)
|
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 = frappe.get_single("Accounts Settings")
|
||||||
settings.add_taxes_from_item_tax_template = 0
|
settings.add_taxes_from_item_tax_template = 0
|
||||||
settings.determine_address_tax_category_from = "Billing Address"
|
settings.determine_address_tax_category_from = "Billing Address"
|
||||||
settings.save()
|
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
|
# search for previously created item tax template by comparing tax maps
|
||||||
for template, item_tax_template_map in iteritems(item_tax_templates):
|
for template, item_tax_template_map in iteritems(item_tax_templates):
|
||||||
if item_tax_map == item_tax_template_map:
|
if item_tax_map == item_tax_template_map:
|
||||||
|
if not parent:
|
||||||
|
rename_template_to_untitled.append(template)
|
||||||
return template
|
return template
|
||||||
|
|
||||||
# if no item tax template found, create one
|
# 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_template.append("taxes", {"tax_type": tax_type, "tax_rate": tax_rate})
|
||||||
item_tax_templates.setdefault(item_tax_template.title, {})
|
item_tax_templates.setdefault(item_tax_template.title, {})
|
||||||
item_tax_templates[item_tax_template.title][tax_type] = tax_rate
|
item_tax_templates[item_tax_template.title][tax_type] = tax_rate
|
||||||
|
|
||||||
try:
|
|
||||||
item_tax_template.save()
|
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
|
return item_tax_template.name
|
||||||
|
Loading…
Reference in New Issue
Block a user