Skip to content

Commit

Permalink
fix: add customer portal options in API
Browse files Browse the repository at this point in the history
  • Loading branch information
RitvikSardana committed Sep 29, 2024
1 parent 54266a7 commit ae6a26b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 17 deletions.
9 changes: 8 additions & 1 deletion desk/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ const routes = [
{
path: "",
name: "TicketsCustomer",
component: () => import("@/pages/TicketsCustomer.vue"),
component: () => import("@/pages/TicketsAgent.vue"),
meta: {
public: true,
},
},
{
path: "new/:templateId?",
Expand All @@ -88,13 +91,17 @@ const routes = [
meta: {
onSuccessRoute: "TicketCustomer",
parent: "TicketsCustomer",
public: true,
},
},
{
path: ":ticketId",
name: "TicketCustomer",
component: () => import("@/pages/TicketCustomer.vue"),
props: true,
meta: {
public: true,
},
},
],
},
Expand Down
73 changes: 57 additions & 16 deletions helpdesk/api/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@frappe.whitelist()
@redis_cache()
def get_filterable_fields(doctype):
def get_filterable_fields(doctype: str, show_customer_portal_fields=False):
check_permissions(doctype, None)
QBDocField = frappe.qb.DocType("DocField")
QBCustomField = frappe.qb.DocType("Custom Field")
Expand All @@ -25,6 +25,15 @@ def get_filterable_fields(doctype):
"Text Editor",
"Text",
]
customer_portal_fields = [
"name",
"subject",
"status",
"priority",
"response_by",
"resolution_by",
"creation",
]

from_doc_fields = (
frappe.qb.from_(QBDocField)
Expand All @@ -38,9 +47,16 @@ def get_filterable_fields(doctype):
.where(QBDocField.parent == doctype)
.where(QBDocField.hidden == False)
.where(Criterion.any([QBDocField.fieldtype == i for i in allowed_fieldtypes]))
.run(as_dict=True)
)

# for customer portal show only fields present in customer_portal_fields
if show_customer_portal_fields:
from_doc_fields = from_doc_fields.where(
QBDocField.fieldname.isin(customer_portal_fields)
)

from_doc_fields = from_doc_fields.run(as_dict=True)

from_custom_fields = (
frappe.qb.from_(QBCustomField)
.select(
Expand All @@ -58,26 +74,32 @@ def get_filterable_fields(doctype):
.run(as_dict=True)
)

# from hd ticket template get children with fieldname and hidden_from_customer

res = []
res.extend(from_doc_fields)
res.extend(from_custom_fields)
res.extend(
[
if not show_customer_portal_fields:
# TODO: Ritvik => till a better way we have for custom fields, dont show custom fields in customer portal
res.extend(from_custom_fields)
res.append(
{
"fieldname": "_assign",
"fieldtype": "Link",
"label": "Assigned to",
"name": "_assign",
"options": "HD Agent",
},
{
"fieldname": "name",
"fieldtype": "Data",
"label": "ID",
"name": "name",
},
]
}
)

res.append(
{
"fieldname": "name",
"fieldtype": "Data",
"label": "ID",
"name": "name",
},
)

return res


Expand Down Expand Up @@ -187,7 +209,7 @@ def get_list_data(


@frappe.whitelist()
def sort_options(doctype: str):
def sort_options(doctype: str, show_customer_portal_fields=False):
fields = frappe.get_meta(doctype).fields
fields = [field for field in fields if field.fieldtype not in no_value_fields]
fields = [
Expand All @@ -199,6 +221,26 @@ def sort_options(doctype: str):
if field.label and field.fieldname
]

if show_customer_portal_fields:
custom_fields = frappe.db.get_all(
"Custom Field", {"dt": doctype}, pluck="fieldname"
)
customer_portal_fields = [
"name",
"subject",
"status",
"priority",
"response_by",
"resolution_by",
"creation",
]
fields = [
field
for field in fields
if field.get("value") not in custom_fields
and field.get("value") in customer_portal_fields
]

standard_fields = [
{"label": "Name", "value": "name"},
{"label": "Created On", "value": "creation"},
Expand All @@ -207,7 +249,6 @@ def sort_options(doctype: str):
{"label": "Owner", "value": "owner"},
]

for field in standard_fields:
fields.append(field)
fields.extend(standard_fields)

return fields

0 comments on commit ae6a26b

Please sign in to comment.