fix: get all lead/deal data in one api call

This commit is contained in:
Shariq Ansari 2023-12-15 12:29:02 +05:30
parent 8c797d1532
commit 988d5a66a4
5 changed files with 28 additions and 28 deletions

View File

@ -125,7 +125,6 @@ def get_list_data(doctype: str, filters: dict, order_by: str):
} }
@frappe.whitelist()
def get_doctype_fields(doctype): def get_doctype_fields(doctype):
not_allowed_fieldtypes = [ not_allowed_fieldtypes = [
"Section Break", "Section Break",

View File

@ -1,6 +1,7 @@
import frappe import frappe
from frappe import _ from frappe import _
from crm.api.doc import get_doctype_fields
@frappe.whitelist() @frappe.whitelist()
def get_deal(name): def get_deal(name):
@ -25,4 +26,5 @@ def get_deal(name):
fields=["contact", "is_primary"], fields=["contact", "is_primary"],
) )
deal["doctype_fields"] = get_doctype_fields("CRM Deal")
return deal return deal

View File

@ -1,6 +1,7 @@
import frappe import frappe
from frappe import _ from frappe import _
from crm.api.doc import get_doctype_fields
@frappe.whitelist() @frappe.whitelist()
def get_lead(name): def get_lead(name):
@ -13,4 +14,5 @@ def get_lead(name):
frappe.throw(_("Lead not found"), frappe.DoesNotExistError) frappe.throw(_("Lead not found"), frappe.DoesNotExistError)
lead = lead.pop() lead = lead.pop()
lead["doctype_fields"] = get_doctype_fields("CRM Lead")
return lead return lead

View File

@ -131,13 +131,16 @@
v-model="deal.data" v-model="deal.data"
@updateField="updateField" @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 class="flex flex-col overflow-y-auto">
<div <div
v-for="(section, i) in detailSections.data" v-for="(section, i) in detailSections"
:key="section.label" :key="section.label"
class="flex flex-col p-3" 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"> <Section :is-opened="section.opened" :label="section.label">
<template #actions> <template #actions>
@ -427,17 +430,13 @@ const tabs = [
}, },
] ]
const detailSections = createResource({ const detailSections = computed(() => {
url: 'crm.api.doc.get_doctype_fields', let data = deal.data
params: { doctype: 'CRM Deal' }, if (!data) return []
cache: 'dealFields', return getParsedFields(data.doctype_fields, data.contacts)
auto: true,
transform: (data) => {
return getParsedFields(data)
},
}) })
function getParsedFields(sections) { function getParsedFields(sections, contacts) {
sections.forEach((section) => { sections.forEach((section) => {
section.fields.forEach((field) => { section.fields.forEach((field) => {
if (['website', 'annual_revenue'].includes(field.name)) { if (['website', 'annual_revenue'].includes(field.name)) {
@ -462,15 +461,14 @@ function getParsedFields(sections) {
let contactSection = { let contactSection = {
label: 'Contacts', label: 'Contacts',
opened: true, opened: true,
contacts: computed(() => contacts:
deal.data?.contacts.map((contact) => { contacts?.map((contact) => {
return { return {
name: contact.contact, name: contact.contact,
is_primary: contact.is_primary, is_primary: contact.is_primary,
opened: false, opened: false,
} }
}) }) || [],
),
} }
return [...sections, contactSection] return [...sections, contactSection]

View File

@ -171,13 +171,16 @@
v-model="lead.data" v-model="lead.data"
@updateField="updateField" @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 class="flex flex-col overflow-y-auto">
<div <div
v-for="(section, i) in detailSections.data" v-for="(section, i) in detailSections"
:key="section.label" :key="section.label"
class="flex flex-col p-3" 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"> <Section :is-opened="section.opened" :label="section.label">
<SectionFields <SectionFields
@ -341,14 +344,10 @@ function validateFile(file) {
} }
} }
const detailSections = createResource({ const detailSections = computed(() => {
url: 'crm.api.doc.get_doctype_fields', let data = lead.data
params: { doctype: 'CRM Lead' }, if (!data) return []
cache: 'leadFields', return getParsedFields(data.doctype_fields, data.contacts)
auto: true,
transform: (data) => {
return getParsedFields(data)
},
}) })
function getParsedFields(sections) { function getParsedFields(sections) {