feat: load list column from default lead/deal list data from backend
This commit is contained in:
parent
5852acec42
commit
e311637176
@ -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()
|
||||
return field.fieldtype.lower()
|
||||
|
||||
@ -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):
|
||||
|
||||
@ -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):
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
<Button icon="more-horizontal" />
|
||||
</div>
|
||||
</div>
|
||||
<DealsListView :rows="rows" :columns="columns" />
|
||||
<DealsListView v-if="deals.data" :rows="rows" :columns="deals.data.columns" />
|
||||
<Dialog
|
||||
v-model="showNewDialog"
|
||||
:options="{
|
||||
@ -95,26 +95,20 @@ const currentView = ref({
|
||||
icon: 'list',
|
||||
})
|
||||
|
||||
function getFilter() {
|
||||
return getArgs() || {}
|
||||
function getParams() {
|
||||
const filters = getArgs() || {}
|
||||
const order_by = getOrderBy() || 'modified desc'
|
||||
|
||||
return {
|
||||
doctype: 'CRM Deal',
|
||||
filters: filters,
|
||||
order_by: order_by,
|
||||
}
|
||||
}
|
||||
|
||||
const deals = createListResource({
|
||||
type: 'list',
|
||||
doctype: 'CRM Deal',
|
||||
fields: [
|
||||
'name',
|
||||
'organization',
|
||||
'annual_revenue',
|
||||
'status',
|
||||
'email',
|
||||
'mobile_no',
|
||||
'deal_owner',
|
||||
'modified',
|
||||
],
|
||||
filters: getFilter(),
|
||||
orderBy: 'modified desc',
|
||||
pageLength: 20,
|
||||
const deals = createResource({
|
||||
url: 'crm.api.doc.get_list_data',
|
||||
params: getParams(),
|
||||
auto: true,
|
||||
})
|
||||
|
||||
@ -122,7 +116,7 @@ watch(
|
||||
() => getOrderBy(),
|
||||
(value, old_value) => {
|
||||
if (!value && !old_value) return
|
||||
deals.orderBy = getOrderBy() || 'modified desc'
|
||||
deals.params = getParams()
|
||||
deals.reload()
|
||||
},
|
||||
{ immediate: true }
|
||||
@ -132,75 +126,44 @@ watch(
|
||||
storage,
|
||||
useDebounceFn((value, old_value) => {
|
||||
if (JSON.stringify([...value]) === JSON.stringify([...old_value])) return
|
||||
deals.filters = getFilter()
|
||||
deals.params = getParams()
|
||||
deals.reload()
|
||||
}, 300),
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
const 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',
|
||||
},
|
||||
]
|
||||
|
||||
const rows = computed(() => {
|
||||
if (!deals.data) return []
|
||||
return deals.data.map((deal) => {
|
||||
return {
|
||||
name: deal.name,
|
||||
organization: {
|
||||
label: deal.organization,
|
||||
logo: getOrganization(deal.organization)?.organization_logo,
|
||||
},
|
||||
annual_revenue: formatNumberIntoCurrency(deal.annual_revenue),
|
||||
status: {
|
||||
label: deal.status,
|
||||
color: dealStatuses[deal.status]?.color,
|
||||
},
|
||||
email: deal.email,
|
||||
mobile_no: deal.mobile_no,
|
||||
deal_owner: {
|
||||
label: deal.deal_owner && getUser(deal.deal_owner).full_name,
|
||||
...(deal.deal_owner && getUser(deal.deal_owner)),
|
||||
},
|
||||
modified: {
|
||||
label: dateFormat(deal.modified, dateTooltipFormat),
|
||||
timeAgo: timeAgo(deal.modified),
|
||||
},
|
||||
}
|
||||
if (!deals.data?.data) return []
|
||||
return deals.data.data.map((deal) => {
|
||||
let _rows = {}
|
||||
deals.data.rows.forEach((row) => {
|
||||
_rows[row] = deal[row]
|
||||
|
||||
if (row == 'organization') {
|
||||
_rows[row] = {
|
||||
label: deal.organization,
|
||||
logo: getOrganization(deal.organization)?.organization_logo,
|
||||
}
|
||||
} else if (row == 'annual_revenue') {
|
||||
_rows[row] = formatNumberIntoCurrency(deal.annual_revenue)
|
||||
} else if (row == 'status') {
|
||||
_rows[row] = {
|
||||
label: deal.status,
|
||||
color: dealStatuses[deal.status]?.color,
|
||||
}
|
||||
} else if (row == 'deal_owner') {
|
||||
_rows[row] = {
|
||||
label: deal.deal_owner && getUser(deal.deal_owner).full_name,
|
||||
...(deal.deal_owner && getUser(deal.deal_owner)),
|
||||
}
|
||||
} else if (row == 'modified') {
|
||||
_rows[row] = {
|
||||
label: dateFormat(deal.modified, dateTooltipFormat),
|
||||
timeAgo: timeAgo(deal.modified),
|
||||
}
|
||||
}
|
||||
})
|
||||
return _rows
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@ -32,7 +32,11 @@
|
||||
<Button icon="more-horizontal" />
|
||||
</div>
|
||||
</div>
|
||||
<LeadsListView :rows="rows" :columns="columns" />
|
||||
<LeadsListView
|
||||
v-if="leads.data"
|
||||
:rows="rows"
|
||||
:columns="leads.data.columns"
|
||||
/>
|
||||
<Dialog
|
||||
v-model="showNewDialog"
|
||||
:options="{
|
||||
@ -88,35 +92,24 @@ const currentView = ref({
|
||||
icon: 'list',
|
||||
})
|
||||
|
||||
function getFilter() {
|
||||
return {
|
||||
...(getArgs() || {}),
|
||||
function getParams() {
|
||||
const filters = {
|
||||
converted: 0,
|
||||
...(getArgs() || {}),
|
||||
}
|
||||
|
||||
const order_by = getOrderBy() || 'modified desc'
|
||||
|
||||
return {
|
||||
doctype: 'CRM Lead',
|
||||
filters: filters,
|
||||
order_by: order_by,
|
||||
}
|
||||
}
|
||||
|
||||
function getSortBy() {
|
||||
return getOrderBy() || 'modified desc'
|
||||
}
|
||||
|
||||
const leads = createListResource({
|
||||
type: 'list',
|
||||
doctype: 'CRM Lead',
|
||||
fields: [
|
||||
'name',
|
||||
'first_name',
|
||||
'lead_name',
|
||||
'image',
|
||||
'organization',
|
||||
'status',
|
||||
'email',
|
||||
'mobile_no',
|
||||
'lead_owner',
|
||||
'modified',
|
||||
],
|
||||
filters: getFilter(),
|
||||
orderBy: getSortBy(),
|
||||
pageLength: 20,
|
||||
const leads = createResource({
|
||||
url: 'crm.api.doc.get_list_data',
|
||||
params: getParams(),
|
||||
auto: true,
|
||||
})
|
||||
|
||||
@ -124,7 +117,7 @@ watch(
|
||||
() => getOrderBy(),
|
||||
(value, old_value) => {
|
||||
if (!value && !old_value) return
|
||||
leads.orderBy = getSortBy()
|
||||
leads.params = getParams()
|
||||
leads.reload()
|
||||
},
|
||||
{ immediate: true }
|
||||
@ -134,79 +127,49 @@ watch(
|
||||
storage,
|
||||
useDebounceFn((value, old_value) => {
|
||||
if (JSON.stringify([...value]) === JSON.stringify([...old_value])) return
|
||||
leads.filters = getFilter()
|
||||
leads.params = getParams()
|
||||
leads.reload()
|
||||
}, 300),
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
const 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',
|
||||
},
|
||||
]
|
||||
|
||||
const rows = computed(() => {
|
||||
if (!leads.data) return []
|
||||
return leads.data.map((lead) => {
|
||||
return {
|
||||
name: lead.name,
|
||||
lead_name: {
|
||||
label: lead.lead_name,
|
||||
image: lead.image,
|
||||
image_label: lead.first_name,
|
||||
},
|
||||
organization: {
|
||||
label: lead.organization,
|
||||
logo: getOrganization(lead.organization)?.organization_logo,
|
||||
},
|
||||
status: {
|
||||
label: lead.status,
|
||||
color: leadStatuses[lead.status]?.color,
|
||||
},
|
||||
email: lead.email,
|
||||
mobile_no: lead.mobile_no,
|
||||
lead_owner: {
|
||||
label: lead.lead_owner && getUser(lead.lead_owner).full_name,
|
||||
...(lead.lead_owner && getUser(lead.lead_owner)),
|
||||
},
|
||||
modified: {
|
||||
label: dateFormat(lead.modified, dateTooltipFormat),
|
||||
timeAgo: timeAgo(lead.modified),
|
||||
},
|
||||
}
|
||||
if (!leads.data?.data) return []
|
||||
return leads.data.data.map((lead) => {
|
||||
let _rows = {}
|
||||
|
||||
leads.data.rows.forEach((row) => {
|
||||
_rows[row] = lead[row]
|
||||
|
||||
if (row == 'lead_name') {
|
||||
_rows[row] = {
|
||||
label: lead.lead_name,
|
||||
image: lead.image,
|
||||
image_label: lead.first_name,
|
||||
}
|
||||
} else if (row == 'organization') {
|
||||
_rows[row] = {
|
||||
label: lead.organization,
|
||||
logo: getOrganization(lead.organization)?.organization_logo,
|
||||
}
|
||||
} else if (row == 'status') {
|
||||
_rows[row] = {
|
||||
label: lead.status,
|
||||
color: leadStatuses[lead.status]?.color,
|
||||
}
|
||||
} else if (row == 'lead_owner') {
|
||||
_rows[row] = {
|
||||
label: lead.lead_owner && getUser(lead.lead_owner).full_name,
|
||||
...(lead.lead_owner && getUser(lead.lead_owner)),
|
||||
}
|
||||
} else if (row == 'modified') {
|
||||
_rows[row] = {
|
||||
label: dateFormat(lead.modified, dateTooltipFormat),
|
||||
timeAgo: timeAgo(lead.modified),
|
||||
}
|
||||
}
|
||||
})
|
||||
return _rows
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user