From c670fe190b52a3a5e124daf463d7f2ae0616f172 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Thu, 4 Jan 2024 21:35:52 +0530 Subject: [PATCH] fix: removed organization as a link field in lead & added reqd field validation --- crm/fcrm/doctype/crm_lead/api.py | 2 +- crm/fcrm/doctype/crm_lead/crm_lead.json | 7 ++-- frontend/src/pages/Lead.vue | 43 ++++++++++--------------- 3 files changed, 21 insertions(+), 31 deletions(-) diff --git a/crm/fcrm/doctype/crm_lead/api.py b/crm/fcrm/doctype/crm_lead/api.py index 9758d045..87b64a83 100644 --- a/crm/fcrm/doctype/crm_lead/api.py +++ b/crm/fcrm/doctype/crm_lead/api.py @@ -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 diff --git a/crm/fcrm/doctype/crm_lead/crm_lead.json b/crm/fcrm/doctype/crm_lead/crm_lead.json index ad15f430..3090a4ae 100644 --- a/crm/fcrm/doctype/crm_lead/crm_lead.json +++ b/crm/fcrm/doctype/crm_lead/crm_lead.json @@ -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", diff --git a/frontend/src/pages/Lead.vue b/frontend/src/pages/Lead.vue index 99675a69..0f7f49eb 100644 --- a/frontend/src/pages/Lead.vue +++ b/frontend/src/pages/Lead.vue @@ -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,