Add Phase 3 Tally accounting master synchronization

This commit is contained in:
A R R R Associates
2026-08-19 16:11:03 +05:30
parent 2f061d29b4
commit 93ae6caa54
11 changed files with 586 additions and 337 deletions
+52 -2
View File
@@ -114,6 +114,7 @@ def tally_tool(
initialized: int = 0,
mapped: int = 0,
unmapped: int = 0,
synced: int = 0,
error: str = "",
):
db = CommonSessionLocal()
@@ -148,7 +149,7 @@ def tally_tool(
try:
response_data = request_agent_command(
node.node_code,
"phase2_status",
"phase3_status",
payload,
timeout_seconds=20,
)
@@ -163,7 +164,7 @@ def tally_tool(
request,
db,
user,
title="Tally Company Mapping",
title="Tally Accounting Masters",
clients=clients,
selected_client=selected_client,
registrations=registrations,
@@ -173,6 +174,7 @@ def tally_tool(
initialized=bool(initialized),
mapped=bool(mapped),
unmapped=bool(unmapped),
synced=bool(synced),
command_error=command_error,
)
finally:
@@ -358,3 +360,51 @@ def unmap_tally_company(
)
finally:
db.close()
@router.post("/sync-masters")
def sync_tally_masters(
request: Request,
client_id: int = Form(...),
tally_guid: str = Form(...),
csrf_token: str = Form(...),
):
validate_csrf(request, csrf_token)
db = CommonSessionLocal()
try:
user, response = _require_partner(request, db, "accounting.tally.sync_masters")
if response:
return response
client, _clients, scope = _find_visible_client(db, request, user, client_id)
if not client:
return _denied()
node = get_active_storage_node_for_branch(db, scope.tenant_id, scope.branch_id)
if not node or not _node_online(node):
return RedirectResponse(
url=f"/tools/tally?client_id={client.id}&error={quote('ERP Local Agent is offline for the active branch.')}",
status_code=303,
)
try:
result = request_agent_command(
node.node_code,
"accounting_sync_masters",
{
"client_id": int(client.id),
"tally_guid": str(tally_guid or "").strip(),
"requested_by_user_id": int(user.id),
},
timeout_seconds=120,
)
if not result.get("ok"):
raise RuntimeError(str(result.get("error") or "Tally master synchronization failed."))
except Exception as exc:
return RedirectResponse(
url=f"/tools/tally?client_id={client.id}&error={quote(str(exc))}",
status_code=303,
)
return RedirectResponse(
url=f"/tools/tally?client_id={client.id}&refresh=1&synced=1",
status_code=303,
)
finally:
db.close()