diff options
Diffstat (limited to 'overlays')
-rwxr-xr-x | overlays/worktime/worktime/__main__.py | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/overlays/worktime/worktime/__main__.py b/overlays/worktime/worktime/__main__.py index c91d73aa..19737805 100755 --- a/overlays/worktime/worktime/__main__.py +++ b/overlays/worktime/worktime/__main__.py | |||
@@ -175,6 +175,7 @@ class Worktime(object): | |||
175 | time_to_work = None | 175 | time_to_work = None |
176 | force_day_to_work = True | 176 | force_day_to_work = True |
177 | leave_days = set() | 177 | leave_days = set() |
178 | excused_days = set() | ||
178 | leave_budget = dict() | 179 | leave_budget = dict() |
179 | time_per_day = None | 180 | time_per_day = None |
180 | workdays = None | 181 | workdays = None |
@@ -310,8 +311,11 @@ class Worktime(object): | |||
310 | if self.end_date.date() < day or day < self.start_date.date(): | 311 | if self.end_date.date() < day or day < self.start_date.date(): |
311 | continue | 312 | continue |
312 | 313 | ||
313 | if excused_kind == 'leave' and self.would_be_workday(day): | 314 | if self.would_be_workday(day): |
314 | self.leave_days.add(day) | 315 | if excused_kind == 'leave': |
316 | self.leave_days.add(day) | ||
317 | elif time >= self.time_per_day: | ||
318 | self.excused_days.add(day) | ||
315 | holidays[day] = time | 319 | holidays[day] = time |
316 | except IOError as e: | 320 | except IOError as e: |
317 | if e.errno != 2: | 321 | if e.errno != 2: |
@@ -628,6 +632,10 @@ def classification(classification_name, table, **args): | |||
628 | date_format = config.get("WORKTIME", {}).get("DateFormat", '%Y-%m-%d') | 632 | date_format = config.get("WORKTIME", {}).get("DateFormat", '%Y-%m-%d') |
629 | config_dir = BaseDirectory.load_first_config('worktime') | 633 | config_dir = BaseDirectory.load_first_config('worktime') |
630 | days = [worktime.start_date.date() + timedelta(days = x) for x in range(0, (worktime.end_date.date() - worktime.start_date.date()).days + 1)] | 634 | days = [worktime.start_date.date() + timedelta(days = x) for x in range(0, (worktime.end_date.date() - worktime.start_date.date()).days + 1)] |
635 | classify_excused = config.get("day-classification", {}).get(classification_name, {}).get("classify-excused", False) | ||
636 | classify_non_workdays = config.get("day-classification", {}).get(classification_name, {}).get("classify-non-workdays", classify_excused) | ||
637 | if classify_excused and not classify_non_workdays: | ||
638 | print('classify_excused but not classify_non_workdays', file=stderr) | ||
631 | 639 | ||
632 | year_classification = defaultdict(dict) | 640 | year_classification = defaultdict(dict) |
633 | year_offset = defaultdict(lambda: 0) | 641 | year_offset = defaultdict(lambda: 0) |
@@ -655,13 +663,18 @@ def classification(classification_name, table, **args): | |||
655 | fromDay = toDay = parse_single(stripped_line) | 663 | fromDay = toDay = parse_single(stripped_line) |
656 | 664 | ||
657 | for day in [fromDay + timedelta(days = x) for x in range(0, (toDay - fromDay).days + 1)]: | 665 | for day in [fromDay + timedelta(days = x) for x in range(0, (toDay - fromDay).days + 1)]: |
666 | if day in extra_classified: | ||
667 | print(f'Conflicting classification: {day}', file=stderr) | ||
658 | extra_classified[day] = val | 668 | extra_classified[day] = val |
659 | except IOError as e: | 669 | except IOError as e: |
660 | if e.errno != 2: | 670 | if e.errno != 2: |
661 | raise e | 671 | raise e |
662 | 672 | ||
673 | extra_classified_used = set() | ||
663 | for day in days: | 674 | for day in days: |
664 | if not worktime.is_workday(day, extra=False): | 675 | if not classify_excused and worktime.is_workday(day, extra=False) == classify_non_workdays: |
676 | continue | ||
677 | if classify_excused and day not in worktime.excused_days: | ||
665 | continue | 678 | continue |
666 | 679 | ||
667 | classification_days = set() | 680 | classification_days = set() |
@@ -686,8 +699,11 @@ def classification(classification_name, table, **args): | |||
686 | if day in extra_classified: | 699 | if day in extra_classified: |
687 | override = extra_classified[day] | 700 | override = extra_classified[day] |
688 | if override != default_classification: | 701 | if override != default_classification: |
702 | extra_classified_used.add(day) | ||
689 | year_offset[day.year] += 1 if override else -1 | 703 | year_offset[day.year] += 1 if override else -1 |
690 | year_classification[day.year][day] = override if override is not None else default_classification | 704 | year_classification[day.year][day] = override if override is not None else default_classification |
705 | if set(extra_classified.keys()) - set(extra_classified_used): | ||
706 | print(f'Unused manual classification(s): {set(extra_classified.keys()) - set(extra_classified_used)}', file=stderr) | ||
691 | 707 | ||
692 | if not table: | 708 | if not table: |
693 | print(sum(year_offset.values())) | 709 | print(sum(year_offset.values())) |
@@ -697,7 +713,7 @@ def classification(classification_name, table, **args): | |||
697 | row_data = [year, year_offset[year]] | 713 | row_data = [year, year_offset[year]] |
698 | 714 | ||
699 | classified = [day for day, classified in year_classification[year].items() if classified] | 715 | classified = [day for day, classified in year_classification[year].items() if classified] |
700 | count_would_be_workdays = len([1 for day in days if day.year == year and worktime.would_be_workday(day) and day not in worktime.leave_days]) | 716 | count_would_be_workdays = len([1 for day in days if day.year == year and (classify_excused or (worktime.would_be_workday(day) and day not in worktime.leave_days) != classify_non_workdays) and (not classify_excused or day in worktime.excused_days)]) |
701 | if len(year_classification[year]) != count_would_be_workdays: | 717 | if len(year_classification[year]) != count_would_be_workdays: |
702 | row_data.append(f"{len(classified)}/{len(year_classification[year])}/{count_would_be_workdays}") | 718 | row_data.append(f"{len(classified)}/{len(year_classification[year])}/{count_would_be_workdays}") |
703 | else: | 719 | else: |