From 470534af7825402b20a72f96e46a7d25c0c2689d Mon Sep 17 00:00:00 2001 From: Marc Ramser Date: Tue, 3 Jun 2025 08:29:13 +0200 Subject: [PATCH] fix(Timesheet): Only update to_time if it's more than 1 second off (#47702) * Fix: 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 * Update erpnext/projects/doctype/timesheet/timesheet.py Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com> * Update timesheet.py --------- Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com> --- erpnext/projects/doctype/timesheet/timesheet.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/projects/doctype/timesheet/timesheet.py b/erpnext/projects/doctype/timesheet/timesheet.py index 758b25f0de0..1dcee64e54f 100644 --- a/erpnext/projects/doctype/timesheet/timesheet.py +++ b/erpnext/projects/doctype/timesheet/timesheet.py @@ -7,7 +7,7 @@ import json import frappe from frappe import _ from frappe.model.document import Document -from frappe.utils import add_to_date, flt, get_datetime, getdate, time_diff_in_hours +from frappe.utils import add_to_date, flt, get_datetime, getdate, time_diff_in_hours, time_diff_in_seconds from erpnext.controllers.queries import get_match_cond from erpnext.setup.utils import get_exchange_rate @@ -194,7 +194,7 @@ class Timesheet(Document): return _to_time = get_datetime(add_to_date(data.from_time, hours=data.hours, as_datetime=True)) - if data.to_time != _to_time: + if abs(time_diff_in_seconds(_to_time, data.to_time)) >= 1: data.to_time = _to_time def validate_overlap(self, data):