diff --git a/desk/src/composables/listManager.ts b/desk/src/composables/listManager.ts index 1cfbba595..78fafd119 100644 --- a/desk/src/composables/listManager.ts +++ b/desk/src/composables/listManager.ts @@ -99,5 +99,13 @@ export function createListManager(options: ListOptions) { ); } + watch( + () => list.list.loading, + () => { + list.hasPreviousPage = false; + list.hasNextPage = false; + } + ); + return list; } diff --git a/desk/src/pages/desk/ticket-list/AssignedInfo.vue b/desk/src/pages/desk/ticket-list/AssignedInfo.vue index e29291a19..a1f0bb648 100644 --- a/desk/src/pages/desk/ticket-list/AssignedInfo.vue +++ b/desk/src/pages/desk/ticket-list/AssignedInfo.vue @@ -1,40 +1,35 @@ - - diff --git a/helpdesk/extends/client.py b/helpdesk/extends/client.py index 01c32cc0e..0dd606713 100644 --- a/helpdesk/extends/client.py +++ b/helpdesk/extends/client.py @@ -35,10 +35,13 @@ def get_list( group_by=group_by, ) - query = apply_custom_filters(doctype, query,fields=fields) + query = apply_custom_filters(doctype, query) query = apply_hook(doctype, query) query = apply_sort(doctype, order_by, query) + if not fields: + query = apply_custom_select(doctype, query) + return query.run(as_dict=True, debug=debug) @@ -104,14 +107,28 @@ def check_permissions(doctype, parent): frappe.throw(f"Insufficient Permission for {doctype}", frappe.PermissionError) -def apply_custom_filters(doctype: str, query,fields:list=[]): +def apply_custom_filters(doctype: str, query): """ Apply custom filters to query """ controller = get_controller(doctype) - if hasattr(controller, "get_list_query"): - return_value = controller.get_list_query(query,fields) + if hasattr(controller, "get_list_filters"): + return_value = controller.get_list_filters(query) + if return_value is not None: + query = return_value + + return query + + +def apply_custom_select(doctype: str, query): + """ + Apply custom select logic to query + """ + controller = get_controller(doctype) + + if hasattr(controller, "get_list_select"): + return_value = controller.get_list_select(query) if return_value is not None: query = return_value @@ -126,7 +143,7 @@ def apply_hook(doctype: str, query): _module_path = "helpdesk.helpdesk.hooks." + doctype.lower() _module = importlib.import_module(_module_path) _class = getattr(_module, doctype) - _function = getattr(_class, "get_list_query") + _function = getattr(_class, "get_list_filters") return _function(query) except: return query diff --git a/helpdesk/helpdesk/doctype/hd_article/hd_article.py b/helpdesk/helpdesk/doctype/hd_article/hd_article.py index c676d36d5..773f9a7cb 100644 --- a/helpdesk/helpdesk/doctype/hd_article/hd_article.py +++ b/helpdesk/helpdesk/doctype/hd_article/hd_article.py @@ -9,7 +9,7 @@ class HDArticle(Document): @staticmethod - def get_list_query(query): + def get_list_filters(query): QBArticle = DocType("HD Article") QBCategory = DocType("Category") @@ -84,10 +84,14 @@ def add_feedback(hd_article, helpful): field = "helpful" if helpful else "not_helpful" value = cint(frappe.db.get_value("HD Article", hd_article, field)) - frappe.db.set_value("HD Article", hd_article, field, value + 1, update_modified=False) + frappe.db.set_value( + "HD Article", hd_article, field, value + 1, update_modified=False + ) @frappe.whitelist(allow_guest=True) def increment_view(hd_article): value = cint(frappe.db.get_value("HD Article", hd_article, "views")) - frappe.db.set_value("HD Article", hd_article, "views", value + 1, update_modified=False) + frappe.db.set_value( + "HD Article", hd_article, "views", value + 1, update_modified=False + ) diff --git a/helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py b/helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py index 5f2c1afb1..9b17ed333 100644 --- a/helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py +++ b/helpdesk/helpdesk/doctype/hd_ticket/hd_ticket.py @@ -2,13 +2,12 @@ import json from datetime import timedelta -from typing import List from functools import lru_cache +from typing import List import frappe from frappe import _ from frappe.core.utils import get_parent_doc -from frappe.database.database import Criterion, Query from frappe.desk.form.assign_to import add as assign from frappe.desk.form.assign_to import clear as clear_all_assignments from frappe.email.inbox import link_communication_to_document @@ -18,6 +17,8 @@ from frappe.query_builder.functions import Count from frappe.utils import date_diff, get_datetime, now_datetime, time_diff_in_seconds from frappe.utils.user import is_website_user +from pypika.queries import Query +from pypika.terms import Criterion from helpdesk.helpdesk.doctype.hd_ticket_activity.hd_ticket_activity import ( log_ticket_activity, @@ -26,22 +27,34 @@ default_outgoing_email_account, default_ticket_outgoing_email_account, ) -from helpdesk.utils import publish_event, capture_event +from helpdesk.utils import capture_event, publish_event class HDTicket(Document): @staticmethod - def get_list_query(query: Query, fields): + def get_list_select(query: Query): QBTicket = frappe.qb.DocType("HD Ticket") - - query = HDTicket.filter_by_team(query) - if not fields: - query = query.select(QBTicket.star) + QBComment = frappe.qb.DocType("HD Ticket Comment") + QBCommunication = frappe.qb.DocType("Communication") + + query = ( + query.left_join(QBComment) + .on(QBComment.reference_ticket == QBTicket.name) + .select(Count(QBComment.name).as_("count_comment")) + .left_join(QBCommunication) + .on( + (QBCommunication.reference_doctype == "HD Ticket") + & (QBCommunication.reference_name == QBTicket.name) + ) + .select(Count(QBCommunication.name).as_("count_communication")) + .select(QBTicket.star) + .groupby(QBTicket.name) + ) return query @staticmethod - def filter_by_team(query: Query): + def get_list_filters(query: Query): user = frappe.session.user if HDTicket.can_ignore_restrictions(user): @@ -538,45 +551,6 @@ def create_communication_via_contact(self, message, attachments=[]): def mark_seen(self): self.add_seen() - def get_comment_count(self): - QBComment = DocType("HD Ticket Comment") - - count = Count("*").as_("count") - res = ( - frappe.qb.from_(QBComment) - .select(count) - .where(QBComment.reference_ticket == self.name) - .run(as_dict=True) - ) - - return res.pop().count - - def get_conversation_count(self): - QBCommunication = DocType("Communication") - - count = Count("*").as_("count") - res = ( - frappe.qb.from_(QBCommunication) - .select(count) - .where(QBCommunication.reference_doctype == "HD Ticket") - .where(QBCommunication.reference_name == self.name) - .run(as_dict=True) - ) - - return res.pop().count - - def is_seen(self): - seen = self._seen or "" - return frappe.session.user in seen - - @frappe.whitelist() - def get_meta(self): - return { - "comment_count": self.get_comment_count(), - "conversation_count": self.get_conversation_count(), - "is_seen": self.is_seen(), - } - @frappe.whitelist() def get_assignees(self): QBUser = DocType("User") diff --git a/helpdesk/helpdesk/hooks/contact.py b/helpdesk/helpdesk/hooks/contact.py index 99cec23cd..ac8d153a1 100644 --- a/helpdesk/helpdesk/hooks/contact.py +++ b/helpdesk/helpdesk/hooks/contact.py @@ -2,25 +2,25 @@ class Contact: - @staticmethod - def get_list_query(query): - QBContact = frappe.qb.DocType("Contact") - QBEmail = frappe.qb.DocType("Contact Email") - QBPhone = frappe.qb.DocType("Contact Phone") - QBLink = frappe.qb.DocType("Dynamic Link") + @staticmethod + def get_list_filters(query): + QBContact = frappe.qb.DocType("Contact") + QBEmail = frappe.qb.DocType("Contact Email") + QBPhone = frappe.qb.DocType("Contact Phone") + QBLink = frappe.qb.DocType("Dynamic Link") - query = ( - query.select(QBContact.first_name) - .select(QBContact.last_name) - .left_join(QBEmail) - .on(QBEmail.parent == QBContact.name) - .select(QBEmail.email_id) - .left_join(QBPhone) - .on(QBPhone.parent == QBContact.name) - .select(QBPhone.phone) - .left_join(QBLink) - .on(QBLink.parent == QBContact.name) - .select(QBLink.link_name) - ) + query = ( + query.select(QBContact.first_name) + .select(QBContact.last_name) + .left_join(QBEmail) + .on(QBEmail.parent == QBContact.name) + .select(QBEmail.email_id) + .left_join(QBPhone) + .on(QBPhone.parent == QBContact.name) + .select(QBPhone.phone) + .left_join(QBLink) + .on(QBLink.parent == QBContact.name) + .select(QBLink.link_name) + ) - return query + return query