From 5852acec426bfcc62d09f338befa99284754e7f1 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Mon, 27 Nov 2023 16:35:36 +0530 Subject: [PATCH 01/16] fix: added crm list view settings doctype --- .../crm_list_view_settings/__init__.py | 0 .../crm_list_view_settings.js | 8 +++ .../crm_list_view_settings.json | 52 +++++++++++++++++++ .../crm_list_view_settings.py | 9 ++++ .../test_crm_list_view_settings.py | 9 ++++ 5 files changed, 78 insertions(+) create mode 100644 crm/fcrm/doctype/crm_list_view_settings/__init__.py create mode 100644 crm/fcrm/doctype/crm_list_view_settings/crm_list_view_settings.js create mode 100644 crm/fcrm/doctype/crm_list_view_settings/crm_list_view_settings.json create mode 100644 crm/fcrm/doctype/crm_list_view_settings/crm_list_view_settings.py create mode 100644 crm/fcrm/doctype/crm_list_view_settings/test_crm_list_view_settings.py diff --git a/crm/fcrm/doctype/crm_list_view_settings/__init__.py b/crm/fcrm/doctype/crm_list_view_settings/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/crm/fcrm/doctype/crm_list_view_settings/crm_list_view_settings.js b/crm/fcrm/doctype/crm_list_view_settings/crm_list_view_settings.js new file mode 100644 index 00000000..87850935 --- /dev/null +++ b/crm/fcrm/doctype/crm_list_view_settings/crm_list_view_settings.js @@ -0,0 +1,8 @@ +// Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +// frappe.ui.form.on("CRM List View Settings", { +// refresh(frm) { + +// }, +// }); diff --git a/crm/fcrm/doctype/crm_list_view_settings/crm_list_view_settings.json b/crm/fcrm/doctype/crm_list_view_settings/crm_list_view_settings.json new file mode 100644 index 00000000..47675244 --- /dev/null +++ b/crm/fcrm/doctype/crm_list_view_settings/crm_list_view_settings.json @@ -0,0 +1,52 @@ +{ + "actions": [], + "allow_rename": 1, + "autoname": "prompt", + "creation": "2023-11-27 16:29:10.993403", + "doctype": "DocType", + "engine": "InnoDB", + "field_order": [ + "user", + "columns" + ], + "fields": [ + { + "fieldname": "columns", + "fieldtype": "Code", + "label": "Columns" + }, + { + "fieldname": "user", + "fieldtype": "Link", + "label": "User", + "options": "User" + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2023-11-27 16:34:16.393091", + "modified_by": "Administrator", + "module": "FCRM", + "name": "CRM List View Settings", + "naming_rule": "Set by user", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "read_only": 1, + "sort_field": "modified", + "sort_order": "DESC", + "states": [], + "track_changes": 1 +} \ No newline at end of file diff --git a/crm/fcrm/doctype/crm_list_view_settings/crm_list_view_settings.py b/crm/fcrm/doctype/crm_list_view_settings/crm_list_view_settings.py new file mode 100644 index 00000000..e388373a --- /dev/null +++ b/crm/fcrm/doctype/crm_list_view_settings/crm_list_view_settings.py @@ -0,0 +1,9 @@ +# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + + +class CRMListViewSettings(Document): + pass diff --git a/crm/fcrm/doctype/crm_list_view_settings/test_crm_list_view_settings.py b/crm/fcrm/doctype/crm_list_view_settings/test_crm_list_view_settings.py new file mode 100644 index 00000000..d99027bc --- /dev/null +++ b/crm/fcrm/doctype/crm_list_view_settings/test_crm_list_view_settings.py @@ -0,0 +1,9 @@ +# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt + +# import frappe +from frappe.tests.utils import FrappeTestCase + + +class TestCRMListViewSettings(FrappeTestCase): + pass From e3116371763a320798221163b4b2345d6c082bae Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Mon, 27 Nov 2023 18:26:15 +0530 Subject: [PATCH 02/16] feat: load list column from default lead/deal list data from backend --- crm/api/doc.py | 33 +++++- crm/fcrm/doctype/crm_deal/crm_deal.py | 42 +++++++ crm/fcrm/doctype/crm_lead/crm_lead.py | 42 +++++++ frontend/src/pages/Deals.vue | 129 ++++++++-------------- frontend/src/pages/Leads.vue | 151 ++++++++++---------------- 5 files changed, 219 insertions(+), 178 deletions(-) diff --git a/crm/api/doc.py b/crm/api/doc.py index dd0c7cc9..6b012bdc 100644 --- a/crm/api/doc.py +++ b/crm/api/doc.py @@ -12,6 +12,7 @@ def sort_options(doctype: str): return c.sort_options() + @frappe.whitelist() def get_filterable_fields(doctype: str): DocField = frappe.qb.DocType("DocField") @@ -46,6 +47,34 @@ def get_filterable_fields(doctype: str): res.extend(from_doc_fields) return res + +@frappe.whitelist() +def get_list_data(doctype: str, filters: dict, order_by: str): + columns = [] + rows = [] + + data_fields = [] + + list = get_controller(doctype) + + if hasattr(list, "default_list_data"): + columns = list.default_list_data().get("columns") + data_fields = list.default_list_data().get("data_fields") + + rows = [i['key'] for i in columns] + rows = rows + data_fields + + data = frappe.get_all( + doctype, + fields=rows, + filters=filters, + order_by=order_by, + page_length=20, + ) or [] + + return {'data': data, 'columns': columns, 'rows': rows} + + @frappe.whitelist() def get_doctype_fields(doctype): not_allowed_fieldtypes = [ @@ -87,6 +116,7 @@ def get_doctype_fields(doctype): return all_fields + def get_field_obj(field): obj = { "label": field.label, @@ -107,6 +137,7 @@ def get_field_obj(field): return obj + def get_type(field): if field.fieldtype == "Data" and field.options == "Phone": return "phone" @@ -120,4 +151,4 @@ def get_type(field): return "textarea" elif field.read_only: return "read_only" - return field.fieldtype.lower() \ No newline at end of file + return field.fieldtype.lower() diff --git a/crm/fcrm/doctype/crm_deal/crm_deal.py b/crm/fcrm/doctype/crm_deal/crm_deal.py index c1f34b28..89308420 100644 --- a/crm/fcrm/doctype/crm_deal/crm_deal.py +++ b/crm/fcrm/doctype/crm_deal/crm_deal.py @@ -57,6 +57,48 @@ class CRMDeal(Document): { "label": 'Mobile no', "value": 'mobile_no' }, ] + @staticmethod + def default_list_data(): + columns = [ + { + 'label': 'Organization', + 'key': 'organization', + 'width': '11rem', + }, + { + 'label': 'Amount', + 'key': 'annual_revenue', + 'width': '9rem', + }, + { + 'label': 'Status', + 'key': 'status', + 'width': '10rem', + }, + { + 'label': 'Email', + 'key': 'email', + 'width': '12rem', + }, + { + 'label': 'Mobile no', + 'key': 'mobile_no', + 'width': '11rem', + }, + { + 'label': 'Deal owner', + 'key': 'deal_owner', + 'width': '10rem', + }, + { + 'label': 'Last modified', + 'key': 'modified', + 'width': '8rem', + }, + ] + data_fields = ['name'] + return {'columns': columns, 'data_fields': data_fields} + @frappe.whitelist() def add_contact(deal, contact): if not frappe.has_permission("CRM Deal", "write", deal): diff --git a/crm/fcrm/doctype/crm_lead/crm_lead.py b/crm/fcrm/doctype/crm_lead/crm_lead.py index 6b016b4a..7c88d480 100644 --- a/crm/fcrm/doctype/crm_lead/crm_lead.py +++ b/crm/fcrm/doctype/crm_lead/crm_lead.py @@ -136,6 +136,48 @@ class CRMLead(Document): { "label": 'Mobile no', "value": 'mobile_no' }, ] + @staticmethod + def default_list_data(): + columns = [ + { + 'label': 'Name', + 'key': 'lead_name', + 'width': '12rem', + }, + { + 'label': 'Organization', + 'key': 'organization', + 'width': '10rem', + }, + { + 'label': 'Status', + 'key': 'status', + 'width': '8rem', + }, + { + 'label': 'Email', + 'key': 'email', + 'width': '12rem', + }, + { + 'label': 'Mobile no', + 'key': 'mobile_no', + 'width': '11rem', + }, + { + 'label': 'Lead owner', + 'key': 'lead_owner', + 'width': '10rem', + }, + { + 'label': 'Last modified', + 'key': 'modified', + 'width': '8rem', + }, + ] + data_fields = ['name', 'first_name', 'image'] + return {'columns': columns, 'data_fields': data_fields} + @frappe.whitelist() def convert_to_deal(lead): if not frappe.has_permission("CRM Lead", "write", lead): diff --git a/frontend/src/pages/Deals.vue b/frontend/src/pages/Deals.vue index 3edbc493..ca0b1897 100644 --- a/frontend/src/pages/Deals.vue +++ b/frontend/src/pages/Deals.vue @@ -33,7 +33,7 @@