From 4cf914d902d2db2a2743fa198c841f70723f0e43 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 22 Jun 2016 11:21:56 +0530 Subject: [PATCH] [minor] added mins to first response for opportunity --- erpnext/config/crm.py | 6 +++ erpnext/crm/report/__init__.py | 0 .../__init__.py | 0 ...nutes_to_first_response_for_opportunity.js | 43 ++++++++++++++++++ ...tes_to_first_response_for_opportunity.json | 18 ++++++++ ...nutes_to_first_response_for_opportunity.py | 28 ++++++++++++ .../minutes_to_first_response_for_issues.js | 44 +++++++++---------- .../minutes_to_first_response_for_issues.py | 4 +- 8 files changed, 120 insertions(+), 23 deletions(-) create mode 100644 erpnext/crm/report/__init__.py create mode 100644 erpnext/crm/report/minutes_to_first_response_for_opportunity/__init__.py create mode 100644 erpnext/crm/report/minutes_to_first_response_for_opportunity/minutes_to_first_response_for_opportunity.js create mode 100644 erpnext/crm/report/minutes_to_first_response_for_opportunity/minutes_to_first_response_for_opportunity.json create mode 100644 erpnext/crm/report/minutes_to_first_response_for_opportunity/minutes_to_first_response_for_opportunity.py diff --git a/erpnext/config/crm.py b/erpnext/config/crm.py index 26e9e03832..dfefb75ed9 100644 --- a/erpnext/config/crm.py +++ b/erpnext/config/crm.py @@ -38,6 +38,12 @@ def get_data(): "label": _("Sales Funnel"), "icon": "icon-bar-chart", }, + { + "type": "report", + "name": "Minutes to First Response for Opportunity", + "doctype": "Opportunity", + "is_query_report": True + }, { "type": "report", "is_query_report": True, diff --git a/erpnext/crm/report/__init__.py b/erpnext/crm/report/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/crm/report/minutes_to_first_response_for_opportunity/__init__.py b/erpnext/crm/report/minutes_to_first_response_for_opportunity/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/crm/report/minutes_to_first_response_for_opportunity/minutes_to_first_response_for_opportunity.js b/erpnext/crm/report/minutes_to_first_response_for_opportunity/minutes_to_first_response_for_opportunity.js new file mode 100644 index 0000000000..b1e4917129 --- /dev/null +++ b/erpnext/crm/report/minutes_to_first_response_for_opportunity/minutes_to_first_response_for_opportunity.js @@ -0,0 +1,43 @@ +// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +frappe.query_reports["Minutes to First Response for Opportunity"] = { + "filters": [ + { + "fieldname":"from_date", + "label": __("From Date"), + "fieldtype": "Date", + 'reqd': 1, + "default": frappe.datetime.add_days(frappe.datetime.nowdate(), -30) + }, + { + "fieldname":"to_date", + "label": __("To Date"), + "fieldtype": "Date", + 'reqd': 1, + "default":frappe.datetime.nowdate() + }, + ], + get_chart_data: function(columns, result) { + return { + data: { + x: 'Date', + columns: [ + ['Date'].concat($.map(result, function(d) { return d[0]; })), + ['Mins to first response'].concat($.map(result, function(d) { return d[1]; })) + ] + // rows: [['Date', 'Mins to first response']].concat(result) + }, + axis: { + x: { + type: 'timeseries', + tick: { + format: frappe.ui.py_date_format + } + } + }, + chart_type: 'line', + + } + } +} diff --git a/erpnext/crm/report/minutes_to_first_response_for_opportunity/minutes_to_first_response_for_opportunity.json b/erpnext/crm/report/minutes_to_first_response_for_opportunity/minutes_to_first_response_for_opportunity.json new file mode 100644 index 0000000000..a366b3e5dd --- /dev/null +++ b/erpnext/crm/report/minutes_to_first_response_for_opportunity/minutes_to_first_response_for_opportunity.json @@ -0,0 +1,18 @@ +{ + "add_total_row": 0, + "apply_user_permissions": 0, + "creation": "2016-06-17 11:28:25.867258", + "disabled": 0, + "docstatus": 0, + "doctype": "Report", + "idx": 0, + "is_standard": "Yes", + "modified": "2016-06-17 11:28:25.867258", + "modified_by": "Administrator", + "module": "CRM", + "name": "Minutes to First Response for Opportunity", + "owner": "Administrator", + "ref_doctype": "Opportunity", + "report_name": "Minutes to First Response for Opportunity", + "report_type": "Script Report" +} \ No newline at end of file diff --git a/erpnext/crm/report/minutes_to_first_response_for_opportunity/minutes_to_first_response_for_opportunity.py b/erpnext/crm/report/minutes_to_first_response_for_opportunity/minutes_to_first_response_for_opportunity.py new file mode 100644 index 0000000000..54e3a60308 --- /dev/null +++ b/erpnext/crm/report/minutes_to_first_response_for_opportunity/minutes_to_first_response_for_opportunity.py @@ -0,0 +1,28 @@ +# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import frappe + +def execute(filters=None): + columns = [ + { + 'fieldname': 'creation_date', + 'label': 'Date', + 'fieldtype': 'Date' + }, + { + 'fieldname': 'mins', + 'fieldtype': 'Float', + 'label': 'Mins to First Response' + }, + ] + + data = frappe.db.sql('''select date(creation) as creation_date, + avg(mins_to_first_response) as mins + from tabOpportunity + where date(creation) between %s and %s + and mins_to_first_response > 0 + group by creation_date order by creation_date desc''', (filters.from_date, filters.to_date)) + + return columns, data diff --git a/erpnext/support/report/minutes_to_first_response_for_issues/minutes_to_first_response_for_issues.js b/erpnext/support/report/minutes_to_first_response_for_issues/minutes_to_first_response_for_issues.js index 9fd35d9b5f..e84b13ced5 100644 --- a/erpnext/support/report/minutes_to_first_response_for_issues/minutes_to_first_response_for_issues.js +++ b/erpnext/support/report/minutes_to_first_response_for_issues/minutes_to_first_response_for_issues.js @@ -1,20 +1,20 @@ frappe.query_reports["Minutes to First Response for Issues"] = { - "filters": [ - { - "fieldname":"from_date", - "label": __("From Date"), - "fieldtype": "Date", + "filters": [ + { + "fieldname":"from_date", + "label": __("From Date"), + "fieldtype": "Date", 'reqd': 1, - "default": frappe.datetime.add_days(frappe.datetime.nowdate(), -30) - }, - { - "fieldname":"to_date", - "label": __("To Date"), - "fieldtype": "Date", + "default": frappe.datetime.add_days(frappe.datetime.nowdate(), -30) + }, + { + "fieldname":"to_date", + "label": __("To Date"), + "fieldtype": "Date", 'reqd': 1, - "default":frappe.datetime.nowdate() - }, - ], + "default":frappe.datetime.nowdate() + }, + ], get_chart_data: function(columns, result) { return { data: { @@ -25,14 +25,14 @@ frappe.query_reports["Minutes to First Response for Issues"] = { ] // rows: [['Date', 'Mins to first response']].concat(result) }, - axis: { - x: { - type: 'timeseries', - tick: { - format: '%Y-%m-%d' - } - } - }, + axis: { + x: { + type: 'timeseries', + tick: { + format: frappe.ui.py_date_format + } + } + }, chart_type: 'line', } diff --git a/erpnext/support/report/minutes_to_first_response_for_issues/minutes_to_first_response_for_issues.py b/erpnext/support/report/minutes_to_first_response_for_issues/minutes_to_first_response_for_issues.py index e88e756412..57c2d442b2 100644 --- a/erpnext/support/report/minutes_to_first_response_for_issues/minutes_to_first_response_for_issues.py +++ b/erpnext/support/report/minutes_to_first_response_for_issues/minutes_to_first_response_for_issues.py @@ -20,7 +20,9 @@ def execute(filters=None): data = frappe.db.sql('''select date(creation) as creation_date, avg(mins_to_first_response) as mins - from tabIssue where date(creation) between %s and %s + from tabIssue + where date(creation) between %s and %s + and mins_to_first_response > 0 group by creation_date order by creation_date desc''', (filters.from_date, filters.to_date)) return columns, data