From c4c44a9a2bb71b2e91b3ee56417328d0d27f79e0 Mon Sep 17 00:00:00 2001 From: Anupam K Date: Wed, 15 Apr 2020 12:58:24 +0530 Subject: [PATCH 1/2] Initial JS setup --- .../crm/doctype/opportunity/opportunity_calendar.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 erpnext/crm/doctype/opportunity/opportunity_calendar.js diff --git a/erpnext/crm/doctype/opportunity/opportunity_calendar.js b/erpnext/crm/doctype/opportunity/opportunity_calendar.js new file mode 100644 index 00000000000..983be9bf2da --- /dev/null +++ b/erpnext/crm/doctype/opportunity/opportunity_calendar.js @@ -0,0 +1,12 @@ +// Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors +// License: GNU General Public License v3. See license.txt +frappe.views.calendar["Opportunity"] = { + field_map: { + "start": "contact_date", + "end": "contact_date", + "id": "name", + "title": "customer_name", + "allDay": "allDay" + }, + get_events_method: 'frappe.desk.doctype.event.event.get_events' +} From 9ee81104110b735df1e592c7fd001464f06e9e9d Mon Sep 17 00:00:00 2001 From: Anupam K Date: Wed, 15 Apr 2020 18:37:35 +0530 Subject: [PATCH 2/2] Adding Calendar view for Opportunity --- .../crm/doctype/opportunity/opportunity.py | 24 +++++++++++++++++++ .../opportunity/opportunity_calendar.js | 11 +++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index 5e640e78c8a..1b071ea1b70 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -336,3 +336,27 @@ def make_opportunity_from_communication(communication, ignore_communication_link link_communication_to_document(doc, "Opportunity", opportunity.name, ignore_communication_links) return opportunity.name +@frappe.whitelist() +def get_events(start, end, filters=None): + """Returns events for Gantt / Calendar view rendering. + :param start: Start date-time. + :param end: End date-time. + :param filters: Filters (JSON). + """ + from frappe.desk.calendar import get_event_conditions + conditions = get_event_conditions("Opportunity", filters) + + data = frappe.db.sql(""" + select + distinct `tabOpportunity`.name, `tabOpportunity`.customer_name, `tabOpportunity`.opportunity_amount, + `tabOpportunity`.title, `tabOpportunity`.contact_date + from + `tabOpportunity` + where + (`tabOpportunity`.contact_date between %(start)s and %(end)s) + {conditions} + """.format(conditions=conditions), { + "start": start, + "end": end + }, as_dict=True, update={"allDay": 0}) + return data \ No newline at end of file diff --git a/erpnext/crm/doctype/opportunity/opportunity_calendar.js b/erpnext/crm/doctype/opportunity/opportunity_calendar.js index 983be9bf2da..58fa2b8cd86 100644 --- a/erpnext/crm/doctype/opportunity/opportunity_calendar.js +++ b/erpnext/crm/doctype/opportunity/opportunity_calendar.js @@ -7,6 +7,13 @@ frappe.views.calendar["Opportunity"] = { "id": "name", "title": "customer_name", "allDay": "allDay" - }, - get_events_method: 'frappe.desk.doctype.event.event.get_events' + }, + options: { + header: { + left: 'prev,next today', + center: 'title', + right: 'month' + } + }, + get_events_method: 'erpnext.crm.doctype.opportunity.opportunity.get_events' }