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
This commit is contained in:
parent
a813571c17
commit
580fa48642
@ -130,6 +130,11 @@ def get_customers_suppliers(doctype, user):
|
|||||||
suppliers = []
|
suppliers = []
|
||||||
meta = frappe.get_meta(doctype)
|
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)):
|
if has_common(["Supplier", "Customer"], frappe.get_roles(user)):
|
||||||
contacts = frappe.db.sql("""
|
contacts = frappe.db.sql("""
|
||||||
select
|
select
|
||||||
@ -141,27 +146,40 @@ def get_customers_suppliers(doctype, user):
|
|||||||
where
|
where
|
||||||
`tabContact`.name=`tabDynamic Link`.parent and `tabContact`.email_id =%s
|
`tabContact`.name=`tabDynamic Link`.parent and `tabContact`.email_id =%s
|
||||||
""", user, as_dict=1)
|
""", user, as_dict=1)
|
||||||
customers = [c.link_name for c in contacts if c.link_doctype == 'Customer'] \
|
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']
|
||||||
suppliers = [c.link_name for c in contacts if c.link_doctype == 'Supplier'] \
|
|
||||||
if meta.get_field("supplier") else None
|
|
||||||
elif frappe.has_permission(doctype, 'read', user=user):
|
elif frappe.has_permission(doctype, 'read', user=user):
|
||||||
customers = [customer.name for customer in frappe.get_list("Customer")] \
|
customer_list = frappe.get_list("Customer")
|
||||||
if meta.get_field("customer") else None
|
customers = suppliers = [customer.name for customer in customer_list]
|
||||||
suppliers = [supplier.name for supplier in frappe.get_list("Customer")] \
|
|
||||||
if meta.get_field("supplier") else None
|
|
||||||
|
|
||||||
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):
|
def has_website_permission(doc, ptype, user, verbose=False):
|
||||||
doctype = doc.doctype
|
doctype = doc.doctype
|
||||||
customers, suppliers = get_customers_suppliers(doctype, user)
|
customers, suppliers = get_customers_suppliers(doctype, user)
|
||||||
if customers:
|
if customers:
|
||||||
return frappe.get_all(doctype, filters=[(doctype, "customer", "in", customers),
|
return frappe.db.exists(doctype, filters=get_customer_filter(doc, customers))
|
||||||
(doctype, "name", "=", doc.name)]) and True or False
|
|
||||||
elif suppliers:
|
elif suppliers:
|
||||||
fieldname = 'suppliers' if doctype == 'Request for Quotation' else 'supplier'
|
fieldname = 'suppliers' if doctype == 'Request for Quotation' else 'supplier'
|
||||||
return frappe.get_all(doctype, filters=[(doctype, fieldname, "in", suppliers),
|
return frappe.db.exists(doctype, filters={
|
||||||
(doctype, "name", "=", doc.name)]) and True or False
|
'name': doc.name,
|
||||||
|
fieldname: ["in", suppliers]
|
||||||
|
})
|
||||||
else:
|
else:
|
||||||
return False
|
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'
|
Loading…
x
Reference in New Issue
Block a user