Patches fixes (#13163)

* [fix] if serialised items not found then return

* [fix] unicode encoding in patch
This commit is contained in:
Saurabh 2018-03-05 13:01:15 +05:30 committed by Nabin Hait
parent 2550180a05
commit 2cfcbf933d
2 changed files with 12 additions and 14 deletions

View File

@ -7,6 +7,9 @@ import frappe
def execute():
serialised_items = [d.name for d in frappe.get_all("Item", filters={"has_serial_no": 1})]
if not serialised_items:
return
for dt in ["Stock Entry Detail", "Purchase Receipt Item", "Purchase Invoice Item"]:
cond = ""
if dt=="Purchase Invoice Item":

View File

@ -13,22 +13,17 @@ def execute():
for d in customer_group_fetch:
when_then = []
for customer in batch_customers:
value = frappe.db.escape(frappe.as_unicode(customer.get("customer_group")))
when_then.append('''
WHEN `{master_fieldname}` = "{docname}" and {linked_to_fieldname} != "{value}"
THEN "{value}"
'''.format(
master_fieldname=d["master_fieldname"],
linked_to_fieldname=d["linked_to_fieldname"],
docname=frappe.db.escape(frappe.as_unicode(customer.name)),
value=frappe.db.escape(frappe.as_unicode(customer.get("customer_group")))))
WHEN `%s` = "%s" and %s != "%s"
THEN "%s"
'''%(d["master_fieldname"], frappe.db.escape(frappe.as_unicode(customer.name)),
d["linked_to_fieldname"], value, value))
frappe.db.sql("""
update
`tab{doctype}`
`tab%s`
set
{linked_to_fieldname} = CASE {when_then_cond} ELSE `{linked_to_fieldname}` END
""".format(
doctype = d['doctype'],
when_then_cond=" ".join(when_then),
linked_to_fieldname=d.linked_to_fieldname
))
%s = CASE %s ELSE `%s` END
"""%(d['doctype'], d.linked_to_fieldname, " ".join(when_then), d.linked_to_fieldname))