feat: add total_billing_hours to Sales Invoice (fp #26783) (#27742)

* feat: add `total_billing_hours` to Sales Invoice

* fix: re-save doctypes

* fix: indentation

* fix: replace reference to old function
This commit is contained in:
Sagar Vora
2021-10-04 16:41:24 +05:30
committed by GitHub
parent 5905cf9002
commit 09ccdee2db
5 changed files with 192 additions and 105 deletions

View File

@@ -215,25 +215,47 @@ 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("""SELECT tsd.name as name,
tsd.parent as parent, 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 {0}
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)
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)
@frappe.whitelist()
def get_timesheet_detail_rate(timelog, currency):