fix(opportunity-flow): separate quote creation from quote sending
This commit is contained in:
@@ -609,7 +609,36 @@ async def create_quotation_for_opportunity(opportunity_id: str) -> Dict[str, Any
|
||||
except Exception:
|
||||
# operation_links é compatibilidade visual; não deve falhar o fluxo principal.
|
||||
pass
|
||||
set_opportunity_stage(opportunity_id, "QUOTE_SENT", note="Orçamento Jasmin criado via ClientFlow.", created_by="jasmin_service")
|
||||
# Criar o documento no Jasmin não significa que foi enviado ao cliente.
|
||||
# Mantemos o estágio de pedido até a ação SEND_QUOTE ser concluída.
|
||||
set_opportunity_stage(
|
||||
opportunity_id,
|
||||
"QUOTE_REQUESTED",
|
||||
note="Orçamento criado no Jasmin; falta enviar ao cliente.",
|
||||
created_by="jasmin_service",
|
||||
)
|
||||
|
||||
# Materializar a próxima obrigação humana usando o mecanismo central,
|
||||
# preservando idempotência, route, prioridade e ligação à oportunidade.
|
||||
try:
|
||||
from app.opportunity_next_action_service import get_opportunity_next_action
|
||||
from app.opportunity_action_task_materializer import ensure_pending_task_for_next_action
|
||||
|
||||
ensure_pending_task_for_next_action(
|
||||
opportunity_id,
|
||||
get_opportunity_next_action(opportunity_id),
|
||||
source="jasmin_quotation_created",
|
||||
actor="jasmin_service",
|
||||
)
|
||||
except Exception as exc:
|
||||
# O orçamento Jasmin já foi criado com sucesso. Uma falha de
|
||||
# materialização não pode duplicar/reverter a criação externa.
|
||||
print(
|
||||
f"ClientFlow SEND_QUOTE materialization failed for opportunity "
|
||||
f"{opportunity_id}: {exc}",
|
||||
flush=True,
|
||||
)
|
||||
|
||||
return {"customer": customer, "quotation": doc, "quotation_id": quotation_id, "payload": payload}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user