diff --git a/crm/patches.txt b/crm/patches.txt index 484c73dc..910f0fe1 100644 --- a/crm/patches.txt +++ b/crm/patches.txt @@ -13,4 +13,5 @@ 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 # 13-06-2025 -crm.patches.v1_0.update_deal_status_probabilities \ No newline at end of file +crm.patches.v1_0.update_deal_status_probabilities +crm.patches.v1_0.update_deal_status_type \ No newline at end of file diff --git a/crm/patches/v1_0/update_deal_status_type.py b/crm/patches/v1_0/update_deal_status_type.py new file mode 100644 index 00000000..230f3776 --- /dev/null +++ b/crm/patches/v1_0/update_deal_status_type.py @@ -0,0 +1,44 @@ +import frappe + + +def execute(): + deal_statuses = frappe.get_all("CRM Deal Status", fields=["name", "type", "deal_status"]) + + openStatuses = ["New", "Open", "Unassigned", "Qualification"] + ongoingStatuses = [ + "Demo/Making", + "Proposal/Quotation", + "Negotiation", + "Ready to Close", + "Demo Scheduled", + "Follow Up", + ] + onHoldStatuses = ["On Hold", "Paused", "Stalled", "Awaiting Reply"] + wonStatuses = ["Won", "Closed Won", "Successful", "Completed"] + lostStatuses = [ + "Lost", + "Closed", + "Closed Lost", + "Junk", + "Unqualified", + "Disqualified", + "Cancelled", + "No Response", + ] + + for status in deal_statuses: + if status.type is None or status.type == "": + if status.deal_status in openStatuses: + type = "Open" + elif status.deal_status in ongoingStatuses: + type = "Ongoing" + elif status.deal_status in onHoldStatuses: + type = "On Hold" + elif status.deal_status in wonStatuses: + type = "Won" + elif status.deal_status in lostStatuses: + type = "Lost" + else: + type = "Ongoing" + + frappe.db.set_value("CRM Deal Status", status.name, "type", type)