From c82611aa6260e303995d9ed09b59799ef6b44c03 Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Mon, 2 Aug 2021 23:19:57 +0200 Subject: [PATCH] feat: sort timesheets by start time --- .../projects/doctype/timesheet/timesheet.py | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/erpnext/projects/doctype/timesheet/timesheet.py b/erpnext/projects/doctype/timesheet/timesheet.py index 1e11f73cfdc..f82072e6318 100644 --- a/erpnext/projects/doctype/timesheet/timesheet.py +++ b/erpnext/projects/doctype/timesheet/timesheet.py @@ -216,15 +216,15 @@ class Timesheet(Document): @frappe.whitelist() def get_projectwise_timesheet_data(project=None, parent=None, from_time=None, to_time=None): - condition = '' + condition = "" if project: - condition += "and tsd.project = %(project)s" + condition += "AND tsd.project = %(project)s " if parent: - condition += "AND tsd.parent = %(parent)s" + condition += "AND tsd.parent = %(parent)s " if from_time and to_time: condition += "AND CAST(tsd.from_time as DATE) BETWEEN %(from_time)s AND %(to_time)s" - return frappe.db.sql(""" + query = f""" SELECT tsd.name as name, @@ -242,16 +242,25 @@ def get_projectwise_timesheet_data(project=None, parent=None, from_time=None, to INNER JOIN `tabTimesheet` ts ON ts.name = tsd.parent - WHERE tsd.parenttype = 'Timesheet' - AND tsd.docstatus=1 {0} + WHERE + + tsd.parenttype = 'Timesheet' + AND tsd.docstatus = 1 AND tsd.is_billable = 1 - AND tsd.sales_invoice is null - """.format(condition), { - 'project': project, - 'parent': parent, - 'from_time': from_time, - 'to_time': to_time - }, as_dict=1) + AND tsd.sales_invoice is NULL + {condition} + + ORDER BY tsd.from_time ASC + """ + + filters = { + "project": project, + "parent": parent, + "from_time": from_time, + "to_time": to_time + } + + return frappe.db.sql(query, filters, as_dict=1) @frappe.whitelist() @frappe.validate_and_sanitize_search_inputs