From b3acff8cba6fd30e15ce2d579287cbd02d9c8282 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Fri, 13 Jun 2025 14:42:09 +0530 Subject: [PATCH] fix: create standard forecasting script on install and added in patch --- .../doctype/fcrm_settings/fcrm_settings.py | 37 +++++++++++++++++++ crm/install.py | 2 + crm/patches.txt | 2 +- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/crm/fcrm/doctype/fcrm_settings/fcrm_settings.py b/crm/fcrm/doctype/fcrm_settings/fcrm_settings.py index 48da4c99..0cdbc2df 100644 --- a/crm/fcrm/doctype/fcrm_settings/fcrm_settings.py +++ b/crm/fcrm/doctype/fcrm_settings/fcrm_settings.py @@ -76,3 +76,40 @@ def sync_table(key, hook): crm_settings.set(key, items) crm_settings.save() + + +def create_forecasting_script(): + if not frappe.db.exists("CRM Form Script", "Forecasting Script"): + script = get_forecasting_script() + frappe.get_doc( + { + "doctype": "CRM Form Script", + "name": "Forecasting Script", + "dt": "CRM Deal", + "view": "Form", + "script": script, + "enabled": 1, + "is_standard": 1, + } + ).insert() + + +def get_forecasting_script(): + return ( +""" +class CRMDeal { + async status() { + await this.doc.trigger('updateProbability') + } + async updateProbability() { + let status = await call("frappe.client.get_value", { + doctype: "CRM Deal Status", + fieldname: "probability", + filters: { name: this.doc.status }, + }) + + this.doc.probability = status.probability + } +} +""" +) diff --git a/crm/install.py b/crm/install.py index 5f25e7d0..51166471 100644 --- a/crm/install.py +++ b/crm/install.py @@ -5,6 +5,7 @@ import frappe from frappe.custom.doctype.custom_field.custom_field import create_custom_fields from crm.fcrm.doctype.crm_products.crm_products import create_product_details_script +from crm.fcrm.doctype.fcrm_settings.fcrm_settings import create_forecasting_script def before_install(): @@ -361,3 +362,4 @@ def add_standard_dropdown_items(): def add_default_scripts(): for doctype in ["CRM Lead", "CRM Deal"]: create_product_details_script(doctype) + create_forecasting_script() diff --git a/crm/patches.txt b/crm/patches.txt index 59f37bfb..ee56be84 100644 --- a/crm/patches.txt +++ b/crm/patches.txt @@ -12,4 +12,4 @@ crm.patches.v1_0.create_default_sidebar_fields_layout crm.patches.v1_0.update_deal_quick_entry_layout crm.patches.v1_0.update_layouts_to_new_format crm.patches.v1_0.move_twilio_agent_to_telephony_agent -crm.patches.v1_0.create_default_scripts \ No newline at end of file +crm.patches.v1_0.create_default_scripts # 13-06-2025 \ No newline at end of file