Move cash payment compliance to SQLite accounting mirror
This commit is contained in:
@@ -153,6 +153,12 @@ def cash_payment_review(
|
||||
saved: int = 0,
|
||||
error: str = "",
|
||||
):
|
||||
"""Cash Payment Compliance from the local Accounting Mirror only.
|
||||
|
||||
TallyPrime is not contacted by this review route. The Local Agent is used
|
||||
only to read the client's local .act mirror database through the existing
|
||||
secure tunnel. Users refresh that mirror separately from /tools/tally.
|
||||
"""
|
||||
db = CommonSessionLocal()
|
||||
try:
|
||||
user, response = _require_partner(request, db, "accounting.tally.view")
|
||||
@@ -170,58 +176,68 @@ def cash_payment_review(
|
||||
fy_start_year = int(fy.split("-", 1)[0])
|
||||
start_text = date_from or date(fy_start_year, 4, 1).isoformat()
|
||||
end_text = date_to or today.isoformat()
|
||||
live_result = None
|
||||
|
||||
review = None
|
||||
cache_job = None
|
||||
mirror_status = None
|
||||
command_error = error or ""
|
||||
|
||||
if selected_client and node and online:
|
||||
try:
|
||||
status_response = request_agent_command(
|
||||
node.node_code,
|
||||
"phase4_status",
|
||||
_accounting_storage_payload(selected_client, _financial_year_for_date(date.fromisoformat(start_text))),
|
||||
timeout_seconds=20,
|
||||
if selected_client:
|
||||
if not node or not online:
|
||||
command_error = command_error or (
|
||||
"ERP Local Agent is offline. Cash Payment Review reads the client's local "
|
||||
"SQLite Accounting Mirror, so the storage agent must be online."
|
||||
)
|
||||
if status_response.get("ok"):
|
||||
live_result = status_response.get("result") or {}
|
||||
else:
|
||||
command_error = str(status_response.get("error") or "Local Agent status failed.")
|
||||
|
||||
if job_id:
|
||||
status = request_agent_command(
|
||||
else:
|
||||
storage_payload = _accounting_storage_payload(
|
||||
selected_client,
|
||||
_financial_year_for_date(date.fromisoformat(start_text)),
|
||||
)
|
||||
try:
|
||||
status_response = request_agent_command(
|
||||
node.node_code,
|
||||
"accounting_cash_payment_cache_status",
|
||||
{
|
||||
**_accounting_storage_payload(selected_client, _financial_year_for_date(date.fromisoformat(start_text))),
|
||||
"job_id": str(job_id),
|
||||
},
|
||||
"accounting_mirror_status",
|
||||
storage_payload,
|
||||
timeout_seconds=20,
|
||||
)
|
||||
if status.get("ok"):
|
||||
cache_job = (status.get("result") or {}).get("job")
|
||||
if status_response.get("ok"):
|
||||
mirror_status = status_response.get("result") or {}
|
||||
else:
|
||||
command_error = str(status.get("error") or "Could not read cash-payment cache status.")
|
||||
command_error = str(
|
||||
status_response.get("error") or "Could not read the local Accounting Mirror status."
|
||||
)
|
||||
except Exception as exc:
|
||||
command_error = str(exc)
|
||||
|
||||
if analyze and job_id and cache_job and cache_job.get("status") == "completed":
|
||||
result = request_agent_command(
|
||||
node.node_code,
|
||||
"accounting_cash_payment_cache_analyze",
|
||||
{
|
||||
**_accounting_storage_payload(selected_client, _financial_year_for_date(date.fromisoformat(start_text))),
|
||||
"job_id": str(job_id),
|
||||
"cash_limit": float(setting.cash_limit),
|
||||
"split_window_days": int(setting.split_window_days),
|
||||
"near_limit_percent": float(setting.near_limit_percent),
|
||||
},
|
||||
timeout_seconds=120,
|
||||
)
|
||||
if result.get("ok"):
|
||||
review = (result.get("result") or {}).get("cash_payment_review")
|
||||
else:
|
||||
command_error = str(result.get("error") or "Cash payment SQLite analysis failed.")
|
||||
except Exception as exc:
|
||||
command_error = str(exc)
|
||||
if analyze and not command_error:
|
||||
try:
|
||||
result = request_agent_command(
|
||||
node.node_code,
|
||||
"accounting_cash_payment_mirror_analyze",
|
||||
{
|
||||
**storage_payload,
|
||||
"date_from": start_text,
|
||||
"date_to": end_text,
|
||||
"cash_ledger_name": str(cash_ledger_name or "").strip(),
|
||||
"cash_limit": float(setting.cash_limit),
|
||||
"split_window_days": int(setting.split_window_days),
|
||||
"near_limit_percent": float(setting.near_limit_percent),
|
||||
"requested_by_user_id": int(user.id),
|
||||
},
|
||||
timeout_seconds=120,
|
||||
)
|
||||
if result.get("ok"):
|
||||
body = result.get("result") or {}
|
||||
review = body.get("cash_payment_review")
|
||||
mirror_status = {
|
||||
**(mirror_status or {}),
|
||||
"mirror": body.get("mirror") or (mirror_status or {}).get("mirror") or {},
|
||||
}
|
||||
else:
|
||||
command_error = str(
|
||||
result.get("error") or "Cash payment SQLite mirror analysis failed."
|
||||
)
|
||||
except Exception as exc:
|
||||
command_error = str(exc)
|
||||
|
||||
return _render(
|
||||
request,
|
||||
@@ -232,14 +248,15 @@ def cash_payment_review(
|
||||
selected_client=selected_client,
|
||||
storage_node=node,
|
||||
agent_online=online,
|
||||
live_result=live_result,
|
||||
live_result=None,
|
||||
mirror_status=mirror_status,
|
||||
selected_tally_guid=str(tally_guid or ""),
|
||||
date_from=start_text,
|
||||
date_to=end_text,
|
||||
setting=setting,
|
||||
review=review,
|
||||
cache_job=cache_job,
|
||||
active_job_id=str(job_id or ""),
|
||||
cache_job=None,
|
||||
active_job_id="",
|
||||
selected_cash_ledger_name=str(cash_ledger_name or ""),
|
||||
saved=bool(saved),
|
||||
command_error=command_error,
|
||||
|
||||
Reference in New Issue
Block a user