Add Phase 12 server AI semantic accounting layer

This commit is contained in:
A R R R Associates
2026-08-22 21:36:27 +05:30
parent 016299cf0c
commit ef2b0e1f83
14 changed files with 1023 additions and 5 deletions
+35 -1
View File
@@ -9,7 +9,7 @@ from app.core.db.common import CommonSessionLocal
from app.core.security.csrf import get_or_create_csrf_token, validate_csrf
from app.core.templating import templates
from app.modules.accounting.bank_service import (
confirm_review, import_completed_job, preflight_choices, queue_post, queue_preflight,
ai_assist_transaction, confirm_review, import_completed_job, preflight_choices, queue_post, queue_preflight,
queue_rows, sync_posting, visible_workstations,
)
from app.modules.accounting.ledger_learning_service import active_natures
@@ -121,3 +121,37 @@ def post(request: Request, tx_id: int, client_id: int = Form(...), bank_ledger_n
except Exception as exc:
db.rollback(); return _go(client_id, error=str(exc))
finally: db.close()
@router.post("/{tx_id}/ai-assist")
def ai_assist(
request: Request,
tx_id: int,
client_id: int = Form(...),
csrf_token: str = Form(...),
):
validate_csrf(request, csrf_token)
db = CommonSessionLocal()
try:
user, denied = _require_partner(request, db, "accounting.learning.manage")
if denied:
return denied
client, _, scope = _find_visible_client(db, request, user, client_id)
if not client:
return _go(error="Client is not visible.")
decision = ai_assist_transaction(
db,
tx_id=tx_id,
tenant_id=scope.tenant_id,
client_id=client.id,
user_id=user.id,
)
return _go(
client.id,
message=f"AI semantic fallback completed at {decision.combined_confidence}% combined confidence.",
)
except Exception as exc:
db.rollback()
return _go(client_id, error=str(exc))
finally:
db.close()