Skip to content

Commit

Permalink
Merge pull request #1024 from frappe/fix/contact_list_fetch
Browse files Browse the repository at this point in the history
fix: contact list fetch
  • Loading branch information
ssiyad authored Mar 1, 2023
2 parents 906e62a + b107ba0 commit e9ca7dd
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 16 deletions.
8 changes: 0 additions & 8 deletions desk/src/pages/desk/Contacts.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
<template>
<div class="flex flex-col px-4 overflow-hidden">
<ListManager

ref="contactList"
:options="{
cache: ['Contacts', 'Desk'],
doctype: 'Contact',
urlQueryFilters: true,
saveFiltersLocally: true,
fields: [
'first_name',
'last_name',
'email_ids.email_id as email',
'phone_nos.phone as phone',
'links.link_name as customer',
],
limit: 20,
}"
>
Expand Down
2 changes: 1 addition & 1 deletion frappedesk/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.6.1"
__version__ = "0.6.4"
23 changes: 20 additions & 3 deletions frappedesk/extends/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

import importlib

import frappe
from frappe.model.base_document import get_controller

Expand Down Expand Up @@ -31,9 +33,10 @@ def get_list(
group_by=group_by,
)

custom_query = apply_custom_filters(doctype, query)
query = apply_custom_filters(doctype, query)
query = apply_hook(doctype, query)

return custom_query.run(as_dict=True, debug=debug)
return query.run(as_dict=True, debug=debug)


def check_permissions(doctype, parent):
Expand All @@ -48,7 +51,7 @@ def check_permissions(doctype, parent):
frappe.throw(f"Insufficient Permission for {doctype}", frappe.PermissionError)


def apply_custom_filters(doctype, query):
def apply_custom_filters(doctype: str, query):
"""
Apply custom filters to query
"""
Expand All @@ -60,3 +63,17 @@ def apply_custom_filters(doctype, query):
query = return_value

return query


def apply_hook(doctype: str, query):
"""
Apply hooks to query
"""
try:
_module_path = "frappedesk.frappedesk.hooks." + doctype.lower()
_module = importlib.import_module(_module_path)
_class = getattr(_module, doctype)
_function = getattr(_class, "get_list_query")
return _function(query)
except:
return query
9 changes: 5 additions & 4 deletions frappedesk/extends/qb.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ def extract_order_by(params: dict) -> tuple[str, str]:
:param params: Dict of call parameters
:return: Order by field and order direction
"""
order_by: list = params.get(ORDER_BY_FIELD, DEFAULT_ORDER_FIELD).split(" ")
order_by = params.get(ORDER_BY_FIELD) or DEFAULT_ORDER_FIELD
result: list = order_by.split(" ")

if len(order_by) < 2:
return order_by.pop(), DEFAULT_ORDER_DIR
if len(result) < 2:
return result.pop(), DEFAULT_ORDER_DIR

return order_by
return result
26 changes: 26 additions & 0 deletions frappedesk/frappedesk/hooks/contact.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import frappe


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")

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

0 comments on commit e9ca7dd

Please sign in to comment.