[enhance] Report for analysis of support hours count

This commit is contained in:
Rohit Waghchaure 2017-06-23 20:20:01 +05:30
parent 2cb598f644
commit 67526f244e
7 changed files with 153 additions and 0 deletions

View File

@ -49,6 +49,12 @@ def get_data():
"doctype": "Issue",
"is_query_report": True
},
{
"type": "report",
"name": "Support Hours",
"doctype": "Issue",
"is_query_report": True
},
]
},
]

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

View File

@ -0,0 +1,8 @@
### Support Hours
This report provide the information about the time slot along with the count of issues has been reported during the slot daywise.
> Support > Reports > Support Hours
<img class="screenshot" alt="Maintenance Visit" src="{{docs_base_url}}/assets/img/support/support_hours.png">

View File

@ -0,0 +1,39 @@
// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
/* eslint-disable */
frappe.query_reports["Support Hours"] = {
"filters": [
{
'lable': __("From Date"),
'fieldname': 'from_date',
'fieldtype': 'Date',
'default': frappe.datetime.nowdate(),
'reqd': 1
},
{
'lable': __("To Date"),
'fieldname': 'to_date',
'fieldtype': 'Date',
'default': frappe.datetime.nowdate(),
'reqd': 1
}
],
get_chart_data: function(columns, result) {
return {
data: {
x: 'Date',
columns: [
['Date'].concat($.map(result, function(d) { return d.date; })),
[columns[3].label].concat($.map(result, function(d) { return d[columns[3].label]; })),
[columns[4].label].concat($.map(result, function(d) { return d[columns[4].label]; })),
[columns[5].label].concat($.map(result, function(d) { return d[columns[5].label]; })),
[columns[6].label].concat($.map(result, function(d) { return d[columns[6].label]; })),
[columns[7].label].concat($.map(result, function(d) { return d[columns[7].label]; }))
]
},
chart_type: 'bar',
}
}
}

View File

@ -0,0 +1,27 @@
{
"add_total_row": 0,
"apply_user_permissions": 1,
"creation": "2017-06-23 14:21:37.558691",
"disabled": 0,
"docstatus": 0,
"doctype": "Report",
"idx": 0,
"is_standard": "Yes",
"letter_head": "",
"modified": "2017-06-23 16:33:31.211390",
"modified_by": "Administrator",
"module": "Support",
"name": "Support Hours",
"owner": "Administrator",
"ref_doctype": "Issue",
"report_name": "Support Hours",
"report_type": "Script Report",
"roles": [
{
"role": "Support Team"
},
{
"role": "System Manager"
}
]
}

View File

@ -0,0 +1,73 @@
# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.utils import add_to_date, getdate, get_datetime
time_slots = {
'12AM - 3AM': '00:00:00-03:00:00',
'3AM - 6AM': '03:00:00-06:00:00',
'6AM - 9AM': '06:00:00-09:00:00',
'9AM - 12PM': '09:00:00-12:00:00',
'12PM - 3PM': '12:00:00-15:00:00',
'3PM - 6PM': '15:00:00-18:00:00',
'6PM - 9PM': '18:00:00-21:00:00',
'9PM - 12AM': '21:00:00-23:00:00'
}
def execute(filters=None):
columns, data = [], []
if not filters.get('periodicity'):
filters['periodicity'] = 'Daily'
columns = get_columns()
data = get_data(filters)
return columns, data
def get_data(filters):
start_date = getdate(filters.from_date)
data = []
while(start_date <= getdate(filters.to_date)):
hours_count = {'date': start_date}
for key, value in time_slots.items():
start_time, end_time = value.split('-')
start_time = get_datetime("{0} {1}".format(start_date.strftime("%Y-%m-%d"), start_time))
end_time = get_datetime("{0} {1}".format(start_date.strftime("%Y-%m-%d"), end_time))
hours_count[key] = get_hours_count(start_time, end_time)
if hours_count:
data.append(hours_count)
start_date = add_to_date(start_date, days=1)
return data
def get_hours_count(start_time, end_time):
data = frappe.db.sql(""" select count(*) from `tabIssue` where creation
between %(start_time)s and %(end_time)s""", {
'start_time': start_time,
'end_time': end_time
}, as_list=1) or []
return data[0][0] if len(data) > 0 else 0
def get_columns():
columns = [{
"fieldname": "date",
"label": _("Date"),
"fieldtype": "Date",
"width": 100
}]
for label in ['12AM - 3AM', '3AM - 6AM', '6AM - 9AM',
'9AM - 12PM', '12PM - 3PM', '3PM - 6PM', '6PM - 9PM', '9PM - 12AM']:
columns.append({
"fieldname": label,
"label": _(label),
"fieldtype": "Data",
"width": 120
})
return columns