fix: removed organization as a link field in lead & added reqd field validation
This commit is contained in:
parent
ed5a4b53ba
commit
c670fe190b
@ -15,7 +15,7 @@ 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")
|
lead["doctype_fields"], lead["all_fields"] = get_doctype_fields("CRM Lead")
|
||||||
lead["doctype"] = "CRM Lead"
|
lead["doctype"] = "CRM Lead"
|
||||||
lead["_form_script"] = get_form_script('CRM Lead')
|
lead["_form_script"] = get_form_script('CRM Lead')
|
||||||
return lead
|
return lead
|
||||||
|
|||||||
@ -184,9 +184,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "organization",
|
"fieldname": "organization",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Data",
|
||||||
"label": "Organization",
|
"label": "Organization"
|
||||||
"options": "CRM Organization"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"default": "0",
|
"default": "0",
|
||||||
@ -279,7 +278,7 @@
|
|||||||
"image_field": "image",
|
"image_field": "image",
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2024-01-04 20:12:22.104289",
|
"modified": "2024-01-04 21:34:32.388456",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "FCRM",
|
"module": "FCRM",
|
||||||
"name": "CRM Lead",
|
"name": "CRM Lead",
|
||||||
|
|||||||
@ -262,6 +262,8 @@ const organization = computed(() => {
|
|||||||
function updateLead(fieldname, value, callback) {
|
function updateLead(fieldname, value, callback) {
|
||||||
value = Array.isArray(fieldname) ? '' : value
|
value = Array.isArray(fieldname) ? '' : value
|
||||||
|
|
||||||
|
if (validateRequired(fieldname, value)) return
|
||||||
|
|
||||||
createResource({
|
createResource({
|
||||||
url: 'frappe.client.set_value',
|
url: 'frappe.client.set_value',
|
||||||
params: {
|
params: {
|
||||||
@ -292,6 +294,20 @@ function updateLead(fieldname, value, callback) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function validateRequired(fieldname, value) {
|
||||||
|
let meta = lead.data.all_fields || {}
|
||||||
|
if (meta[fieldname]?.reqd && !value) {
|
||||||
|
createToast({
|
||||||
|
title: 'Error Updating Lead',
|
||||||
|
text: `${meta[fieldname].label} is a required field`,
|
||||||
|
icon: 'x',
|
||||||
|
iconClasses: 'text-red-600',
|
||||||
|
})
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
const breadcrumbs = computed(() => {
|
const breadcrumbs = computed(() => {
|
||||||
let items = [{ label: 'Leads', route: { name: 'Leads' } }]
|
let items = [{ label: 'Leads', route: { name: 'Leads' } }]
|
||||||
items.push({
|
items.push({
|
||||||
@ -335,34 +351,9 @@ function validateFile(file) {
|
|||||||
const detailSections = computed(() => {
|
const detailSections = computed(() => {
|
||||||
let data = lead.data
|
let data = lead.data
|
||||||
if (!data) return []
|
if (!data) return []
|
||||||
return getParsedFields(data.doctype_fields, data.contacts)
|
return data.doctype_fields
|
||||||
})
|
})
|
||||||
|
|
||||||
function getParsedFields(sections) {
|
|
||||||
sections.forEach((section) => {
|
|
||||||
section.fields.forEach((field) => {
|
|
||||||
if (['website', 'industry'].includes(field.name)) {
|
|
||||||
field.value = organization.value?.[field.name]
|
|
||||||
field.tooltip =
|
|
||||||
'This field is read-only and is fetched from the organization'
|
|
||||||
} else if (field.name == 'organization') {
|
|
||||||
field.create = (value, close) => {
|
|
||||||
_organization.value.organization_name = value
|
|
||||||
showOrganizationModal.value = true
|
|
||||||
close()
|
|
||||||
}
|
|
||||||
field.link = (org) =>
|
|
||||||
router.push({
|
|
||||||
name: 'Organization',
|
|
||||||
params: { organizationId: org },
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
return sections
|
|
||||||
}
|
|
||||||
|
|
||||||
async function convertToDeal() {
|
async function convertToDeal() {
|
||||||
let deal = await call('crm.fcrm.doctype.crm_lead.crm_lead.convert_to_deal', {
|
let deal = await call('crm.fcrm.doctype.crm_lead.crm_lead.convert_to_deal', {
|
||||||
lead: lead.data.name,
|
lead: lead.data.name,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user