fix(Timesheet): only update to_time if it's more than 1 second off (#47703)

* Only update to_time if it's more than 1 second off

Before, to_time was updated even when it was almost the same as the expected time (like 17:20 vs 17:19:59.998). This causes problems because of small rounding errors and caused valid times like 17:20 to be reset. Now, to_time is only updated if the difference is greater than 1 second.

To reproduce the current error:

From Time 09:00:00
To Time 17:20:00 Save
To Time is 17:19:59

* Change data to self in timesheet

* Update timesheet_detail.py
This commit is contained in:
Marc Ramser
2025-06-03 08:28:00 +02:00
committed by GitHub
parent 20b87512d1
commit 0670765baa

View File

@@ -5,7 +5,7 @@
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import add_to_date, flt, get_datetime, time_diff_in_hours
from frappe.utils import add_to_date, flt, get_datetime, time_diff_in_hours, time_diff_in_seconds
class TimesheetDetail(Document):
@@ -48,7 +48,9 @@ class TimesheetDetail(Document):
if not (self.from_time and self.hours):
return
self.to_time = get_datetime(add_to_date(self.from_time, hours=self.hours, as_datetime=True))
_to_time = get_datetime(add_to_date(self.from_time, hours=self.hours, as_datetime=True))
if abs(time_diff_in_seconds(_to_time, self.to_time)) >= 1:
self.to_time = _to_time
def set_project(self):
"""Set project based on task."""