From dace2b6796421908b4922ec4402429dab1dcd279 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 1 Oct 2015 13:54:46 +0530 Subject: [PATCH] [fix] get permission query condition if no permitted links --- erpnext/utilities/address_and_contact.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/erpnext/utilities/address_and_contact.py b/erpnext/utilities/address_and_contact.py index 9341adfb41..d175db6649 100644 --- a/erpnext/utilities/address_and_contact.py +++ b/erpnext/utilities/address_and_contact.py @@ -53,13 +53,23 @@ def get_permission_query_conditions(doctype): if not links.get("not_permitted_links"): # when everything is permitted, don't add additional condition return "" + + elif not links.get("permitted_links"): + conditions = [] + + # when everything is not permitted + for df in links.get("not_permitted_links"): + # like ifnull(customer, '')='' and ifnull(supplier, '')='' + conditions.append("ifnull(`tab{doctype}`.`{fieldname}`, '')=''".format(doctype=doctype, fieldname=df.fieldname)) + + return "( " + " and ".join(conditions) + " )" else: conditions = [] for df in links.get("permitted_links"): # like ifnull(customer, '')!='' or ifnull(supplier, '')!='' - conditions.append("ifnull(`tab{doctype}`.`{fieldname}`, '')!=''".format(doctype=doctype, fieldname=df.fieldname)) + conditions.append("ifnull(`tab{doctype}`.`{fieldname}`, '')!=''".format(doctype=doctype, fieldname=df.fieldname)) return "( " + " or ".join(conditions) + " )"