Implement document reconciliation v2
This commit is contained in:
@@ -97,9 +97,13 @@ class OpportunityEvidence:
|
||||
def _find_doc(docs: list[dict[str, Any]], kinds: set[str]) -> dict[str, Any] | None:
|
||||
for doc in docs:
|
||||
kind = _s(doc.get("document_kind") or doc.get("kind") or doc.get("type")).lower()
|
||||
role = _s(doc.get("role") or "current").lower()
|
||||
active = doc.get("is_active", True)
|
||||
if kind in kinds and role in {"current", "accepted", "historical", "history"} and active is not False:
|
||||
# Service DTOs always carry relationship in v2. The final default is
|
||||
# retained only for old callers/tests constructing a bare document DTO;
|
||||
# database resolution never reads legacy role as authority.
|
||||
relationship = _s(doc.get("relationship") or doc.get("role") or "PRIMARY").upper()
|
||||
if "relationship" not in doc and relationship in {"CURRENT", "ACCEPTED"}:
|
||||
relationship = "PRIMARY" # compatibility for pre-v2 in-memory DTOs only
|
||||
if kind in kinds and relationship == "PRIMARY" and _s(doc.get("status")).upper() not in {"CANCELLED", "CANCELED"}:
|
||||
return doc
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user