Add direct Cash-in-Hand ledger selection for cash payment review
This commit is contained in:
@@ -252,7 +252,7 @@ def cash_payment_review(
|
||||
|
||||
@router.post("/ledgers")
|
||||
async def cash_payment_ledgers(request: Request):
|
||||
"""Return cached ledgers immediately or start a non-blocking Tally master job."""
|
||||
"""Load Cash-in-Hand ledgers directly; keep full-ledger sync only as manual fallback."""
|
||||
form = await request.form()
|
||||
validate_csrf(request, str(form.get("csrf_token") or ""))
|
||||
db = CommonSessionLocal()
|
||||
@@ -268,32 +268,46 @@ async def cash_payment_ledgers(request: Request):
|
||||
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()
|
||||
company_name = str(form.get("company_name") or "").strip()
|
||||
date_from = str(form.get("date_from") or date.today().isoformat()).strip()
|
||||
force_refresh = str(form.get("force_refresh") or "").strip().lower() in {"1","true","yes","on"}
|
||||
ledger_scope = str(form.get("ledger_scope") or "cash").strip().lower()
|
||||
force_refresh = str(form.get("force_refresh") or "").strip().lower() in {"1", "true", "yes", "on"}
|
||||
if not tally_guid:
|
||||
return JSONResponse({"ok": False, "error": "Select an open 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_start",
|
||||
{
|
||||
**_accounting_storage_payload(selected_client, fy),
|
||||
"tally_guid": tally_guid,
|
||||
"company_name": company_name,
|
||||
"force_refresh": force_refresh,
|
||||
},
|
||||
timeout_seconds=20,
|
||||
)
|
||||
payload = {
|
||||
**_accounting_storage_payload(selected_client, fy),
|
||||
"tally_guid": tally_guid,
|
||||
"company_name": company_name,
|
||||
}
|
||||
if ledger_scope == "all":
|
||||
# Explicit manual fallback preserves the existing full-master async flow.
|
||||
payload["force_refresh"] = force_refresh
|
||||
result = request_agent_command(
|
||||
node.node_code,
|
||||
"accounting_cash_payment_ledgers_start",
|
||||
payload,
|
||||
timeout_seconds=20,
|
||||
)
|
||||
else:
|
||||
# Normal path: small filtered Tally collection, no full ledger cache.
|
||||
result = request_agent_command(
|
||||
node.node_code,
|
||||
"accounting_cash_payment_cash_ledgers",
|
||||
payload,
|
||||
timeout_seconds=30,
|
||||
)
|
||||
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 start Tally ledger sync.")}, status_code=409)
|
||||
return JSONResponse({"ok": False, "error": str(result.get("error") or "Could not load Tally ledgers.")}, status_code=409)
|
||||
return JSONResponse({"ok": True, **(result.get("result") or {})})
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
Reference in New Issue
Block a user