From 8a62ff38af4d1421d963e3797adc4f63649e59e2 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Mon, 18 Aug 2025 17:51:14 +0530 Subject: [PATCH] feat: implement validation and script creation for Helpdesk CRM settings --- .../erpnext_crm_settings.py | 11 ++--- .../helpdesk_crm_settings.py | 49 ++++++++++++++++++- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/crm/fcrm/doctype/erpnext_crm_settings/erpnext_crm_settings.py b/crm/fcrm/doctype/erpnext_crm_settings/erpnext_crm_settings.py index 84351670..fde6fb72 100644 --- a/crm/fcrm/doctype/erpnext_crm_settings/erpnext_crm_settings.py +++ b/crm/fcrm/doctype/erpnext_crm_settings/erpnext_crm_settings.py @@ -135,7 +135,7 @@ def get_quotation_url(crm_deal, organization): "party_name": crm_deal, "company": erpnext_crm_settings.erpnext_company, "contact_person": contact, - "customer_address": address + "customer_address": address, } else: site_url = erpnext_crm_settings.get("erpnext_site_url") @@ -147,14 +147,11 @@ def get_quotation_url(crm_deal, organization): "party_name": prospect, "company": erpnext_crm_settings.erpnext_company, "contact_person": contact, - "customer_address": address + "customer_address": address, } - + # Filter out None values and build query string - query_string = "&".join( - f"{key}={value}" for key, value in params.items() - if value is not None - ) + query_string = "&".join(f"{key}={value}" for key, value in params.items() if value is not None) return f"{base_url}?{query_string}" diff --git a/crm/fcrm/doctype/helpdesk_crm_settings/helpdesk_crm_settings.py b/crm/fcrm/doctype/helpdesk_crm_settings/helpdesk_crm_settings.py index 2edba045..71590bf3 100644 --- a/crm/fcrm/doctype/helpdesk_crm_settings/helpdesk_crm_settings.py +++ b/crm/fcrm/doctype/helpdesk_crm_settings/helpdesk_crm_settings.py @@ -1,9 +1,54 @@ # Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and contributors # For license information, please see license.txt -# import frappe +import frappe +from frappe import _ from frappe.model.document import Document class HelpdeskCRMSettings(Document): - pass + def validate(self): + if self.enabled: + self.validate_if_helpdesk_installed() + self.create_helpdesk_script() + + def validate_if_helpdesk_installed(self): + if not self.is_helpdesk_in_different_site: + if "helpdesk" not in frappe.get_installed_apps(): + frappe.throw(_("Helpdesk is not installed in the current site")) + + def create_helpdesk_script(self): + if not frappe.db.exists("CRM Form Script", "Helpdesk Integration Script"): + script = get_helpdesk_script() + frappe.get_doc( + { + "doctype": "CRM Form Script", + "name": "Helpdesk Integration Script", + "dt": "CRM Deal", + "view": "Form", + "script": script, + "enabled": 1, + "is_standard": 1, + } + ).insert() + + +def get_helpdesk_script(): + return """class CRMDeal { + onLoad() { + this.actions.push( + { + group: "Helpdesk", + hideLabel: true, + items: [ + { + label: "Create customer in Helpdesk", + onClick: () => { + toast.success("Success Message") + } + } + ] + } + ) + } +}"""