From 3e7b14ca6cb4db6e3f5bba0969c2a476d2bd8df2 Mon Sep 17 00:00:00 2001 From: Leon Date: Fri, 4 Jul 2025 15:30:26 +0200 Subject: [PATCH] fix release workflowfixed a bug where the tolerance was not applied correctly when checking the attendances --- CHANGELOG.md | 6 ++++++ src/fwtv/verifier.py | 9 +++++---- src/fwtv/widgets/settings_widget.py | 2 +- src/fwtv/widgets/working_time_widget.py | 10 +--------- tests/test_verifier.py | 2 +- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 731ad82..a2ec67e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to fwtv module will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0) +## Unreleased + +### Fixed + +- fixed a bug where the tolerance was not applied correctly when checking the attendances + ## [2.4.0] - 2025-06-06 ### Added diff --git a/src/fwtv/verifier.py b/src/fwtv/verifier.py index 867ff8e..f453717 100644 --- a/src/fwtv/verifier.py +++ b/src/fwtv/verifier.py @@ -90,7 +90,7 @@ def time_attended(self) -> datetime.timedelta: return calculate_time_attended(self.attendances) -def verify_attendances(attendances: list[Attendance]) -> list[Error]: +def verify_attendances(attendances: list[Attendance], tolerance: datetime.timedelta) -> list[Error]: """Verify that the specified attendances meet the requirements (in order). Requirements: @@ -99,6 +99,7 @@ def verify_attendances(attendances: list[Attendance]) -> list[Error]: 3. It shall not be allowed to attend for more than 6 hours without not attended for at least 30 minutes :param attendances: attendances to be verified + :param tolerance: adjustable tolerance which is added to the limits :return: a list of errors found during verification """ errors: list[Error] = [] @@ -122,11 +123,11 @@ def verify_attendances(attendances: list[Attendance]) -> list[Error]: cumulated_break_time = calculate_break_time(current_attendances) reason = None reset = False - if cumulated_time_attended > HOURS_6 and cumulated_break_time < MINUTES_30: + if cumulated_time_attended > HOURS_6 + tolerance and cumulated_break_time < MINUTES_30: reason = 'Attended more than 6 hours without a cumulated break of 30 min' - if cumulated_time_attended > HOURS_9 and cumulated_break_time < MINUTES_45: + if cumulated_time_attended > HOURS_9 + tolerance and cumulated_break_time < MINUTES_45: reason = 'Attended more than 9 hours without a cumulated break of 45 min' - if cumulated_time_attended > HOURS_10: + if cumulated_time_attended > HOURS_10 + tolerance: reason = 'Attended more than 10 hours without a single break of 11 hours' reset = True if reason: diff --git a/src/fwtv/widgets/settings_widget.py b/src/fwtv/widgets/settings_widget.py index 8e42cf1..60b7a48 100644 --- a/src/fwtv/widgets/settings_widget.py +++ b/src/fwtv/widgets/settings_widget.py @@ -57,7 +57,7 @@ def __init__(self, label: str, default: int, *args: typing.Any, **kwargs: typing self.label = QLabel(label, self) self.qh.addWidget(self.label) - self.picker = QDoubleSpinBox(self) + self.picker = QDoubleSpinBox(self, maximum=999) # allow maximum of 9-digit number self.picker.setSingleStep(1) self.picker.setDecimals(0) self.picker.setSizePolicy(QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Minimum) diff --git a/src/fwtv/widgets/working_time_widget.py b/src/fwtv/widgets/working_time_widget.py index 7da4b0c..df4fb27 100644 --- a/src/fwtv/widgets/working_time_widget.py +++ b/src/fwtv/widgets/working_time_widget.py @@ -48,15 +48,7 @@ def get_errors( preconditions[name].append(str(e)) continue - errors = verifier.verify_attendances(employee_attendances) - # ignore all errors where the time attended is the tolerance above the limit, as factorial's automated time - # tracking is not precises enough - errors = [ - e - for e in errors - if e.time_attended > datetime.timedelta(hours=6, minutes=tolerance) - and e.time_attended > datetime.timedelta(hours=9, minutes=tolerance) - ] + errors = verifier.verify_attendances(employee_attendances, datetime.timedelta(minutes=tolerance)) if errors: employee_errors[name] = errors return preconditions, employee_errors diff --git a/tests/test_verifier.py b/tests/test_verifier.py index 2a910fd..c89d8bf 100644 --- a/tests/test_verifier.py +++ b/tests/test_verifier.py @@ -311,5 +311,5 @@ def test_error_break_time(attendances: list[verifier.Attendance], expected: date ) def test_verify_work_time(attendances: list[verifier.Attendance], error_count: int): """Verify found error count.""" - errors = verifier.verify_attendances(attendances) + errors = verifier.verify_attendances(attendances, tolerance=datetime.timedelta()) assert len(errors) == error_count