diff --git a/erpnext/projects/doctype/timesheet/timesheet.py b/erpnext/projects/doctype/timesheet/timesheet.py index 0387e9cde82..239329bc17d 100644 --- a/erpnext/projects/doctype/timesheet/timesheet.py +++ b/erpnext/projects/doctype/timesheet/timesheet.py @@ -7,6 +7,7 @@ import json import frappe from frappe import _ from frappe.model.document import Document +from frappe.query_builder.functions import Date from frappe.utils import flt, get_datetime, getdate from frappe.utils.deprecations import deprecated @@ -302,16 +303,7 @@ class Timesheet(Document): @frappe.whitelist() -<<<<<<< HEAD def get_projectwise_timesheet_data(project=None, parent=None, from_time=None, to_time=None): - condition = "" -======= -def get_projectwise_timesheet_data( - project: str | None = None, - parent: str | None = None, - from_time: str | None = None, - to_time: str | None = None, -): tsd = frappe.qb.DocType("Timesheet Detail") ts = frappe.qb.DocType("Timesheet") @@ -347,54 +339,23 @@ def get_projectwise_timesheet_data( ) ) ->>>>>>> d5df409 (fix(timesheet): scoping whitelisted methods output to projects and timesheets that are acccessible to users (#58267)) if project: - condition += "AND tsd.project = %(project)s " + query = query.where(tsd.project == project) if parent: - condition += "AND tsd.parent = %(parent)s " + query = query.where(tsd.parent == parent) if from_time and to_time: - condition += "AND CAST(tsd.from_time as DATE) BETWEEN %(from_time)s AND %(to_time)s" + query = query.where(Date(tsd.from_time).between(from_time, to_time)) - query = f""" - SELECT - tsd.name as name, - tsd.parent as time_sheet, - tsd.from_time as from_time, - tsd.to_time as to_time, - tsd.billing_hours as billing_hours, - tsd.billing_amount as billing_amount, - tsd.activity_type as activity_type, - tsd.description as description, - ts.currency as currency, - tsd.project_name as project_name - FROM `tabTimesheet Detail` tsd - INNER JOIN `tabTimesheet` ts - ON ts.name = tsd.parent - WHERE - tsd.parenttype = 'Timesheet' - AND tsd.docstatus = 1 - AND tsd.is_billable = 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) + return query.orderby(tsd.from_time).run(as_dict=1) @frappe.whitelist() -<<<<<<< HEAD def get_timesheet_detail_rate(timelog, currency): -======= -def get_timesheet_detail_rate(timelog: str, currency: str): allowed_timesheets = frappe.get_list("Timesheet", pluck="name") if not allowed_timesheets: return 0.0 ->>>>>>> d5df409 (fix(timesheet): scoping whitelisted methods output to projects and timesheets that are acccessible to users (#58267)) ts = frappe.qb.DocType("Timesheet") ts_detail = frappe.qb.DocType("Timesheet Detail") @@ -430,9 +391,6 @@ def get_timesheet(doctype, txt, searchfield, start, page_len, filters): if not filters: filters = {} -<<<<<<< HEAD - condition = "" -======= allowed_timesheets = frappe.get_list("Timesheet", pluck="name") if not allowed_timesheets: @@ -456,32 +414,14 @@ def get_timesheet(doctype, txt, searchfield, start, page_len, filters): ) ) ->>>>>>> d5df409 (fix(timesheet): scoping whitelisted methods output to projects and timesheets that are acccessible to users (#58267)) if filters.get("project"): - condition = "and tsd.project = %(project)s" + query = query.where(tsd.project == filters.get("project")) - return frappe.db.sql( - f"""select distinct tsd.parent from `tabTimesheet Detail` tsd, - `tabTimesheet` ts where - ts.status in ('Submitted', 'Payslip') and tsd.parent = ts.name and - tsd.docstatus = 1 and ts.total_billable_amount > 0 - and tsd.parent LIKE %(txt)s {condition} - order by tsd.parent limit %(page_len)s offset %(start)s""", - { - "txt": "%" + txt + "%", - "start": start, - "page_len": page_len, - "project": filters.get("project"), - }, - ) + return query.orderby(tsd.parent).limit(page_len).offset(start).run() @frappe.whitelist() -<<<<<<< HEAD -def get_timesheet_data(name, project): -======= -def get_timesheet_data(name: str, project: str | None = None): ->>>>>>> d5df409 (fix(timesheet): scoping whitelisted methods output to projects and timesheets that are acccessible to users (#58267)) +def get_timesheet_data(name, project=None): data = None if project: data = get_projectwise_timesheet_data(project, name)