Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(Timesheet) #43881

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions erpnext/projects/doctype/timesheet/timesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,8 @@ def on_submit(self):
self.update_task_and_project()

def validate_mandatory_fields(self):
for data in self.time_logs:
if not data.from_time and not data.to_time:
frappe.throw(_("Row {0}: From Time and To Time is mandatory.").format(data.idx))

if not data.activity_type and self.employee:
frappe.throw(_("Row {0}: Activity Type is mandatory.").format(data.idx))

if flt(data.hours) == 0.0:
frappe.throw(_("Row {0}: Hours value must be greater than zero.").format(data.idx))
for time_log in self.time_logs:
time_log.validate_mandatory_fields(needs_activity_type=bool(self.employee))

def update_task_and_project(self):
tasks, projects = [], []
Expand All @@ -160,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
22 changes: 22 additions & 0 deletions erpnext/projects/doctype/timesheet_detail/timesheet_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,25 @@ def validate_billing_hours(self):
indicator="orange",
alert=True,
)

def validate_mandatory_fields(self, needs_activity_type: bool = False):
for fieldname in ("from_time", "to_time"):
if not self.get(fieldname):
frappe.throw(
_("Row {0}: Please set {1}.").format(
self.idx,
_(self.meta.get_label(fieldname)),
)
)

if needs_activity_type and not self.activity_type:
frappe.throw(
_("Row {0}: please set {1}.").format(self.idx, _(self.meta.get_label("activity_type")))
)

if flt(self.hours) == 0.0:
frappe.throw(
_("Row {0}: The value of the field {1} cannot be 0.").format(
self.idx, _(self.meta.get_label("hours"))
)
)
Loading