Add Phase 13 internal accounting model
This commit is contained in:
@@ -11,7 +11,7 @@ from app.modules.accounting.historical_learning_service import active_natures
|
||||
from app.modules.accounting.ledger_learning_service import available_tally_guids
|
||||
from app.modules.accounting.purchase_review_service import (
|
||||
review_queue, review_counts, return_periods, nature_maps_for_rows,
|
||||
explanations_for_rows, mappings_by_nature, review_one, bulk_confirm, ai_assist_one,
|
||||
explanations_for_rows, mappings_by_nature, review_one, bulk_confirm, ai_assist_one, internal_model_predict_one,
|
||||
)
|
||||
from app.modules.accounting.ui import _find_visible_client, _require_partner, _visible_clients
|
||||
from app.modules.core.rbac.deps import get_user_permissions, get_user_roles
|
||||
@@ -139,3 +139,52 @@ def ai_assist_purchase_row(
|
||||
return _redirect(client_id, filters, error=str(exc))
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
@router.post("/purchase/{purchase_id}/internal-predict")
|
||||
def internal_predict_purchase_row(
|
||||
request: Request,
|
||||
purchase_id: int,
|
||||
client_id: int = Form(...),
|
||||
tally_guid: str = Form(""),
|
||||
status: str = Form("all"),
|
||||
confidence: str = Form("all"),
|
||||
source: str = Form("all"),
|
||||
supplier: str = Form(""),
|
||||
return_period: str = Form(""),
|
||||
page: int = Form(1),
|
||||
per_page: int = Form(25),
|
||||
csrf_token: str = Form(...),
|
||||
):
|
||||
validate_csrf(request, csrf_token)
|
||||
db = CommonSessionLocal()
|
||||
filters = {
|
||||
"tally_guid": tally_guid, "status": status, "confidence": confidence,
|
||||
"source": source, "supplier": supplier, "return_period": return_period,
|
||||
"page": page, "per_page": per_page,
|
||||
}
|
||||
try:
|
||||
user, response = _require_partner(request, db, "accounting.learning.manage")
|
||||
if response:
|
||||
return response
|
||||
client, _, scope = _find_visible_client(db, request, user, client_id)
|
||||
if not client:
|
||||
from app.core.http_responses import ui_access_denied
|
||||
return ui_access_denied()
|
||||
prediction = internal_model_predict_one(
|
||||
db,
|
||||
tenant_id=scope.tenant_id,
|
||||
client_id=client.id,
|
||||
purchase_id=purchase_id,
|
||||
force_shadow=True,
|
||||
)
|
||||
return _redirect(
|
||||
client.id,
|
||||
filters,
|
||||
message=f"Internal model shadow prediction recorded at {prediction.predicted_probability * 100:.1f}%.",
|
||||
)
|
||||
except Exception as exc:
|
||||
db.rollback()
|
||||
return _redirect(client_id, filters, error=str(exc))
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
Reference in New Issue
Block a user