Add cash ledger extraction and dual progress UI
This commit is contained in:
@@ -147,6 +147,7 @@ def cash_payment_review(
|
||||
date_from: str = "",
|
||||
date_to: str = "",
|
||||
job_id: str = "",
|
||||
cash_ledger_name: str = "",
|
||||
analyze: int = 0,
|
||||
saved: int = 0,
|
||||
error: str = "",
|
||||
@@ -238,6 +239,7 @@ def cash_payment_review(
|
||||
review=review,
|
||||
cache_job=cache_job,
|
||||
active_job_id=str(job_id or ""),
|
||||
selected_cash_ledger_name=str(cash_ledger_name or ""),
|
||||
saved=bool(saved),
|
||||
command_error=command_error,
|
||||
allocation_plan=None,
|
||||
@@ -248,6 +250,47 @@ def cash_payment_review(
|
||||
db.close()
|
||||
|
||||
|
||||
@router.post("/ledgers")
|
||||
async def cash_payment_ledgers(request: Request):
|
||||
form = await request.form()
|
||||
validate_csrf(request, str(form.get("csrf_token") or ""))
|
||||
db = CommonSessionLocal()
|
||||
try:
|
||||
user, response = _require_partner(request, db, "accounting.tally.view")
|
||||
if response:
|
||||
return JSONResponse({"ok": False, "error": "Access denied."}, status_code=403)
|
||||
clients, scope = _visible_clients(db, request, user)
|
||||
try:
|
||||
client_id = int(form.get("client_id") or 0)
|
||||
except Exception:
|
||||
client_id = 0
|
||||
selected_client = next((row for row in clients if int(row.id) == client_id), None)
|
||||
if not selected_client:
|
||||
return JSONResponse({"ok": False, "error": "Select a valid client."}, status_code=400)
|
||||
tally_guid = str(form.get("tally_guid") or "").strip()
|
||||
date_from = str(form.get("date_from") or date.today().isoformat()).strip()
|
||||
if not tally_guid:
|
||||
return JSONResponse({"ok": False, "error": "Select a mapped Tally company."}, status_code=400)
|
||||
node = get_active_storage_node_for_branch(db, scope.tenant_id, scope.branch_id)
|
||||
if not node or not _node_online(node):
|
||||
return JSONResponse({"ok": False, "error": "ERP Local Agent is offline."}, status_code=409)
|
||||
try:
|
||||
fy = _financial_year_for_date(date.fromisoformat(date_from))
|
||||
result = request_agent_command(
|
||||
node.node_code,
|
||||
"accounting_cash_payment_ledgers",
|
||||
{**_accounting_storage_payload(selected_client, fy), "tally_guid": tally_guid},
|
||||
timeout_seconds=45,
|
||||
)
|
||||
except Exception as exc:
|
||||
return JSONResponse({"ok": False, "error": str(exc)}, status_code=502)
|
||||
if not result.get("ok"):
|
||||
return JSONResponse({"ok": False, "error": str(result.get("error") or "Could not read Tally ledgers.")}, status_code=409)
|
||||
return JSONResponse({"ok": True, **(result.get("result") or {})})
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
@router.post("/cache/start")
|
||||
async def start_cash_payment_cache(request: Request):
|
||||
form = await request.form()
|
||||
@@ -266,6 +309,7 @@ async def start_cash_payment_cache(request: Request):
|
||||
if not selected_client:
|
||||
return JSONResponse({"ok": False, "error": "Select a valid client."}, status_code=400)
|
||||
tally_guid = str(form.get("tally_guid") or "").strip()
|
||||
cash_ledger_name = str(form.get("cash_ledger_name") or "").strip()
|
||||
date_from = str(form.get("date_from") or "").strip()
|
||||
date_to = str(form.get("date_to") or "").strip()
|
||||
try:
|
||||
@@ -277,6 +321,8 @@ async def start_cash_payment_cache(request: Request):
|
||||
return JSONResponse({"ok": False, "error": str(exc)}, status_code=400)
|
||||
if not tally_guid:
|
||||
return JSONResponse({"ok": False, "error": "Select a mapped Tally company."}, status_code=400)
|
||||
if not cash_ledger_name:
|
||||
return JSONResponse({"ok": False, "error": "Load the Tally ledgers and confirm the Cash ledger."}, status_code=400)
|
||||
node = get_active_storage_node_for_branch(db, scope.tenant_id, scope.branch_id)
|
||||
if not node or not _node_online(node):
|
||||
return JSONResponse({"ok": False, "error": "ERP Local Agent is offline."}, status_code=409)
|
||||
@@ -290,6 +336,8 @@ async def start_cash_payment_cache(request: Request):
|
||||
"tally_guid": tally_guid,
|
||||
"date_from": date_from,
|
||||
"date_to": date_to,
|
||||
"cash_ledger_name": cash_ledger_name,
|
||||
"cash_ledger_names": [cash_ledger_name],
|
||||
"cash_limit": float(setting.cash_limit),
|
||||
"split_window_days": int(setting.split_window_days),
|
||||
"near_limit_percent": float(setting.near_limit_percent),
|
||||
|
||||
Reference in New Issue
Block a user