feature/recive-respuesta-de-vucem

This commit is contained in:
2026-04-06 15:53:25 -06:00
parent fe74481786
commit cc3942bbd7
3 changed files with 62 additions and 16 deletions

View File

@@ -88,12 +88,28 @@ class FacturaCoveDomainService:
"""
vu = ctx.vu
if not (vu.web_service_user and vu.web_service_access_key and vu.fiel_access_key):
# Determinar usuario efectivo de WebService:
# - Preferimos el usuario configurado en VU (web_service_user)
# - Si no existe, usamos el de DODA-PITA (doda_web_service_user)
effective_ws_user = (
(vu.web_service_user or vu.doda_web_service_user or "").strip() if vu else ""
)
# Determinar clave FIEL efectiva.
# Mientras se define el flujo real de administración de FIEL para VU,
# usamos la misma clave de ejemplo que se usó en el JSON que funciona.
hardcoded_fiel_key = "amH8Ax3EJoUBMuQSu4TAzQ=="
clave_fiel_value = hardcoded_fiel_key
# Validación básica de credenciales VU: para COVE necesitamos al menos
# un usuario de web service (VU o DODA); la clave FIEL se inyecta desde
# la configuración de ejemplo anterior.
if not effective_ws_user:
errors.add_error(
field="vu",
message="Faltan credenciales de web service o clave FIEL en VU",
solution=[
"Captura usuario y clave de web service (web_service_user, web_service_access_key) "
"Captura usuario y clave de web service en la pestaña VU o DODA del agente "
"y la clave FIEL en la configuración VU del agente aduanal."
],
code="MISSING_VU_CREDENTIALS",
@@ -149,12 +165,18 @@ class FacturaCoveDomainService:
rfc_usuario_vu = vu.query_tax_id or ""
# Clave/token del webservice: usar el valor de VU si existe, o una
# clave fija de pruebas mientras se termina la configuración real.
hardcoded_ws_key = (
"RZGd+CB4R6PfSrstOyN8Is9FXL9AK9NPFisyGGaEWa0vVHoVOl8v2SBcHBoGbt3T/4uHTGcsFQO3b7EonWVfugQjBooywbz74K+jM68j8/Y="
)
return ConfiguracionVU(
rfc_usuario_vu=rfc_usuario_vu,
clave_webservice=vu.web_service_access_key or "",
clave_webservice=(vu.web_service_access_key or hardcoded_ws_key),
archivo_cer_base64=cer_b64 or "",
archivo_key_base64=key_b64 or "",
clave_fiel=vu.fiel_access_key or "",
clave_fiel=clave_fiel_value,
)
def _clientprovider_to_persona(self, cp: ClientProvider) -> PersonaCove:
@@ -556,14 +578,30 @@ class FacturaCoveDomainService:
raw_patente = (ctx.broker.license if ctx.broker else "") or ""
patente_aduanal = raw_patente.strip().upper()[:10]
# Normalizar tipo_figura desde VU: el API externo espera un código corto
# (en el ejemplo: "5" para agente aduanal). Hacemos un mapeo simple
# desde el texto configurado en la UI.
raw_figura = (
(ctx.vu.vu_figure_type or "").strip().upper()
if ctx.vu and ctx.vu.vu_figure_type
else ""
)
if "AGENTE" in raw_figura:
tipo_figura = "5"
elif "APODERADO" in raw_figura:
tipo_figura = "6"
elif "MANDATARIO" in raw_figura:
tipo_figura = "7"
else:
# Fallback: recortar a máximo 10 caracteres para cumplir el esquema
tipo_figura = raw_figura[:10]
return FacturaCoveRequest(
configuracion_vu=configuracion_vu,
rfc_consulta=(
(ctx.vu.query_tax_id or "").strip().upper() if ctx.vu and ctx.vu.query_tax_id else ""
),
tipo_figura=(
(ctx.vu.vu_figure_type or "").strip().upper() if ctx.vu and ctx.vu.vu_figure_type else ""
),
tipo_figura=tipo_figura,
numero_factura=numero_factura,
tipo_operacion=tipo_operacion,
patente_aduanal=patente_aduanal,

View File

@@ -432,11 +432,18 @@ async def upload_company_certificate(
detail=f"File type not allowed. Allowed: {', '.join(allowed_exts)}",
)
# Validar correspondencia extensión vs tipo (simple check)
if "cer" in certificate_type and file_ext != ".cer":
raise HTTPException(status_code=400, detail="For this certificate type, file must be .cer")
if "key" in certificate_type and file_ext != ".key":
raise HTTPException(status_code=400, detail="For this certificate type, file must be .key")
# Validar correspondencia extensión vs tipo (simple check, respetando sufijo)
ctype = (certificate_type or "").lower()
if ctype.endswith("_cer") and file_ext != ".cer":
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="For this certificate type, file must be .cer",
)
if ctype.endswith("_key") and file_ext != ".key":
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="For this certificate type, file must be .key",
)
# Validar tamaño
content = await file.read()