feat: add autonomous fiscal completion v1

This commit is contained in:
gti
2026-09-22 13:08:38 -03:00
parent eada0df37e
commit e3ac68c70e
28 changed files with 44630 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
"""Conservative deterministic role, ST, and inbound scope resolution."""
def resolve_product_role(signals: dict) -> dict:
if signals.get("recipe") and signals.get("production"):
return {"value": "OWN_PRODUCTION", "status": "CONFIRMED", "evidence": ["recipe", "production"]}
if signals.get("purchase") and signals.get("sale") and not signals.get("recipe"):
return {"value": "RESALE", "status": "CONFIRMED", "evidence": ["purchase", "sale"]}
if signals.get("input_consumed") and signals.get("recipe"):
return {"value": "INPUT", "status": "CONFIRMED", "evidence": ["input_consumed", "recipe"]}
if signals.get("service_flag") and signals.get("service_transactions"):
return {"value": "SERVICE", "status": "CONFIRMED", "evidence": ["service_flag", "service_transactions"]}
return {"value": None, "status": "PENDING_PRODUCT_ROLE", "evidence": []}
def resolve_st_status(signals: dict) -> dict:
if not signals.get("official_cest"):
return {"value": "NOT_SUBJECT_TO_ST", "status": "CONFIRMED", "evidence": []}
if signals.get("purchase_retained") is True:
return {"value": "ST_ALREADY_WITHHELD_IN_PURCHASE", "status": "CONFIRMED", "evidence": ["official_cest", "purchase_retained"]}
if signals.get("purchase_retained") is False:
return {"value": "PRODUCT_SUBJECT_TO_ST", "status": "CONFIRMED", "evidence": ["official_cest", "purchase_not_retained"]}
return {"value": None, "status": "PENDING_ST_WITHHELD", "evidence": ["official_cest"]}
def resolve_entry_scope(supplier_ufs: list[str], company_uf: str) -> dict:
observed = {str(uf).strip().upper() for uf in supplier_ufs if uf}
if not observed:
return {"value": None, "status": "PENDING_ENTRY_SCOPE", "evidence": []}
if len(observed - {company_uf.upper()}) and company_uf.upper() in observed:
value = "MIXED_OR_DYNAMIC"
elif observed - {company_uf.upper()}:
value = "INTER"
else:
value = "INTRA"
return {"value": value, "status": "CONFIRMED", "evidence": sorted(observed)}