Skip to content

Commit

Permalink
bug portal
Browse files Browse the repository at this point in the history
  • Loading branch information
bvisible authored Nov 6, 2023
1 parent c4893e6 commit aaafbc9
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions erpnext/controllers/website_list_for_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,14 @@ def get_customers_suppliers(doctype, user):
if has_common(["Supplier", "Customer"], frappe.get_roles(user)):
suppliers = get_parents_for_user("Supplier")
customers = get_parents_for_user("Customer")
#////
if customers:
for idx, customer in enumerate(customers):
customers[idx] = frappe.db.get_value("Customer", {"email_id":customer}, "name")
else:
self_customer = frappe.db.get_value("Customer", {"email_id": user}, "name")
customers = [self_customer] if self_customer else []
#////
elif frappe.has_permission(doctype, "read", user=user):
customer_list = frappe.get_list("Customer")
customers = suppliers = [customer.name for customer in customer_list]
Expand All @@ -245,11 +253,28 @@ def get_customers_suppliers(doctype, user):

def get_parents_for_user(parenttype: str) -> list[str]:
portal_user = frappe.qb.DocType("Portal User")
'''
#/// code to merge in erpnext
customer = frappe.qb.DocType("Customer")
query = (
frappe.qb
.from_(portal_user)
.left_join(customer)
.on(customer.email_id == portal_user.user)
.select(customer.name)
.where(portal_user.parenttype == parenttype)
).run(pluck="name")
if not query:
return portal_user.parent
return query
'''

return (
frappe.qb.from_(portal_user)
.select(portal_user.parent)
.where(portal_user.user == frappe.session.user)
.select(portal_user.user) #//// .select(portal_user.parent
#////.where(portal_user.user == frappe.session.user)
.where(portal_user.parenttype == parenttype)
).run(pluck="name")

Expand Down

0 comments on commit aaafbc9

Please sign in to comment.