feat: add us-cpa case intake workflow
This commit is contained in:
@@ -6,6 +6,7 @@ import sys
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from us_cpa.cases import CaseConflictError, CaseManager
|
||||
from us_cpa.sources import TaxYearCorpus, bootstrap_irs_catalog
|
||||
|
||||
COMMANDS = (
|
||||
@@ -47,6 +48,12 @@ def _require_case_dir(args: argparse.Namespace) -> Path:
|
||||
return Path(args.case_dir).expanduser().resolve()
|
||||
|
||||
|
||||
def _load_json_file(path_value: str | None) -> dict[str, Any]:
|
||||
if not path_value:
|
||||
return {}
|
||||
return json.loads(Path(path_value).expanduser().resolve().read_text())
|
||||
|
||||
|
||||
def build_parser() -> argparse.ArgumentParser:
|
||||
parser = argparse.ArgumentParser(
|
||||
prog="us-cpa",
|
||||
@@ -74,6 +81,10 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
"extract-docs", help="Extract facts from case documents."
|
||||
)
|
||||
_add_common_arguments(extract_docs)
|
||||
extract_docs.add_argument("--create-case", action="store_true")
|
||||
extract_docs.add_argument("--case-label")
|
||||
extract_docs.add_argument("--facts-json")
|
||||
extract_docs.add_argument("--input-file", action="append", default=[])
|
||||
|
||||
render_forms = subparsers.add_parser(
|
||||
"render-forms", help="Render compiled IRS forms."
|
||||
@@ -103,7 +114,35 @@ def main(argv: list[str] | None = None) -> int:
|
||||
}
|
||||
return _emit(payload, args.format)
|
||||
|
||||
if args.command in {"prepare", "review", "extract-docs", "render-forms", "export-efile-ready"}:
|
||||
if args.command == "extract-docs":
|
||||
case_dir = _require_case_dir(args)
|
||||
manager = CaseManager(case_dir)
|
||||
if args.create_case:
|
||||
if not args.case_label:
|
||||
raise SystemExit("--case-label is required when --create-case is used.")
|
||||
manager.create_case(case_label=args.case_label, tax_year=args.tax_year)
|
||||
elif not manager.manifest_path.exists():
|
||||
raise SystemExit("Case manifest not found. Use --create-case for a new case.")
|
||||
|
||||
try:
|
||||
result = manager.intake(
|
||||
tax_year=args.tax_year,
|
||||
user_facts=_load_json_file(args.facts_json),
|
||||
document_paths=[
|
||||
Path(path_value).expanduser().resolve() for path_value in args.input_file
|
||||
],
|
||||
)
|
||||
except CaseConflictError as exc:
|
||||
print(json.dumps(exc.issue, indent=2))
|
||||
return 1
|
||||
payload = {
|
||||
"command": args.command,
|
||||
"format": args.format,
|
||||
**result,
|
||||
}
|
||||
return _emit(payload, args.format)
|
||||
|
||||
if args.command in {"prepare", "review", "render-forms", "export-efile-ready"}:
|
||||
case_dir = _require_case_dir(args)
|
||||
payload = {
|
||||
"command": args.command,
|
||||
|
||||
Reference in New Issue
Block a user