Skip to content
Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions src/fwtv/verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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] = []
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/fwtv/widgets/settings_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 1 addition & 9 deletions src/fwtv/widgets/working_time_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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