[New Script Report] added report daily time log summary

This commit is contained in:
Nabin Hait 2013-04-03 15:44:19 +05:30
parent 0b9ec8cbc1
commit 5c1d3c5a8b
7 changed files with 98 additions and 24 deletions

View File

@ -234,5 +234,6 @@ patch_list = [
'execute:webnotes.reload_doc("selling", "Print Format", "Quotation Classic") # 2013-04-02',
'execute:webnotes.reload_doc("selling", "Print Format", "Quotation Modern") # 2013-04-02',
'execute:webnotes.reload_doc("selling", "Print Format", "Quotation Spartan") # 2013-04-02',
"execute:webnotes.delete_doc('Search Criteria', 'time_log_summary')"
]

View File

@ -62,8 +62,8 @@ wn.module_page["Projects"] = [
icon: "icon-list",
items: [
{
"label":wn._("Time Log Summary"),
route: "Report2/Time Log/Time Log Summary",
"label":wn._("Daily Time Log Summary"),
route: "query-report/Daily Time Log Summary",
doctype: "Time Log"
},
]

View File

@ -0,0 +1,21 @@
wn.query_reports["Daily Time Log Summary"] = {
"filters": [
{
"fieldname": "employee_name",
"label":"Employee Name",
"fieldtype": "Data",
},
{
"fieldname":"from_date",
"label": "From Date",
"fieldtype": "Date",
"default": wn.datetime.get_today()
},
{
"fieldname":"to_date",
"label": "To Date",
"fieldtype": "Date",
"default": wn.datetime.get_today()
}
]
}

View File

@ -0,0 +1,53 @@
from __future__ import unicode_literals
import webnotes
def execute(filters=None):
if not filters: filters = {}
columns = ["Profile:Link:150", "From Time::120", "To Time::120", "Hours::70", "Task::150",
"Project:Link/Project:100", "Status::70"]
profile_map = get_profile_map()
if filters.get("employee_name"):
filters["employee_name"] = "%" + filters.get("employee_name") + "%"
conditions = build_conditions(filters)
time_logs = webnotes.conn.sql("""select * from `tabTime Log`
where docstatus < 2 %s order by owner asc""" % (conditions,), filters, as_dict=1)
data = []
profiles = []
for tl in time_logs:
employee_name = profile_map[tl.owner]
if employee_name not in profiles:
data.append(employee_name)
profiles.append(employee_name)
data.append(["", tl.from_time, tl.to_time, tl.hours, tl.task, tl.project, tl.status])
return columns, data
def get_profile_map():
profiles = webnotes.conn.sql("""select name,
concat(first_name, if(last_name, (' ' + last_name), '')) as fullname
from tabProfile""", as_dict=1)
profile_map = {}
for p in profiles:
profile_map.setdefault(p.name, []).append(p.fullname)
return profile_map
def build_conditions(filters):
conditions = ""
if filters.get("employee_name"):
conditions += """ and owner in (select name from `tabProfile`
where concat(first_name, if(last_name, (' ' + last_name), ''))
like %(employee_name)s)"""
if filters.get("from_date"):
conditions += " and from_time >= %(from_date)s"
if filters.get("to_date"):
conditions += " and to_time <= %(to_date)s"
return conditions

View File

@ -0,0 +1,21 @@
[
{
"creation": "2013-04-03 11:27:52",
"docstatus": 0,
"modified": "2013-04-03 11:48:07",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doctype": "Report",
"is_standard": "Yes",
"name": "__common__",
"ref_doctype": "Time Log",
"report_name": "Daily Time Log Summary",
"report_type": "Script Report"
},
{
"doctype": "Report",
"name": "Daily Time Log Summary"
}
]

View File

@ -1,22 +0,0 @@
[
{
"creation": "2013-03-01 17:36:35",
"docstatus": 0,
"modified": "2013-03-01 18:17:13",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doctype": "Report",
"is_standard": "Yes",
"json": "{\"filters\":[],\"columns\":[[\"name\",\"Time Log\"],[\"status\",\"Time Log\"],[\"from_time\",\"Time Log\"],[\"hours\",\"Time Log\"],[\"activity_type\",\"Time Log\"],[\"owner\",\"Time Log\"],[\"billable\",\"Time Log\"],[\"time_log_batch\",\"Time Log\"],[\"sales_invoice\",\"Time Log\"]],\"sort_by\":\"Time Log.name\",\"sort_order\":\"desc\",\"sort_by_next\":\"\",\"sort_order_next\":\"desc\"}",
"name": "__common__",
"ref_doctype": "Time Log",
"report_name": "Time Log Summary",
"report_type": "Report Builder"
},
{
"doctype": "Report",
"name": "Time Log Summary"
}
]