fix: open lead and opportunities based on today's event
diff --git a/erpnext/crm/utils.py b/erpnext/crm/utils.py
index 33441b1..a2528c3 100644
--- a/erpnext/crm/utils.py
+++ b/erpnext/crm/utils.py
@@ -1,6 +1,7 @@
import frappe
from frappe.model.document import Document
-from frappe.utils import cstr, now
+from frappe.utils import cstr, now, today
+from pypika import functions
def update_lead_phone_numbers(contact, method):
@@ -177,6 +178,27 @@
return data
+def open_leads_opportunities_based_on_todays_event():
+ event = frappe.qb.DocType("Event")
+ event_link = frappe.qb.DocType("Event Participants")
+
+ query = (
+ frappe.qb.from_(event)
+ .join(event_link)
+ .on(event_link.parent == event.name)
+ .select(event_link.reference_doctype, event_link.reference_docname)
+ .where(
+ (event_link.reference_doctype.isin(["Lead", "Opportunity"]))
+ & (event.status == "Open")
+ & (functions.Date(event.starts_on) == today())
+ )
+ )
+ data = query.run(as_dict=True)
+
+ for d in data:
+ frappe.db.set_value(d.reference_doctype, d.reference_docname, "status", "Open")
+
+
class CRMNote(Document):
@frappe.whitelist()
def add_note(self, note):
diff --git a/erpnext/hooks.py b/erpnext/hooks.py
index b3c35cf..8abf65f 100644
--- a/erpnext/hooks.py
+++ b/erpnext/hooks.py
@@ -457,6 +457,7 @@
"erpnext.hr.utils.allocate_earned_leaves",
"erpnext.loan_management.doctype.process_loan_security_shortfall.process_loan_security_shortfall.create_process_loan_security_shortfall",
"erpnext.loan_management.doctype.process_loan_interest_accrual.process_loan_interest_accrual.process_loan_interest_accrual_for_term_loans",
+ "erpnext.crm.utils.open_leads_opportunities_based_on_todays_event",
],
"weekly": ["erpnext.hr.doctype.employee.employee_reminders.send_reminders_in_advance_weekly"],
"monthly": ["erpnext.hr.doctype.employee.employee_reminders.send_reminders_in_advance_monthly"],