Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Custom Columns in lead/deal list view #32

Merged
merged 16 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 61 additions & 1 deletion crm/api/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -46,6 +47,63 @@ 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 = []

if frappe.db.exists("CRM List View Settings", doctype):
list_view_settings = frappe.get_doc("CRM List View Settings", doctype)
columns = frappe.parse_json(list_view_settings.columns)
rows = frappe.parse_json(list_view_settings.rows)
else:
list = get_controller(doctype)

if hasattr(list, "default_list_data"):
columns = list.default_list_data().get("columns")
rows = list.default_list_data().get("rows")

# check if rows has all keys from columns if not add them
for column in columns:
if column.get("key") not in rows:
rows.append(column.get("key"))

data = frappe.get_all(
doctype,
fields=rows,
filters=filters,
order_by=order_by,
page_length=20,
) or []

not_allowed_fieldtypes = [
"Section Break",
"Column Break",
"Tab Break",
]

fields = frappe.get_meta(doctype).fields
fields = [field for field in fields if field.fieldtype not in not_allowed_fieldtypes]
fields = [{"label": field.label, "value": field.fieldname} for field in fields if field.label and field.fieldname]

std_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'},
]

for field in std_fields:
if field.get('value') not in rows:
rows.append(field.get('value'))
if field not in fields:
fields.append(field)

return {'data': data, 'columns': columns, 'rows': rows, 'fields': fields}


@frappe.whitelist()
def get_doctype_fields(doctype):
not_allowed_fieldtypes = [
Expand Down Expand Up @@ -87,6 +145,7 @@ def get_doctype_fields(doctype):

return all_fields


def get_field_obj(field):
obj = {
"label": field.label,
Expand All @@ -107,6 +166,7 @@ def get_field_obj(field):

return obj


def get_type(field):
if field.fieldtype == "Data" and field.options == "Phone":
return "phone"
Expand All @@ -120,4 +180,4 @@ def get_type(field):
return "textarea"
elif field.read_only:
return "read_only"
return field.fieldtype.lower()
return field.fieldtype.lower()
51 changes: 51 additions & 0 deletions crm/fcrm/doctype/crm_deal/crm_deal.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,57 @@ def sort_options():
{ "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',
},
]
rows = [
"name",
"organization",
"annual_revenue",
"status",
"email",
"mobile_no",
"deal_owner",
"modified",
]
return {'columns': columns, 'rows': rows}

@frappe.whitelist()
def add_contact(deal, contact):
if not frappe.has_permission("CRM Deal", "write", deal):
Expand Down
53 changes: 53 additions & 0 deletions crm/fcrm/doctype/crm_lead/crm_lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,59 @@ def sort_options():
{ "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',
},
]
rows = [
"name",
"lead_name",
"organization",
"status",
"email",
"mobile_no",
"lead_owner",
"first_name",
"modified",
"image",
]
return {'columns': columns, 'rows': rows}

@frappe.whitelist()
def convert_to_deal(lead):
if not frappe.has_permission("CRM Lead", "write", lead):
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -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) {

// },
// });
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"actions": [],
"allow_rename": 1,
"autoname": "prompt",
"creation": "2023-11-27 16:29:10.993403",
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"user",
"columns",
"rows"
],
"fields": [
{
"fieldname": "columns",
"fieldtype": "Code",
"label": "Columns"
},
{
"fieldname": "user",
"fieldtype": "Link",
"label": "User",
"options": "User"
},
{
"fieldname": "rows",
"fieldtype": "Code",
"label": "Rows"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-11-28 00:17:42.675332",
"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
}
29 changes: 29 additions & 0 deletions crm/fcrm/doctype/crm_list_view_settings/crm_list_view_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
import json
import frappe
from frappe.model.document import Document


class CRMListViewSettings(Document):
pass


@frappe.whitelist()
def update(doctype, columns, rows):
if not frappe.db.exists("CRM List View Settings", doctype):
# create new CRM List View Settings
doc = frappe.new_doc("CRM List View Settings")
doc.name = doctype
doc.columns = json.dumps(columns)
doc.rows = json.dumps(remove_duplicates(rows))
doc.insert()
else:
# update existing CRM List View Settings
doc = frappe.get_doc("CRM List View Settings", doctype)
doc.columns = json.dumps(columns)
doc.rows = json.dumps(remove_duplicates(rows))
doc.save()

def remove_duplicates(l):
return list(dict.fromkeys(l))
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"tailwindcss": "^3.3.3",
"vite": "^4.4.9",
"vue": "^3.3.4",
"vue-router": "^4.2.2"
"vue-router": "^4.2.2",
"vuedraggable": "^4.1.0"
},
"devDependencies": {
"@vitejs/plugin-vue": "^4.2.3",
Expand Down
15 changes: 15 additions & 0 deletions frontend/src/components/Icons/SettingsIcon.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<template>
<svg
width="18"
height="18"
viewBox="0 0 18 18"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M7.48069 2.93167L7.48066 2.93173C7.22113 3.4979 6.81542 3.9782 6.27003 4.29118C5.72492 4.60401 5.10392 4.71317 4.48225 4.65362L4.47831 4.65324C4.38554 4.6436 4.29136 4.65661 4.20417 4.69129C4.11752 4.72575 4.04086 4.78039 3.98066 4.8501C3.49267 5.42823 3.10928 6.08487 2.84733 6.79073C2.8166 6.876 2.80739 6.96674 2.82005 7.05518C2.83278 7.14407 2.86727 7.22846 2.9207 7.30108L2.92304 7.30425L2.92302 7.30426C3.28725 7.80753 3.50281 8.3954 3.50112 9.02032L3.50112 9.02058C3.49912 9.64243 3.28219 10.2276 2.9195 10.7294L2.87923 10.7905C2.79807 10.9301 2.77389 11.0964 2.8317 11.2526L2.83206 11.2536C3.09058 11.9565 3.46969 12.6094 3.95288 13.1838C4.01152 13.2522 4.08662 13.3057 4.1721 13.3394L3.98882 13.8046L4.1721 13.3394C4.25807 13.3733 4.35179 13.3859 4.44503 13.3758L4.45431 13.3747L4.46362 13.3741L4.64024 13.3615L4.64849 13.3609L4.6485 13.3609C5.20037 13.3306 5.7493 13.4566 6.23089 13.725L6.23468 13.7271L6.23467 13.7272C6.77958 14.0371 7.18389 14.516 7.44043 15.0816L7.44206 15.0852L7.44205 15.0852C7.47849 15.1672 7.53486 15.2395 7.60669 15.2955C7.67817 15.3512 7.76294 15.3892 7.85391 15.4056C8.60087 15.5332 9.36556 15.5315 10.1139 15.4003C10.2057 15.3833 10.2919 15.3444 10.3651 15.2872C10.4386 15.2297 10.4964 15.1557 10.5338 15.0722L10.5356 15.0682L10.5356 15.0683C10.7952 14.502 11.2015 14.0214 11.7462 13.7088C12.2912 13.3961 12.9124 13.288 13.5331 13.3463L13.5381 13.3468L13.5381 13.3468C13.6309 13.3564 13.725 13.3434 13.8121 13.3088L13.9969 13.7734L13.8121 13.3088C13.8988 13.2743 13.9754 13.2197 14.0356 13.15C14.524 12.5713 14.9076 11.9141 15.1696 11.2075L15.1697 11.2071C15.2363 11.028 15.1964 10.8383 15.0932 10.6957C14.7292 10.1927 14.5131 9.60571 14.5152 8.97941L14.5152 8.97906C14.5176 8.35901 14.7334 7.77374 15.0963 7.27232L15.1364 7.21067C15.2181 7.07086 15.2425 6.90403 15.1846 6.7474L15.1842 6.74645C14.9254 6.04291 14.5459 5.38941 14.0621 4.81462L14.062 4.81449C13.939 4.66831 13.7495 4.60609 13.5677 4.62461L13.5602 4.62538L13.5526 4.62591L13.376 4.63854L13.3685 4.63907L13.361 4.63938C12.81 4.66211 12.2647 4.54912 11.7813 4.27262C11.2354 3.96277 10.832 3.4832 10.5758 2.91842L10.5754 2.91743C10.5042 2.75965 10.3588 2.62823 10.1641 2.59472L7.48069 2.93167ZM7.48069 2.93167C7.5554 2.76862 7.70513 2.63444 7.9003 2.60005L7.48069 2.93167ZM7.90047 2.60002C8.64996 2.46846 9.41582 2.46669 10.1639 2.59468L7.90047 2.60002Z"
stroke="currentColor"
/>
<circle cx="9.00781" cy="9" r="2.125" stroke="currentColor" />
</svg>
</template>
2 changes: 1 addition & 1 deletion frontend/src/components/ListViews/DealsListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<PhoneIcon class="h-4 w-4" />
</div>
</template>
<div v-if="column.key === 'modified'" class="truncate text-base">
<div v-if="['modified', 'creation'].includes(column.key)" class="truncate text-base">
{{ item.timeAgo }}
</div>
</ListRowItem>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/ListViews/LeadsListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<PhoneIcon class="h-4 w-4" />
</div>
</template>
<div v-if="column.key === 'modified'" class="truncate text-base">
<div v-if="['modified', 'creation'].includes(column.key)" class="truncate text-base">
{{ item.timeAgo }}
</div>
</ListRowItem>
Expand Down
Loading
Loading