Align client onboarding documents and engagement AQMM workflow

This commit is contained in:
A R R R Associates
2026-07-11 22:20:26 +05:30
parent a9dda197ad
commit c36f419923
4 changed files with 223 additions and 180 deletions
+151 -1
View File
@@ -95,6 +95,144 @@ router = APIRouter(prefix="/documents", tags=["documents-ui"])
logger = logging.getLogger("audit_storage_agent.documents_ui")
def _normalise_document_text(value) -> str:
return re.sub(r"[^a-z0-9]+", " ", str(value or "").lower()).strip()
def _permanent_onboarding_requirements(client) -> list[dict[str, object]]:
"""Return the client-master KYC checklist without creating a second document system."""
constitution = _normalise_document_text(getattr(client, "client_type", ""))
requirements: list[dict[str, object]] = [
{
"code": "pan",
"label": "PAN / Income-tax identity proof",
"categories": {"income tax", "kyc"},
"keywords": {"pan", "income tax"},
},
{
"code": "kyc",
"label": "Authorised person / proprietor KYC",
"categories": {"kyc"},
"keywords": {"kyc", "aadhaar", "aadhar", "identity", "authorised signatory", "authorized signatory"},
},
{
"code": "bank",
"label": "Bank account proof",
"categories": {"bank"},
"keywords": {"bank", "cancelled cheque", "canceled cheque"},
},
]
if getattr(client, "gstin", None):
requirements.append({
"code": "gst",
"label": "GST registration certificate",
"categories": {"gst registration"},
"keywords": {"gst", "gstin"},
})
if "partnership" in constitution:
requirements.append({
"code": "constitution",
"label": "Partnership deed",
"categories": {"agreements", "company registration"},
"keywords": {"partnership deed", "deed"},
})
elif constitution == "llp" or "limited liability partnership" in constitution:
requirements.extend([
{
"code": "registration",
"label": "LLP incorporation / registration certificate",
"categories": {"company registration", "roc master data"},
"keywords": {"llp incorporation", "certificate of incorporation", "incorporation"},
},
{
"code": "constitution",
"label": "LLP agreement",
"categories": {"agreements"},
"keywords": {"llp agreement", "agreement"},
},
])
elif "limited company" in constitution or constitution in {"private limited company", "public limited company"}:
requirements.extend([
{
"code": "registration",
"label": "Certificate of Incorporation",
"categories": {"company registration", "roc master data"},
"keywords": {"certificate of incorporation", "incorporation"},
},
{
"code": "constitution",
"label": "MOA / AOA",
"categories": {"company registration", "agreements", "roc master data"},
"keywords": {"moa", "aoa", "memorandum", "articles of association"},
},
])
elif "trust" in constitution:
requirements.append({
"code": "constitution",
"label": "Trust deed / registration document",
"categories": {"agreements", "company registration", "licenses"},
"keywords": {"trust deed", "trust registration"},
})
elif "society" in constitution:
requirements.extend([
{
"code": "registration",
"label": "Society registration certificate",
"categories": {"company registration", "licenses"},
"keywords": {"society registration", "registration certificate"},
},
{
"code": "constitution",
"label": "Bye-laws / governing document",
"categories": {"agreements"},
"keywords": {"bye laws", "byelaws", "governing document"},
},
])
elif "proprietorship" in constitution:
requirements.append({
"code": "constitution",
"label": "Business constitution / registration proof",
"categories": {"licenses", "company registration", "gst registration"},
"keywords": {"proprietorship", "shop act", "udyam", "business registration"},
})
elif constitution in {"aop", "huf"}:
requirements.append({
"code": "constitution",
"label": "Constitution / formation document",
"categories": {"agreements", "kyc", "company registration"},
"keywords": {"formation", "constitution", "deed", "huf"},
})
return requirements
def _build_permanent_onboarding_checklist(client, documents) -> tuple[list[dict[str, object]], bool]:
haystacks = []
for document in documents or []:
haystacks.append({
"category": _normalise_document_text(getattr(document, "category", "")),
"text": _normalise_document_text(" ".join([
str(getattr(document, "title", "") or ""),
str(getattr(document, "description", "") or ""),
str(getattr(document, "document_code", "") or ""),
])),
})
checklist = []
for requirement in _permanent_onboarding_requirements(client):
category_tokens = {_normalise_document_text(v) for v in requirement["categories"]}
keyword_tokens = {_normalise_document_text(v) for v in requirement["keywords"]}
complete = any(
item["category"] in category_tokens
or any(keyword and keyword in item["text"] for keyword in keyword_tokens)
for item in haystacks
)
checklist.append({**requirement, "complete": complete})
return checklist, all(item["complete"] for item in checklist)
def _base_ctx(request: Request, user, db, **ctx):
base = {
"request": request,
@@ -723,7 +861,19 @@ def permanent_client_documents(request: Request, client_id: int):
if not client or not user_can_view_client_documents(db, user, client, scope):
return _redirect_denied()
documents = list_permanent_documents_for_client(db, client_id)
return _render(request, "modules/documents/templates/documents/permanent_client_documents.html", db, user, title="Permanent Client Documents", client=client, documents=documents, can_upload=user_can_upload_client_documents(db, user, client, scope))
onboarding_checklist, onboarding_complete = _build_permanent_onboarding_checklist(client, documents)
return _render(
request,
"modules/documents/templates/documents/permanent_client_documents.html",
db,
user,
title="Permanent Client Documents",
client=client,
documents=documents,
can_upload=user_can_upload_client_documents(db, user, client, scope),
onboarding_checklist=onboarding_checklist,
onboarding_complete=onboarding_complete,
)
finally:
db.close()