35 lines
876 B
Python
35 lines
876 B
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""Reprocess stored supplier-invoice files through the app code."""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import argparse
|
||
|
|
import asyncio
|
||
|
|
import json
|
||
|
|
|
||
|
|
from app.billing.backend.supplier_invoices import reprocess_uploaded_file
|
||
|
|
from app.core.database import init_db
|
||
|
|
|
||
|
|
|
||
|
|
async def _run(file_ids: list[int]) -> list[dict]:
|
||
|
|
results = []
|
||
|
|
for file_id in file_ids:
|
||
|
|
result = await reprocess_uploaded_file(file_id)
|
||
|
|
results.append({"file_id": file_id, "result": result})
|
||
|
|
return results
|
||
|
|
|
||
|
|
|
||
|
|
def main() -> int:
|
||
|
|
parser = argparse.ArgumentParser()
|
||
|
|
parser.add_argument("file_ids", nargs="+", type=int)
|
||
|
|
args = parser.parse_args()
|
||
|
|
|
||
|
|
init_db()
|
||
|
|
payload = asyncio.run(_run(args.file_ids))
|
||
|
|
print(json.dumps(payload, ensure_ascii=False, indent=2, default=str))
|
||
|
|
return 0
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
raise SystemExit(main())
|