fix: get all lead/deal data in one api call
This commit is contained in:
parent
8c797d1532
commit
988d5a66a4
@ -125,7 +125,6 @@ def get_list_data(doctype: str, filters: dict, order_by: str):
|
||||
}
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_doctype_fields(doctype):
|
||||
not_allowed_fieldtypes = [
|
||||
"Section Break",
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import frappe
|
||||
from frappe import _
|
||||
|
||||
from crm.api.doc import get_doctype_fields
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_deal(name):
|
||||
@ -25,4 +26,5 @@ def get_deal(name):
|
||||
fields=["contact", "is_primary"],
|
||||
)
|
||||
|
||||
deal["doctype_fields"] = get_doctype_fields("CRM Deal")
|
||||
return deal
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import frappe
|
||||
from frappe import _
|
||||
|
||||
from crm.api.doc import get_doctype_fields
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_lead(name):
|
||||
@ -13,4 +14,5 @@ def get_lead(name):
|
||||
frappe.throw(_("Lead not found"), frappe.DoesNotExistError)
|
||||
lead = lead.pop()
|
||||
|
||||
lead["doctype_fields"] = get_doctype_fields("CRM Lead")
|
||||
return lead
|
||||
@ -131,13 +131,16 @@
|
||||
v-model="deal.data"
|
||||
@updateField="updateField"
|
||||
/>
|
||||
<div class="flex flex-1 flex-col justify-between overflow-hidden">
|
||||
<div
|
||||
v-if="detailSections.length"
|
||||
class="flex flex-1 flex-col justify-between overflow-hidden"
|
||||
>
|
||||
<div class="flex flex-col overflow-y-auto">
|
||||
<div
|
||||
v-for="(section, i) in detailSections.data"
|
||||
v-for="(section, i) in detailSections"
|
||||
:key="section.label"
|
||||
class="flex flex-col p-3"
|
||||
:class="{ 'border-b': i !== detailSections.data.length - 1 }"
|
||||
:class="{ 'border-b': i !== detailSections.length - 1 }"
|
||||
>
|
||||
<Section :is-opened="section.opened" :label="section.label">
|
||||
<template #actions>
|
||||
@ -427,17 +430,13 @@ const tabs = [
|
||||
},
|
||||
]
|
||||
|
||||
const detailSections = createResource({
|
||||
url: 'crm.api.doc.get_doctype_fields',
|
||||
params: { doctype: 'CRM Deal' },
|
||||
cache: 'dealFields',
|
||||
auto: true,
|
||||
transform: (data) => {
|
||||
return getParsedFields(data)
|
||||
},
|
||||
const detailSections = computed(() => {
|
||||
let data = deal.data
|
||||
if (!data) return []
|
||||
return getParsedFields(data.doctype_fields, data.contacts)
|
||||
})
|
||||
|
||||
function getParsedFields(sections) {
|
||||
function getParsedFields(sections, contacts) {
|
||||
sections.forEach((section) => {
|
||||
section.fields.forEach((field) => {
|
||||
if (['website', 'annual_revenue'].includes(field.name)) {
|
||||
@ -462,15 +461,14 @@ function getParsedFields(sections) {
|
||||
let contactSection = {
|
||||
label: 'Contacts',
|
||||
opened: true,
|
||||
contacts: computed(() =>
|
||||
deal.data?.contacts.map((contact) => {
|
||||
contacts:
|
||||
contacts?.map((contact) => {
|
||||
return {
|
||||
name: contact.contact,
|
||||
is_primary: contact.is_primary,
|
||||
opened: false,
|
||||
}
|
||||
})
|
||||
),
|
||||
}) || [],
|
||||
}
|
||||
|
||||
return [...sections, contactSection]
|
||||
|
||||
@ -171,13 +171,16 @@
|
||||
v-model="lead.data"
|
||||
@updateField="updateField"
|
||||
/>
|
||||
<div class="flex flex-1 flex-col justify-between overflow-hidden">
|
||||
<div
|
||||
v-if="detailSections.length"
|
||||
class="flex flex-1 flex-col justify-between overflow-hidden"
|
||||
>
|
||||
<div class="flex flex-col overflow-y-auto">
|
||||
<div
|
||||
v-for="(section, i) in detailSections.data"
|
||||
v-for="(section, i) in detailSections"
|
||||
:key="section.label"
|
||||
class="flex flex-col p-3"
|
||||
:class="{ 'border-b': i !== detailSections.data.length - 1 }"
|
||||
:class="{ 'border-b': i !== detailSections.length - 1 }"
|
||||
>
|
||||
<Section :is-opened="section.opened" :label="section.label">
|
||||
<SectionFields
|
||||
@ -341,14 +344,10 @@ function validateFile(file) {
|
||||
}
|
||||
}
|
||||
|
||||
const detailSections = createResource({
|
||||
url: 'crm.api.doc.get_doctype_fields',
|
||||
params: { doctype: 'CRM Lead' },
|
||||
cache: 'leadFields',
|
||||
auto: true,
|
||||
transform: (data) => {
|
||||
return getParsedFields(data)
|
||||
},
|
||||
const detailSections = computed(() => {
|
||||
let data = lead.data
|
||||
if (!data) return []
|
||||
return getParsedFields(data.doctype_fields, data.contacts)
|
||||
})
|
||||
|
||||
function getParsedFields(sections) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user