From 37351489911726655708bd59791ba56443c325d3 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Wed, 29 Nov 2023 13:32:28 +0530 Subject: [PATCH] fix: add default lead/deal status on app install --- crm/hooks.py | 4 +-- crm/install.py | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 crm/install.py diff --git a/crm/hooks.py b/crm/hooks.py index abfc9d0e..c8e6be06 100644 --- a/crm/hooks.py +++ b/crm/hooks.py @@ -70,8 +70,8 @@ website_route_rules = [ # Installation # ------------ -# before_install = "crm.install.before_install" -# after_install = "crm.install.after_install" +before_install = "crm.install.before_install" +after_install = "crm.install.after_install" # Uninstallation # ------------ diff --git a/crm/install.py b/crm/install.py new file mode 100644 index 00000000..77979f73 --- /dev/null +++ b/crm/install.py @@ -0,0 +1,93 @@ +# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors +# MIT License. See license.txt + +from __future__ import unicode_literals +import frappe + +def before_install(): + pass + +def after_install(): + add_default_lead_statuses() + add_default_deal_statuses() + frappe.db.commit() + +def add_default_lead_statuses(): + statuses = { + "Open": { + "color": "gray", + "position": 1, + }, + "Contacted": { + "color": "orange", + "position": 2, + }, + "Nurture": { + "color": "blue", + "position": 3, + }, + "Qualified": { + "color": "green", + "position": 4, + }, + "Unqualified": { + "color": "red", + "position": 5, + }, + "Junk": { + "color": "purple", + "position": 6, + }, + } + + for status in statuses: + if frappe.db.exists("CRM Lead Status", status): + continue + + doc = frappe.new_doc("CRM Lead Status") + doc.lead_status = status + doc.color = statuses[status]["color"] + doc.position = statuses[status]["position"] + doc.insert() + +def add_default_deal_statuses(): + statuses = { + "Qualification": { + "color": "gray", + "position": 1, + }, + "Demo/Making": { + "color": "orange", + "position": 2, + }, + "Proposal/Quotation": { + "color": "blue", + "position": 3, + }, + "Negotiation": { + "color": "yellow", + "position": 4, + }, + "Ready to Close": { + "color": "purple", + "position": 5, + }, + "Won": { + "color": "green", + "position": 6, + }, + "Lost": { + "color": "red", + "position": 7, + }, + } + + for status in statuses: + if frappe.db.exists("CRM Deal Status", status): + continue + + doc = frappe.new_doc("CRM Deal Status") + doc.deal_status = status + doc.color = statuses[status]["color"] + doc.position = statuses[status]["position"] + doc.insert() \ No newline at end of file