mirror of
https://github.com/hoshikawa2/first_contas.git
synced 2026-07-10 02:34:20 +00:00
first commit
This commit is contained in:
78
legacy_reference/workflows/actions/vas_avulso/helpers.py
Normal file
78
legacy_reference/workflows/actions/vas_avulso/helpers.py
Normal file
@@ -0,0 +1,78 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
from agente_contas_tim.workflows.actions.common.helpers import (
|
||||
_extract_amount,
|
||||
_extract_boleto_code,
|
||||
_to_dict,
|
||||
)
|
||||
|
||||
def _empty_cancel_result(
|
||||
msisdn: str,
|
||||
*,
|
||||
mensagem: str,
|
||||
nao_encontrados: list[dict[str, str]] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
return {
|
||||
"success": False,
|
||||
"mensagem": mensagem,
|
||||
"resumo_agente": (
|
||||
"Contestacao VAS avulso concluida. "
|
||||
f"Telefone: {msisdn}. "
|
||||
"SMS enviado: nao. "
|
||||
"Servicos cancelados: nenhum. "
|
||||
"Total dos servicos cancelados: R$ 0,00."
|
||||
),
|
||||
"msisdn": msisdn,
|
||||
"cancelados": [],
|
||||
"erros": [],
|
||||
"nao_encontrados": nao_encontrados or [],
|
||||
"prompt_signals": {
|
||||
"sms_enviado": False,
|
||||
"servicos_com_sms": [],
|
||||
"servicos_com_credito_fatura": [],
|
||||
"tipos_fatura_por_servico": {},
|
||||
"boletos_por_servico": {},
|
||||
"data_credito_por_servico": {},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def _build_active_services(raw_services: Any) -> dict[str, dict[str, Any]]:
|
||||
active: dict[str, dict[str, Any]] = {}
|
||||
if not isinstance(raw_services, (list, tuple)):
|
||||
return active
|
||||
for raw_service in raw_services:
|
||||
service_dict = _to_dict(raw_service)
|
||||
service_name = str(service_dict.get("service_name", "") or "")
|
||||
app_id = str(service_dict.get("app_id", "") or "")
|
||||
extra = service_dict.get("extra", {}) or {}
|
||||
if service_name and app_id:
|
||||
active[service_name.lower()] = {
|
||||
"service_name": service_name,
|
||||
"app_id": app_id,
|
||||
"valor": _extract_amount(extra),
|
||||
"codigo_boleto": _extract_boleto_code(extra),
|
||||
"service_context": service_dict,
|
||||
}
|
||||
return active
|
||||
|
||||
|
||||
def _service_can_be_canceled(matched_service: dict[str, Any]) -> bool:
|
||||
context = matched_service.get("service_context", {})
|
||||
if not isinstance(context, dict):
|
||||
return False
|
||||
extra = context.get("extra", {})
|
||||
if not isinstance(extra, dict):
|
||||
return False
|
||||
can = extra.get("can", {})
|
||||
if not isinstance(can, dict):
|
||||
return False
|
||||
return can.get("cancel") is True
|
||||
|
||||
|
||||
__all__ = [
|
||||
'_empty_cancel_result',
|
||||
'_build_active_services',
|
||||
'_service_can_be_canceled',
|
||||
]
|
||||
Reference in New Issue
Block a user