Add Phase 13 internal accounting model
This commit is contained in:
@@ -10,6 +10,7 @@ from app.modules.accounting.gstr2b_service import nature_lookup, review_purchase
|
||||
from app.modules.accounting.historical_learning_service import active_natures, ledger_mappings
|
||||
from app.modules.accounting.purchase_enrichment_models import AccountingPurchaseEnrichmentRecord
|
||||
from app.modules.accounting.ai_service import ai_assist_purchase as run_ai_assist_purchase, mark_review_outcome
|
||||
from app.modules.accounting.internal_model_service import predict_purchase, record_prediction_review
|
||||
|
||||
VALID_STATUSES = {"all", "pending_analysis", "suggested", "review_required", "reviewed"}
|
||||
VALID_CONFIDENCE = {"all", "high", "medium", "low"}
|
||||
@@ -144,6 +145,14 @@ def review_one(db, *, tenant_id, client_id, purchase_id, final_nature_id, final_
|
||||
final_ledger_name=reviewed.final_ledger_name,
|
||||
user_id=user_id,
|
||||
)
|
||||
record_prediction_review(
|
||||
db,
|
||||
tenant_id=tenant_id,
|
||||
source_type="gstr2b",
|
||||
source_record_id=reviewed.id,
|
||||
final_nature_id=reviewed.final_nature_id,
|
||||
user_id=user_id,
|
||||
)
|
||||
return reviewed
|
||||
|
||||
|
||||
@@ -169,6 +178,14 @@ def bulk_confirm(db, *, tenant_id, client_id, purchase_ids, user_id):
|
||||
final_ledger_name=reviewed.final_ledger_name,
|
||||
user_id=user_id,
|
||||
)
|
||||
record_prediction_review(
|
||||
db,
|
||||
tenant_id=tenant_id,
|
||||
source_type="gstr2b",
|
||||
source_record_id=reviewed.id,
|
||||
final_nature_id=reviewed.final_nature_id,
|
||||
user_id=user_id,
|
||||
)
|
||||
completed+=1
|
||||
return completed
|
||||
|
||||
@@ -182,3 +199,14 @@ def ai_assist_one(db, *, tenant_id, client_id, purchase_id, user_id):
|
||||
if not row:
|
||||
raise ValueError("Purchase record was not found.")
|
||||
return run_ai_assist_purchase(db, row=row, user_id=user_id)
|
||||
|
||||
|
||||
def internal_model_predict_one(db, *, tenant_id, client_id, purchase_id, force_shadow=True):
|
||||
row = db.execute(select(AccountingGSTR2BPurchase).where(
|
||||
AccountingGSTR2BPurchase.id == int(purchase_id),
|
||||
AccountingGSTR2BPurchase.tenant_id == int(tenant_id),
|
||||
AccountingGSTR2BPurchase.client_id == int(client_id),
|
||||
)).scalar_one_or_none()
|
||||
if not row:
|
||||
raise ValueError("Purchase record was not found.")
|
||||
return predict_purchase(db, row=row, force_shadow=force_shadow)
|
||||
|
||||
Reference in New Issue
Block a user