Unify accounting analysis on local SQLite mirror
This commit is contained in:
@@ -67,16 +67,36 @@ def _workspace(request, db, user, client_id, tally_guid, date_from, date_to, run
|
||||
online = _node_online(node)
|
||||
today=date.today(); fy=_financial_year_for_date(today); sy=int(fy.split('-',1)[0])
|
||||
start=date_from or date(sy,4,1).isoformat(); end=date_to or today.isoformat()
|
||||
live=None; review=None; error=""
|
||||
live=None; review=None; error=""; history=[]
|
||||
if selected and node and online:
|
||||
st=request_agent_command(node.node_code,"phase4_status",_accounting_storage_payload(selected,_financial_year_for_date(date.fromisoformat(start))),timeout_seconds=20)
|
||||
storage = _accounting_storage_payload(selected,_financial_year_for_date(date.fromisoformat(start)))
|
||||
st=request_agent_command(node.node_code,"accounting_mirror_status",storage,timeout_seconds=20)
|
||||
if st.get("ok"): live=st.get("result") or {}
|
||||
else: error=str(st.get("error") or "Local Agent status failed.")
|
||||
if run and tally_guid:
|
||||
rr=request_agent_command(node.node_code,"accounting_tds_compliance",{**_accounting_storage_payload(selected,_financial_year_for_date(date.fromisoformat(start))),"tally_guid":tally_guid,"date_from":start,"date_to":end,"rules":_rule_payload(_rules(db,_tenant_id(request,user)))},timeout_seconds=120)
|
||||
else: error=str(st.get("error") or "Accounting Mirror status failed.")
|
||||
if run and not error:
|
||||
rr=request_agent_command(
|
||||
node.node_code,
|
||||
"accounting_tds_compliance",
|
||||
{
|
||||
**storage,
|
||||
"date_from":start,
|
||||
"date_to":end,
|
||||
"rules":_rule_payload(_rules(db,_tenant_id(request,user))),
|
||||
"requested_by_user_id":int(user.id),
|
||||
},
|
||||
timeout_seconds=120,
|
||||
)
|
||||
if rr.get("ok"): review=(rr.get("result") or {}).get("tds_review") or {}
|
||||
else: error=str(rr.get("error") or "TDS review failed.")
|
||||
return clients, selected, node, online, live, review, start, end, error
|
||||
try:
|
||||
hist=request_agent_command(
|
||||
node.node_code,"accounting_analysis_history",
|
||||
{**storage,"analysis_type":"TDS_COMPLIANCE","limit":20},timeout_seconds=20
|
||||
)
|
||||
if hist.get("ok"): history=(hist.get("result") or {}).get("runs") or []
|
||||
except Exception:
|
||||
history=[]
|
||||
return clients, selected, node, online, live, review, start, end, error, history
|
||||
|
||||
|
||||
@router.get("/rules")
|
||||
@@ -116,8 +136,8 @@ def compliance(request:Request,client_id:int|None=None,tally_guid:str="",date_fr
|
||||
try:
|
||||
user,response=_require_partner(request,db,"accounting.tally.view")
|
||||
if response:return response
|
||||
clients,selected,node,online,live,review,start,end,error=_workspace(request,db,user,client_id,tally_guid,date_from,date_to,run)
|
||||
return _render(request,db,user,"modules/accounting/templates/accounting/tds_compliance.html",clients=clients,selected_client=selected,node=node,node_online=online,live=live,review=review,date_from=start,date_to=end,tally_guid=tally_guid,error=error,rules=_rules(db,_tenant_id(request,user)))
|
||||
clients,selected,node,online,live,review,start,end,error,history=_workspace(request,db,user,client_id,tally_guid,date_from,date_to,run)
|
||||
return _render(request,db,user,"modules/accounting/templates/accounting/tds_compliance.html",clients=clients,selected_client=selected,node=node,node_online=online,live=live,review=review,date_from=start,date_to=end,tally_guid=tally_guid,error=error,rules=_rules(db,_tenant_id(request,user)),history=history)
|
||||
finally: db.close()
|
||||
|
||||
|
||||
@@ -127,10 +147,10 @@ def liability(request:Request,client_id:int|None=None,tally_guid:str="",date_fro
|
||||
try:
|
||||
user,response=_require_partner(request,db,"accounting.tally.view")
|
||||
if response:return response
|
||||
clients,selected,node,online,live,review,start,end,run_error=_workspace(request,db,user,client_id,tally_guid,date_from,date_to,run)
|
||||
clients,selected,node,online,live,review,start,end,run_error,history=_workspace(request,db,user,client_id,tally_guid,date_from,date_to,run)
|
||||
instructions=[]
|
||||
if selected: instructions=list(db.execute(select(AccountingTDSPostingInstruction).where(AccountingTDSPostingInstruction.tenant_id==_tenant_id(request,user),AccountingTDSPostingInstruction.client_id==selected.id).order_by(AccountingTDSPostingInstruction.id.desc()).limit(100)).scalars())
|
||||
return _render(request,db,user,"modules/accounting/templates/accounting/tds_liability.html",clients=clients,selected_client=selected,node=node,node_online=online,live=live,review=review,date_from=start,date_to=end,tally_guid=tally_guid,error=error or run_error,saved=saved,instructions=instructions)
|
||||
return _render(request,db,user,"modules/accounting/templates/accounting/tds_liability.html",clients=clients,selected_client=selected,node=node,node_online=online,live=live,review=review,date_from=start,date_to=end,tally_guid=tally_guid,error=error or run_error,saved=saved,instructions=instructions,history=history)
|
||||
finally:db.close()
|
||||
|
||||
|
||||
@@ -209,7 +229,7 @@ async def reconciliation_run(request:Request):
|
||||
node=get_active_storage_node_for_branch(db,scope.tenant_id,scope.branch_id)
|
||||
if not node or not _node_online(node): raise ValueError("Local Agent is offline.")
|
||||
dfrom=str(form.get("date_from") or ""); dto=str(form.get("date_to") or ""); guid=str(form.get("tally_guid") or "")
|
||||
rr=request_agent_command(node.node_code,"accounting_tds_compliance",{**_accounting_storage_payload(selected,_financial_year_for_date(date.fromisoformat(dfrom))),"tally_guid":guid,"date_from":dfrom,"date_to":dto,"rules":_rule_payload(_rules(db,_tenant_id(request,user)))},timeout_seconds=120)
|
||||
rr=request_agent_command(node.node_code,"accounting_tds_compliance",{**_accounting_storage_payload(selected,_financial_year_for_date(date.fromisoformat(dfrom))),"date_from":dfrom,"date_to":dto,"rules":_rule_payload(_rules(db,_tenant_id(request,user)))},timeout_seconds=120)
|
||||
if not rr.get("ok"): raise ValueError(str(rr.get("error") or "Tally review failed."))
|
||||
review=(rr.get("result") or {}).get("tds_review") or {}; tally_total=round(sum(float(x.get("actual_tds") or 0) for x in review.get("transactions",[])),2); expected_total=round(sum(float(x.get("expected_tds") or 0) for x in review.get("transactions",[])),2)
|
||||
returns=_parse_external(str(form.get("return_data") or "")); challans=_parse_external(str(form.get("challan_data") or "")); traces=_parse_external(str(form.get("traces_data") or ""))
|
||||
|
||||
Reference in New Issue
Block a user