[fix] On rename update item code in item_wise_tax_detail json in tax table

This commit is contained in:
Nabin Hait 2016-04-28 17:33:49 +05:30
parent 314246939f
commit 761a7a8e7c

View File

@ -463,10 +463,23 @@ class Item(WebsiteGenerator):
clear_cache(self.page_name) clear_cache(self.page_name)
frappe.db.set_value("Item", newdn, "item_code", newdn) frappe.db.set_value("Item", newdn, "item_code", newdn)
if merge: if merge:
self.set_last_purchase_rate(newdn) self.set_last_purchase_rate(newdn)
self.recalculate_bin_qty(newdn) self.recalculate_bin_qty(newdn)
for dt in ("Sales Taxes and Charges", "Purchase Taxes and Charges"):
for d in frappe.db.sql("""select name, item_wise_tax_detail from `tab{0}`
where ifnull(item_wise_tax_detail, '') != ''""".format(dt), as_dict=1):
item_wise_tax_detail = json.loads(d.item_wise_tax_detail)
if olddn in item_wise_tax_detail:
item_wise_tax_detail[newdn] = item_wise_tax_detail[olddn]
item_wise_tax_detail.pop(olddn)
frappe.db.set_value(dt, d.name, "item_wise_tax_detail",
json.dumps(item_wise_tax_detail), update_modified=False)
def set_last_purchase_rate(self, newdn): def set_last_purchase_rate(self, newdn):
last_purchase_rate = get_last_purchase_details(newdn).get("base_rate", 0) last_purchase_rate = get_last_purchase_details(newdn).get("base_rate", 0)
frappe.db.set_value("Item", newdn, "last_purchase_rate", last_purchase_rate) frappe.db.set_value("Item", newdn, "last_purchase_rate", last_purchase_rate)
@ -564,6 +577,7 @@ class Item(WebsiteGenerator):
frappe.throw(_("Item variant {0} exists with same attributes") frappe.throw(_("Item variant {0} exists with same attributes")
.format(variant), ItemVariantExistsError) .format(variant), ItemVariantExistsError)
def validate_end_of_life(item_code, end_of_life=None, disabled=None, verbose=1): def validate_end_of_life(item_code, end_of_life=None, disabled=None, verbose=1):
if (not end_of_life) or (disabled is None): if (not end_of_life) or (disabled is None):
end_of_life, disabled = frappe.db.get_value("Item", item_code, ["end_of_life", "disabled"]) end_of_life, disabled = frappe.db.get_value("Item", item_code, ["end_of_life", "disabled"])