From 580fa486420b6ed93b197ecd545e3fe8e63226e1 Mon Sep 17 00:00:00 2001 From: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> Date: Mon, 5 Aug 2019 10:08:35 +0530 Subject: [PATCH] fix: Quotation list in customer portal (#18579) * fix: Quotation list in customer portal Customers were not able to see their quotations because of the recent customer field removal from quotation * fix: Remove duplicate code --- .../controllers/website_list_for_contact.py | 50 +++++++++++++------ 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/erpnext/controllers/website_list_for_contact.py b/erpnext/controllers/website_list_for_contact.py index ed48fd1ab4..187eaed107 100644 --- a/erpnext/controllers/website_list_for_contact.py +++ b/erpnext/controllers/website_list_for_contact.py @@ -77,7 +77,7 @@ def get_list_for_transactions(doctype, txt, filters, limit_start, limit_page_len if or_filters: for r in frappe.get_list(doctype, fields=fields,filters=filters, or_filters=or_filters, - limit_start=limit_start, limit_page_length=limit_page_length, + limit_start=limit_start, limit_page_length=limit_page_length, ignore_permissions=ignore_permissions, order_by=order_by): data.append(r) @@ -130,38 +130,56 @@ def get_customers_suppliers(doctype, user): suppliers = [] meta = frappe.get_meta(doctype) + customer_field_name = get_customer_field_name(doctype) + + has_customer_field = meta.has_field(customer_field_name) + has_supplier_field = meta.has_field('supplier') + if has_common(["Supplier", "Customer"], frappe.get_roles(user)): contacts = frappe.db.sql(""" - select + select `tabContact`.email_id, `tabDynamic Link`.link_doctype, `tabDynamic Link`.link_name - from + from `tabContact`, `tabDynamic Link` where `tabContact`.name=`tabDynamic Link`.parent and `tabContact`.email_id =%s """, user, as_dict=1) - customers = [c.link_name for c in contacts if c.link_doctype == 'Customer'] \ - if meta.get_field("customer") else None - suppliers = [c.link_name for c in contacts if c.link_doctype == 'Supplier'] \ - if meta.get_field("supplier") else None + customers = [c.link_name for c in contacts if c.link_doctype == 'Customer'] + suppliers = [c.link_name for c in contacts if c.link_doctype == 'Supplier'] elif frappe.has_permission(doctype, 'read', user=user): - customers = [customer.name for customer in frappe.get_list("Customer")] \ - if meta.get_field("customer") else None - suppliers = [supplier.name for supplier in frappe.get_list("Customer")] \ - if meta.get_field("supplier") else None + customer_list = frappe.get_list("Customer") + customers = suppliers = [customer.name for customer in customer_list] - return customers, suppliers + return customers if has_customer_field else None, \ + suppliers if has_supplier_field else None def has_website_permission(doc, ptype, user, verbose=False): doctype = doc.doctype customers, suppliers = get_customers_suppliers(doctype, user) if customers: - return frappe.get_all(doctype, filters=[(doctype, "customer", "in", customers), - (doctype, "name", "=", doc.name)]) and True or False + return frappe.db.exists(doctype, filters=get_customer_filter(doc, customers)) elif suppliers: fieldname = 'suppliers' if doctype == 'Request for Quotation' else 'supplier' - return frappe.get_all(doctype, filters=[(doctype, fieldname, "in", suppliers), - (doctype, "name", "=", doc.name)]) and True or False + return frappe.db.exists(doctype, filters={ + 'name': doc.name, + fieldname: ["in", suppliers] + }) else: return False + +def get_customer_filter(doc, customers): + doctype = doc.doctype + filters = frappe._dict() + filters.name = doc.name + filters[get_customer_field_name(doctype)] = ['in', customers] + if doctype == 'Quotation': + filters.party_type = 'Customer' + return filters + +def get_customer_field_name(doctype): + if doctype == 'Quotation': + return 'party_name' + else: + return 'customer' \ No newline at end of file