fix: align opportunity UI with canonical current action

This commit is contained in:
plx
2026-08-15 09:47:19 +00:00
parent ee8e2de606
commit 47f21888f9
5 changed files with 366 additions and 12 deletions

View File

@@ -1724,13 +1724,12 @@ def _opportunity_card_next_action(opp: dict) -> str:
if reconstructed_review_required(metadata):
return "Validar processo reconstruído"
pending_code = canonical_action_code(opp.get("pending_primary_action_code"))
if pending_code:
return str(opp.get("pending_primary_action") or primary_action_label(pending_code, fallback="Ver tarefa pendente"))
central = _central_next_action_for_card(opp)
if central.get("label"):
return str(central.get("label") or "")
pending_code = canonical_action_code(opp.get("pending_primary_action_code"))
if pending_code:
return str(opp.get("pending_primary_action") or primary_action_label(pending_code, fallback="Ver tarefa pendente"))
if int(opp.get("pending_task_count") or 0) > 0:
action_code = str(opp.get("last_action_code") or "").strip()
return primary_action_label(action_code, fallback="Ver tarefa pendente")
@@ -1765,9 +1764,9 @@ def _opportunity_board_column_for_opportunity(opp: dict) -> str:
if reconstructed_review_required(metadata):
return "requests"
pending_code = canonical_action_code(opp.get("pending_primary_action_code"))
central_code = canonical_action_code(_central_next_action_for_card(opp).get("action_code"))
effective_code = pending_code or central_code
pending_code = canonical_action_code(opp.get("pending_primary_action_code"))
effective_code = central_code or pending_code
if effective_code in {"SEND_INVOICE", "SEND_PROFORMA", "CONFIRM_PAYMENT", "FOLLOW_UP_PAYMENT"}:
return "payment"
@@ -1776,7 +1775,11 @@ def _opportunity_board_column_for_opportunity(opp: dict) -> str:
"CLOSE_OPPORTUNITY", "VALIDATE_PHYSICAL_ORDER",
}:
return "operations"
if effective_code in {"ASSOCIATE_OPPORTUNITY", "REVIEW_ASSOCIATION", "LINK_DOCUMENT", "REVIEW_RECONSTRUCTED_PROCESS"}:
if effective_code in {
"ASSOCIATE_OPPORTUNITY", "REVIEW_ASSOCIATION", "LINK_DOCUMENT",
"REVIEW_RECONSTRUCTED_PROCESS", "RECONCILE_DOCUMENTS",
"VALIDATE_FISCAL_CUSTOMER",
}:
return "requests"
return _opportunity_board_column_for_stage(opp.get("stage"))
@@ -2081,7 +2084,7 @@ async def opportunity_detail_page(opportunity_id: str, notice: Optional[str] = N
"target_url": f"/tasks/{review_task.get('id')}" if review_task else f"/opportunities/{opportunity_id}",
"source": "explicit_reconstructed_review",
}
elif not lifecycle_override and next_task:
elif not lifecycle_override and not next_action and next_task:
next_action = {
"action_code": str(next_task.get("action_code") or "REVIEW_MANUALLY"),
"label": str(next_task.get("action") or primary_action_label(next_task.get("action_code"))),
@@ -2103,7 +2106,7 @@ async def opportunity_detail_page(opportunity_id: str, notice: Optional[str] = N
primary_action = next_action.get("label") or action_label(next_action.get("action_code"))
primary_note = _safe_opportunity_task_text(next_action.get("description") or "Continuar a próxima ação recomendada.")
action_code_upper = str(next_action.get("action_code") or "").upper()
target_url = next_action.get("target_url") or (f"/tasks/{next_task.get('id')}" if next_task else "/tasks?status=pending")
target_url = next_action.get("target_url") or f"/opportunities/{opportunity_id}"
if str(target_url).startswith("/tasks/") and "return_to=" not in str(target_url):
sep = "&" if "?" in str(target_url) else "?"
target_url = f"{target_url}{sep}return_to={quote(opportunity_return_to, safe='')}"