Add Phase 15 customer and sales ledger intelligence

This commit is contained in:
A R R R Associates
2026-08-22 22:43:44 +05:30
parent efc12e20d3
commit 230fe7ffc5
12 changed files with 879 additions and 6 deletions
+31 -1
View File
@@ -12,6 +12,7 @@ from sqlalchemy import func, select
from app.modules.accounting.sales_models import AccountingSalesIncomeTransaction
from app.modules.accounting.sales_taxonomy import ensure_sales_income_taxonomy, sales_income_natures
from app.modules.accounting.sales_learning_service import save_review_mapping, suggestion_for_customer
from app.modules.accounting.taxonomy_models import AccountingNature
@@ -284,7 +285,22 @@ def import_sales_file(
duplicates += 1
continue
nature, confidence, reason = _classify(data, nature_by_code)
learned = suggestion_for_customer(
db,
tenant_id=tenant_id,
client_id=client_id,
customer_name=data["customer_name"],
customer_gstin=data["customer_gstin"],
)
if learned and learned.get("nature") is not None:
nature = learned["nature"]
confidence = int(learned["confidence"])
reason = learned["reason"]
learned_ledger = learned.get("ledger_name") or ""
else:
nature, confidence, reason = _classify(data, nature_by_code)
learned_ledger = learned.get("ledger_name") if learned else ""
record = AccountingSalesIncomeTransaction(
tenant_id=int(tenant_id),
client_id=int(client_id),
@@ -309,6 +325,7 @@ def import_sales_file(
cess=data["cess"],
invoice_value=data["invoice_value"],
suggested_nature_id=nature.id,
suggested_ledger_name=learned_ledger or "",
suggested_confidence=int(confidence),
suggestion_reason=reason,
review_status="suggested" if confidence >= 60 else "review_required",
@@ -421,4 +438,17 @@ def review_sales(
db.add(row)
db.commit()
db.refresh(row)
save_review_mapping(
db,
tenant_id=tenant_id,
client_id=client_id,
customer_name=row.customer_name,
customer_gstin=row.customer_gstin,
nature_id=row.final_nature_id,
sales_ledger_name=row.final_ledger_name,
user_id=user_id,
amount=row.invoice_value,
invoice_date=row.invoice_date,
)
return row