From f72d5506de0b5ffc55922db0c95b52ee28cdc87e Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Sat, 25 Jun 2022 15:08:13 +0530 Subject: [PATCH] fix: get_all replace by sql --- erpnext/patches/v14_0/crm_ux_cleanup.py | 37 +++++++++++++------------ 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/erpnext/patches/v14_0/crm_ux_cleanup.py b/erpnext/patches/v14_0/crm_ux_cleanup.py index c1bc6b265d..b2df36ff35 100644 --- a/erpnext/patches/v14_0/crm_ux_cleanup.py +++ b/erpnext/patches/v14_0/crm_ux_cleanup.py @@ -4,7 +4,7 @@ from frappe.utils import add_months, cstr, today def execute(): - for doctype in ("Lead", "Opportunity", "Prospect", "Prospect Lead"): + for doctype in ("CRM Note", "Lead", "Opportunity", "Prospect", "Prospect Lead"): frappe.reload_doc("crm", "doctype", doctype) try: @@ -28,11 +28,16 @@ def execute(): def add_calendar_event_for_leads(): # create events based on next contact date - leads = frappe.get_all( - "Lead", - {"contact_date": [">=", add_months(today(), -1)]}, - ["name", "contact_date", "contact_by", "ends_on", "lead_name", "lead_owner"], + leads = frappe.db.sql( + """ + select name, contact_date, contact_by, ends_on, lead_name, lead_owner + from tabLead + where contact_date >= %s + """, + add_months(today(), -1), + as_dict=1, ) + for d in leads: event = frappe.get_doc( { @@ -55,19 +60,17 @@ def add_calendar_event_for_leads(): def add_calendar_event_for_opportunities(): # create events based on next contact date - opportunities = frappe.get_all( - "Opportunity", - {"contact_date": [">=", add_months(today(), -1)]}, - [ - "name", - "contact_date", - "contact_by", - "to_discuss", - "party_name", - "opportunity_owner", - "contact_person", - ], + opportunities = frappe.db.sql( + """ + select name, contact_date, contact_by, to_discuss, + party_name, opportunity_owner, contact_person + from tabOpportunity + where contact_date >= %s + """, + add_months(today(), -1), + as_dict=1, ) + for d in opportunities: event = frappe.get_doc( {