Skip to content

Commit

Permalink
refactor(Timesheet): extract get_task_status
Browse files Browse the repository at this point in the history
  • Loading branch information
barredterra committed Oct 29, 2024
1 parent 2a0d509 commit 2f5c863
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions erpnext/projects/doctype/timesheet/timesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def update_billing_hours(self, args: "TimesheetDetail"):
args.update_billing_hours()

def set_status(self):
self.status = {"0": "Draft", "1": "Submitted", "2": "Cancelled"}[str(self.docstatus or 0)]
self.status = ("Draft", "Submitted", "Cancelled")[int(self.docstatus or 0)]

if flt(self.per_billed, self.precision("per_billed")) >= 100.0:
self.status = "Billed"
Expand Down Expand Up @@ -153,19 +153,20 @@ def update_task_and_project(self):
if data.task and data.task not in tasks:
task = frappe.get_doc("Task", data.task)
task.update_time_and_costing()
time_logs_completed = all(tl.completed for tl in self.time_logs if tl.task == task.name)

if time_logs_completed:
task.status = "Completed"
else:
task.status = "Working"
task.status = self.get_task_status(data.task)
task.save()
tasks.append(data.task)

elif data.project and data.project not in projects:
frappe.get_doc("Project", data.project).update_project()
projects.append(data.project)

def get_task_status(self, task: str):
if all(tl.completed for tl in self.time_logs if tl.task == task):
return "Completed"
else:
return "Working"

def validate_dates(self):
for time_log in self.time_logs:
time_log.validate_dates()
Expand Down

0 comments on commit 2f5c863

Please sign in to comment.