Commonify code
This commit is contained in:
parent
94514ffee9
commit
3d27aabdeb
@ -22,6 +22,5 @@ frappe.query_reports["Employee Billing Summary"] = {
|
|||||||
fieldtype: "Date",
|
fieldtype: "Date",
|
||||||
default: frappe.datetime.add_days(frappe.datetime.get_today(), 30)
|
default: frappe.datetime.add_days(frappe.datetime.get_today(), 30)
|
||||||
},
|
},
|
||||||
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ from frappe.utils import time_diff_in_hours
|
|||||||
|
|
||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
filters = frappe._dict(filters or {})
|
filters = frappe._dict(filters or {})
|
||||||
print(filters)
|
|
||||||
|
|
||||||
columns = get_columns()
|
columns = get_columns()
|
||||||
|
|
||||||
data = get_data(filters)
|
data = get_data(filters)
|
||||||
@ -85,7 +83,8 @@ def get_data(filters):
|
|||||||
|
|
||||||
total_hours = 0
|
total_hours = 0
|
||||||
total_billable_hours = 0
|
total_billable_hours = 0
|
||||||
print("-------------------------------------------->>>>>>>")
|
total_amount = 0
|
||||||
|
|
||||||
for time in timesheet_details:
|
for time in timesheet_details:
|
||||||
time_start = time.from_time
|
time_start = time.from_time
|
||||||
time_end = frappe.utils.add_to_date(time.from_time, hours=time.hours)
|
time_end = frappe.utils.add_to_date(time.from_time, hours=time.hours)
|
||||||
@ -94,26 +93,28 @@ def get_data(filters):
|
|||||||
to_date = frappe.utils.get_datetime(filters.to_date)
|
to_date = frappe.utils.get_datetime(filters.to_date)
|
||||||
|
|
||||||
if time_start <= from_date and time_end <= to_date:
|
if time_start <= from_date and time_end <= to_date:
|
||||||
total_hours += abs(time_diff_in_hours(time_end, from_date))
|
total_hours, total_billable_hours, total_amount = get_billable_and_total_hours(time, time_end, from_date, total_hours, total_billable_hours, total_amount)
|
||||||
print(from_date, time_end)
|
|
||||||
print("case 1", entries.name,time_diff_in_hours(time_end, from_date))
|
|
||||||
elif time_start >= from_date and time_end >= to_date:
|
elif time_start >= from_date and time_end >= to_date:
|
||||||
total_hours += abs(time_diff_in_hours(to_date, time_start))
|
total_hours, total_billable_hours, total_amount = get_billable_and_total_hours(time, to_date, time_start, total_hours, total_billable_hours, total_amount)
|
||||||
print(time_start, to_date)
|
|
||||||
print("case 2", entries.name,time_diff_in_hours(to_date, time_start))
|
|
||||||
elif time_start >= from_date and time_end <= to_date:
|
elif time_start >= from_date and time_end <= to_date:
|
||||||
total_hours = entries.total_hours
|
total_hours, total_billable_hours, total_amount = get_billable_and_total_hours(time, time_end, time_start, total_hours, total_billable_hours, total_amount)
|
||||||
print("case 3 all set", entries.name)
|
|
||||||
|
|
||||||
print(total_hours)
|
|
||||||
print("-------------------------------------------->>>>>>>")
|
|
||||||
row = {
|
row = {
|
||||||
"employee": entries.employee,
|
"employee": entries.employee,
|
||||||
"employee_name": entries.employee_name,
|
"employee_name": entries.employee_name,
|
||||||
"timesheet": entries.name,
|
"timesheet": entries.name,
|
||||||
"total_billable_hours": entries.total_billable_hours,
|
"total_billable_hours": total_billable_hours,
|
||||||
"total_hours": entries.total_hours,
|
"total_hours": total_hours,
|
||||||
"amount": 1
|
"amount": total_amount
|
||||||
}
|
}
|
||||||
|
|
||||||
data.append(row)
|
data.append(row)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def get_billable_and_total_hours(time, end, start, total_hours, total_billable_hours, total_amount):
|
||||||
|
total_hours += abs(time_diff_in_hours(end, start))
|
||||||
|
if time.billable:
|
||||||
|
total_billable_hours += abs(time_diff_in_hours(end, start))
|
||||||
|
total_amount += total_billable_hours * time.billing_rate
|
||||||
|
|
||||||
|
return total_hours, total_billable_hours, total_amount
|
||||||
|
Loading…
x
Reference in New Issue
Block a user