Add preview output list and confirmation before writing
This commit is contained in:
1 parent
7e8e68a9d8
commit
0be2646952
2 files changed
+41
-9
No files matched your search
+36
-4
@@ -10,7 +10,11 @@ from src.taetigkeitsnachweis.logging_utils import configure_logging
|
||||
from src.taetigkeitsnachweis.matcher import match_assignments
|
||||
from src.taetigkeitsnachweis.parser import parse_allocation_records, parse_masterdata_records
|
||||
from src.taetigkeitsnachweis.validator import validate_business_rules, validate_sources
|
||||
from src.taetigkeitsnachweis.writer import build_employee_workbooks, save_employee_workbooks
|
||||
from src.taetigkeitsnachweis.writer import (
|
||||
build_employee_workbooks,
|
||||
build_output_filename,
|
||||
save_employee_workbooks,
|
||||
)
|
||||
|
||||
|
||||
def _load_config(project_root: Path) -> dict:
|
||||
@@ -27,7 +31,7 @@ def _print_issues(issues: list, title: str) -> None:
|
||||
click.echo(f"- [{issue.severity}] {issue.code}: {issue.message}")
|
||||
|
||||
|
||||
def _print_preview(month: int, year: int, matched_assignments: list) -> None:
|
||||
def _print_preview(month: int, year: int, matched_assignments: list, planned_files: list[str]) -> None:
|
||||
click.echo("=== Vorschau der ermittelten Werte ===")
|
||||
click.echo(f"Berichtsmonat : {month:02d}/{year}")
|
||||
click.echo(f"Aktive Faelle : {len(matched_assignments)}")
|
||||
@@ -40,11 +44,16 @@ def _print_preview(month: int, year: int, matched_assignments: list) -> None:
|
||||
f"{item.foerderquote_percent:.2f}%"
|
||||
)
|
||||
|
||||
click.echo("--- Geplante Ausgabedateien ---")
|
||||
for file_name in planned_files:
|
||||
click.echo(f"- {file_name}")
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.option("--month", type=click.IntRange(1, 12), required=True)
|
||||
@click.option("--year", type=click.IntRange(2000, 2100), required=True)
|
||||
def main(month: int, year: int) -> None:
|
||||
@click.option("--yes", is_flag=True, default=False, help="Skip interactive confirmation.")
|
||||
def main(month: int, year: int, yes: bool) -> None:
|
||||
configure_logging()
|
||||
project_root = Path(__file__).resolve().parent
|
||||
|
||||
@@ -93,7 +102,30 @@ def main(month: int, year: int) -> None:
|
||||
if any(issue.severity == "error" for issue in all_issues):
|
||||
raise click.ClickException("Validation failed after matching.")
|
||||
|
||||
_print_preview(month=month, year=year, matched_assignments=matched_assignments)
|
||||
filename_pattern = config["output"]["filename_pattern"]
|
||||
unique_employees = sorted({item.allocation.employee_name for item in matched_assignments})
|
||||
planned_files = [
|
||||
build_output_filename(
|
||||
filename_pattern=filename_pattern,
|
||||
employee_name=employee_name,
|
||||
report_year=year,
|
||||
report_month=month,
|
||||
)
|
||||
for employee_name in unique_employees
|
||||
]
|
||||
|
||||
_print_preview(
|
||||
month=month,
|
||||
year=year,
|
||||
matched_assignments=matched_assignments,
|
||||
planned_files=planned_files,
|
||||
)
|
||||
|
||||
if not yes:
|
||||
confirmed = click.confirm("Dateien jetzt schreiben?", default=False)
|
||||
if not confirmed:
|
||||
click.echo("Abbruch ohne Schreibzugriff.")
|
||||
return
|
||||
|
||||
employee_workbooks = build_employee_workbooks(
|
||||
config=config,
|
||||
|
||||
Reference in new issue
Block a user