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)
|
||||
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["_form_script"] = get_form_script('CRM Lead')
|
||||
return lead
|
||||
|
||||
@ -184,9 +184,8 @@
|
||||
},
|
||||
{
|
||||
"fieldname": "organization",
|
||||
"fieldtype": "Link",
|
||||
"label": "Organization",
|
||||
"options": "CRM Organization"
|
||||
"fieldtype": "Data",
|
||||
"label": "Organization"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
@ -279,7 +278,7 @@
|
||||
"image_field": "image",
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2024-01-04 20:12:22.104289",
|
||||
"modified": "2024-01-04 21:34:32.388456",
|
||||
"modified_by": "Administrator",
|
||||
"module": "FCRM",
|
||||
"name": "CRM Lead",
|
||||
|
||||
@ -262,6 +262,8 @@ const organization = computed(() => {
|
||||
function updateLead(fieldname, value, callback) {
|
||||
value = Array.isArray(fieldname) ? '' : value
|
||||
|
||||
if (validateRequired(fieldname, value)) return
|
||||
|
||||
createResource({
|
||||
url: 'frappe.client.set_value',
|
||||
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(() => {
|
||||
let items = [{ label: 'Leads', route: { name: 'Leads' } }]
|
||||
items.push({
|
||||
@ -335,34 +351,9 @@ function validateFile(file) {
|
||||
const detailSections = computed(() => {
|
||||
let data = lead.data
|
||||
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() {
|
||||
let deal = await call('crm.fcrm.doctype.crm_lead.crm_lead.convert_to_deal', {
|
||||
lead: lead.data.name,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user