From a751b2d3e9a06b95a6752ac9e8938e201b9c0034 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Thu, 25 Jan 2024 21:36:34 +0530 Subject: [PATCH] fix: allow all valid fields in sort by dropdown --- crm/api/doc.py | 25 ++++++++++++++++--- crm/fcrm/doctype/crm_call_log/crm_call_log.py | 14 ----------- crm/fcrm/doctype/crm_deal/crm_deal.py | 12 --------- crm/fcrm/doctype/crm_lead/crm_lead.py | 15 ----------- .../crm_organization/crm_organization.py | 11 -------- crm/overrides/contact.py | 13 ---------- 6 files changed, 21 insertions(+), 69 deletions(-) diff --git a/crm/api/doc.py b/crm/api/doc.py index abb12ca1..a9fc2237 100644 --- a/crm/api/doc.py +++ b/crm/api/doc.py @@ -8,12 +8,29 @@ from crm.api.views import get_views @frappe.whitelist() def sort_options(doctype: str): - c = get_controller(doctype) + fields = frappe.get_meta(doctype).fields + fields = [field for field in fields if field.fieldtype not in no_value_fields] + fields = [ + { + "label": field.label, + "value": field.fieldname, + } + for field in fields + if field.label and field.fieldname + ] - if not hasattr(c, "sort_options"): - return [] + standard_fields = [ + {"label": "Name", "value": "name"}, + {"label": "Created On", "value": "creation"}, + {"label": "Last Modified", "value": "modified"}, + {"label": "Modified By", "value": "modified_by"}, + {"label": "Owner", "value": "owner"}, + ] - return c.sort_options() + for field in standard_fields: + fields.append(field) + + return fields @frappe.whitelist() diff --git a/crm/fcrm/doctype/crm_call_log/crm_call_log.py b/crm/fcrm/doctype/crm_call_log/crm_call_log.py index a1b3b594..8d61dde3 100644 --- a/crm/fcrm/doctype/crm_call_log/crm_call_log.py +++ b/crm/fcrm/doctype/crm_call_log/crm_call_log.py @@ -6,20 +6,6 @@ from frappe.model.document import Document class CRMCallLog(Document): - @staticmethod - def sort_options(): - return [ - { "label": 'Created', "value": 'creation' }, - { "label": 'Modified', "value": 'modified' }, - { "label": 'Status', "value": 'status' }, - { "label": 'Type', "value": 'type' }, - { "label": 'Duration', "value": 'duration' }, - { "label": 'From', "value": 'from' }, - { "label": 'To', "value": 'to' }, - { "label": 'Caller', "value": 'caller' }, - { "label": 'Receiver', "value": 'receiver' }, - ] - @staticmethod def default_list_data(): columns = [ diff --git a/crm/fcrm/doctype/crm_deal/crm_deal.py b/crm/fcrm/doctype/crm_deal/crm_deal.py index 23208844..44034e92 100644 --- a/crm/fcrm/doctype/crm_deal/crm_deal.py +++ b/crm/fcrm/doctype/crm_deal/crm_deal.py @@ -114,18 +114,6 @@ class CRMDeal(Document): if sla: sla.apply(self) - @staticmethod - def sort_options(): - return [ - { "label": 'Created', "value": 'creation' }, - { "label": 'Modified', "value": 'modified' }, - { "label": 'Status', "value": 'status' }, - { "label": 'Deal owner', "value": 'deal_owner' }, - { "label": 'Organization', "value": 'organization' }, - { "label": 'Email', "value": 'email' }, - { "label": 'Mobile no', "value": 'mobile_no' }, - ] - @staticmethod def default_list_data(): columns = [ diff --git a/crm/fcrm/doctype/crm_lead/crm_lead.py b/crm/fcrm/doctype/crm_lead/crm_lead.py index 4a918a3c..7cafc54c 100644 --- a/crm/fcrm/doctype/crm_lead/crm_lead.py +++ b/crm/fcrm/doctype/crm_lead/crm_lead.py @@ -206,21 +206,6 @@ class CRMLead(Document): if sla: sla.apply(self) - @staticmethod - def sort_options(): - return [ - { "label": 'Created', "value": 'creation' }, - { "label": 'Modified', "value": 'modified' }, - { "label": 'Status', "value": 'status' }, - { "label": 'Lead owner', "value": 'lead_owner' }, - { "label": 'Organization', "value": 'organization' }, - { "label": 'Name', "value": 'lead_name' }, - { "label": 'First Name', "value": 'first_name' }, - { "label": 'Last Name', "value": 'last_name' }, - { "label": 'Email', "value": 'email' }, - { "label": 'Mobile no', "value": 'mobile_no' }, - ] - @staticmethod def get_non_filterable_fields(): return ["converted"] diff --git a/crm/fcrm/doctype/crm_organization/crm_organization.py b/crm/fcrm/doctype/crm_organization/crm_organization.py index 0636909c..f1ecaae9 100644 --- a/crm/fcrm/doctype/crm_organization/crm_organization.py +++ b/crm/fcrm/doctype/crm_organization/crm_organization.py @@ -26,17 +26,6 @@ class CRMOrganization(Document): if self.has_value_changed("annual_revenue"): frappe.db.set_value("CRM Deal", deal.name, "annual_revenue", self.annual_revenue) - @staticmethod - def sort_options(): - return [ - { "label": 'Created', "value": 'creation' }, - { "label": 'Modified', "value": 'modified' }, - { "label": 'Name', "value": 'name' }, - { "label": 'Website', "value": 'website' }, - { "label": 'Amount', "value": 'annual_revenue' }, - { "label": 'Industry', "value": 'industry' }, - ] - @staticmethod def default_list_data(): columns = [ diff --git a/crm/overrides/contact.py b/crm/overrides/contact.py index 8316e0f8..9845c398 100644 --- a/crm/overrides/contact.py +++ b/crm/overrides/contact.py @@ -4,19 +4,6 @@ from frappe.contacts.doctype.contact.contact import Contact class CustomContact(Contact): - @staticmethod - def sort_options(): - return [ - { "label": 'Created', "value": 'creation' }, - { "label": 'Modified', "value": 'modified' }, - { "label": 'Organization', "value": 'company_name' }, - { "label": 'Full Name', "value": 'full_name' }, - { "label": 'First Name', "value": 'first_name' }, - { "label": 'Last Name', "value": 'last_name' }, - { "label": 'Email', "value": 'email' }, - { "label": 'Mobile no', "value": 'mobile_no' }, - ] - @staticmethod def default_list_data(): columns = [