refactor: timesheet

This commit is contained in:
Anupam
2021-05-12 16:17:32 +05:30
parent aa9e172091
commit fd4743cc31
17 changed files with 498 additions and 1197 deletions

View File

@@ -126,7 +126,7 @@ def get_timesheet_details(filters, timesheet_list):
timesheet_details = frappe.get_all(
"Timesheet Detail",
filters = timesheet_details_filter,
fields=["from_time", "to_time", "hours", "billable", "billing_hours", "billing_rate", "parent"]
fields=["from_time", "to_time", "hours", "is_billable", "billing_hours", "billing_rate", "parent"]
)
timesheet_details_map = frappe._dict()
@@ -139,7 +139,7 @@ def get_billable_and_total_duration(activity, start_time, end_time):
precision = frappe.get_precision("Timesheet Detail", "hours")
activity_duration = time_diff_in_hours(end_time, start_time)
billing_duration = 0.0
if activity.billable:
if activity.is_billable:
billing_duration = activity.billing_hours
if activity_duration != activity.billing_hours:
billing_duration = activity_duration * activity.billing_hours / activity.hours

View File

@@ -140,7 +140,7 @@ class EmployeeHoursReport:
additional_filters += f"AND tt.{field} = '{self.filters.get(field)}'"
self.filtered_time_logs = frappe.db.sql('''
SELECT tt.employee AS employee, ttd.hours AS hours, ttd.billable AS billable, ttd.project AS project
SELECT tt.employee AS employee, ttd.hours AS hours, ttd.is_billable AS is_billable, ttd.project AS project
FROM `tabTimesheet Detail` AS ttd
JOIN `tabTimesheet` AS tt
ON ttd.parent = tt.name
@@ -153,14 +153,14 @@ class EmployeeHoursReport:
def generate_stats_by_employee(self):
self.stats_by_employee = frappe._dict()
for emp, hours, billable, project in self.filtered_time_logs:
for emp, hours, is_billable, project in self.filtered_time_logs:
self.stats_by_employee.setdefault(
emp, frappe._dict()
).setdefault('billed_hours', 0.0)
self.stats_by_employee[emp].setdefault('non_billed_hours', 0.0)
if billable:
if is_billable:
self.stats_by_employee[emp]['billed_hours'] += flt(hours, 2)
else:
self.stats_by_employee[emp]['non_billed_hours'] += flt(hours, 2)

View File

@@ -31,7 +31,7 @@ class TestEmployeeUtilization(unittest.TestCase):
timesheet1.append("time_logs", {
"activity_type": get_random("Activity Type"),
"hours": 5,
"billable": 1,
"is_billable": 1,
"from_time": '2021-04-01 13:30:00.000000',
"to_time": '2021-04-01 18:30:00.000000'
})
@@ -46,7 +46,7 @@ class TestEmployeeUtilization(unittest.TestCase):
timesheet2.append("time_logs", {
"activity_type": get_random("Activity Type"),
"hours": 10,
"billable": 0,
"is_billable": 0,
"from_time": '2021-04-01 13:30:00.000000',
"to_time": '2021-04-01 23:30:00.000000',
"project": cls.test_project.name

View File

@@ -14,7 +14,7 @@ class TestProjectProfitability(unittest.TestCase):
if not frappe.db.exists('Salary Component', 'Timesheet Component'):
frappe.get_doc({'doctype': 'Salary Component', 'salary_component': 'Timesheet Component'}).insert()
make_salary_structure_for_timesheet(emp, company='_Test Company')
self.timesheet = make_timesheet(emp, simulate = True, billable=1)
self.timesheet = make_timesheet(emp, simulate = True, is_billable=1)
self.salary_slip = make_salary_slip(self.timesheet.name)
self.salary_slip.submit()
self.sales_invoice = make_sales_invoice(self.timesheet.name, '_Test Item', '_Test Customer')