feat(cotizador): 'depósito en garantía' se lee como renta anticipada
Las cotizaciones viejas usan 'DEPÓSITO EN GARANTÍA' para el mismo concepto que la renta anticipada. Ahora se toma ese valor como renta_anticipada cuando aplica. - Visión (ruta principal de imágenes): sinónimo agregado al prompt. - Texto: helper _leer_renta_anticipada — si no hay 'RENTA ANTICIPADA', usa 'DEPÓSITO EN GARANTÍA' (tokens DEP/GARANT toleran acentos). RENTA ANTICIPADA tiene precedencia; el blindaje contra 'TOMA A CUENTA RENTA ANTICIPADA' se mantiene. Aditivo, sin regresión. NO toca calculator.py. 95 tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
1dcd21f264
commit
f57c61c823
3 files changed
+47
-5
No files matched your search
@@ -66,6 +66,20 @@ def _buscar_por_tokens_excl(tabla: dict[str, str], tokens: list[str],
|
||||
return ""
|
||||
|
||||
|
||||
def _leer_renta_anticipada(tabla: dict[str, str]) -> float:
|
||||
"""Renta anticipada del documento.
|
||||
|
||||
- Blindado contra 'TOMA A CUENTA RENTA ANTICIPADA' (colisión de tokens).
|
||||
- Fallback: las cotizaciones VIEJAS usan 'DEPÓSITO EN GARANTÍA' para el mismo
|
||||
concepto → si no hay 'RENTA ANTICIPADA', se toma ese valor. Tokens cortos
|
||||
(DEP/GARANT) para tolerar acentos (DEPÓSITO/GARANTÍA).
|
||||
"""
|
||||
raw = _buscar_por_tokens_excl(tabla, ["RENTA", "ANTICIPADA"], ["TOMA"])
|
||||
if not raw:
|
||||
raw = _buscar_por_tokens(tabla, ["DEP", "GARANT"])
|
||||
return _parse_monto(raw)
|
||||
|
||||
|
||||
def _buscar_alternativas(tabla: dict[str, str], alternativas: list[list[str]]) -> str:
|
||||
"""Prueba múltiples conjuntos de tokens y devuelve el primero que matchee.
|
||||
|
||||
@@ -274,9 +288,7 @@ def extraer_parametros_pdf(base64_str: str) -> dict:
|
||||
|
||||
renta_mensual = _parse_monto(_buscar_por_tokens(tabla, ["RENTA", "MENSUAL"]))
|
||||
comision = _parse_monto(_buscar_por_tokens(tabla, ["COMISION"]))
|
||||
# Blindado: excluye la fila "TOMA A CUENTA RENTA ANTICIPADA" (colisión).
|
||||
renta_anticipada = _parse_monto(
|
||||
_buscar_por_tokens_excl(tabla, ["RENTA", "ANTICIPADA"], ["TOMA"]))
|
||||
renta_anticipada = _leer_renta_anticipada(tabla)
|
||||
# VR: el template viejo usaba "VALOR RESIDUAL TOTAL"; el nuevo usa
|
||||
# "VALOR RESIDUAL ANUAL (dividido en 4 años)". Aceptamos ambos.
|
||||
valor_residual_total = _parse_monto(
|
||||
|
||||
@@ -102,8 +102,9 @@ _SYSTEM = (
|
||||
"- Devuelve los MONTOS como números sin formato (sin $ ni comas): 371033.4\n"
|
||||
"- Si un dato NO se ve con claridad, devuelve valor null y confianza 'baja'. "
|
||||
"NUNCA inventes ni adivines un dígito.\n"
|
||||
"- Sinónimos comunes: 'enganche' o 'pago inicial' = renta_anticipada; "
|
||||
"'VR' = valor residual; 'mensualidad' = renta_mensual; 'apertura' = comision.\n"
|
||||
"- Sinónimos comunes: 'enganche', 'pago inicial' o 'depósito en garantía' "
|
||||
"= renta_anticipada; 'VR' = valor residual; 'mensualidad' = renta_mensual; "
|
||||
"'apertura' = comision.\n"
|
||||
"- valor_residual_total es el VR total; vr_ano_1..5 son los VR por año si el "
|
||||
"documento los desglosa (si no hay desglose por año, déjalos null).\n"
|
||||
"- plazo_meses en MESES. anio es el año-modelo del vehículo. unidades = número "
|
||||
|
||||
@@ -6,9 +6,38 @@ inline anterior.
|
||||
"""
|
||||
from src.services.pdf_extractor import (
|
||||
ensamblar_resultado, _buscar_por_tokens, _buscar_por_tokens_excl, _parse_monto,
|
||||
_leer_renta_anticipada,
|
||||
)
|
||||
|
||||
|
||||
def test_ra_lee_renta_anticipada_normal():
|
||||
tabla = {"RENTA ANTICIPADA": "$32,100.00", "COMISION POR APERTURA": "$7,778.00"}
|
||||
assert _leer_renta_anticipada(tabla) == 32100.0
|
||||
|
||||
|
||||
def test_ra_deposito_en_garantia_como_ra():
|
||||
# Cotización vieja: sin "RENTA ANTICIPADA", con "DEPÓSITO EN GARANTÍA" (acentos).
|
||||
tabla = {"DEPÓSITO EN GARANTÍA": "$32,100.00", "COMISION POR APERTURA": "$7,778.00"}
|
||||
assert _leer_renta_anticipada(tabla) == 32100.0
|
||||
|
||||
|
||||
def test_ra_deposito_sin_acentos_tambien():
|
||||
tabla = {"DEPOSITO EN GARANTIA": "$18,500.00"}
|
||||
assert _leer_renta_anticipada(tabla) == 18500.0
|
||||
|
||||
|
||||
def test_ra_renta_anticipada_tiene_precedencia_sobre_deposito():
|
||||
# Si aparecen ambos, gana RENTA ANTICIPADA.
|
||||
tabla = {"RENTA ANTICIPADA": "$40,000.00", "DEPÓSITO EN GARANTÍA": "$5,000.00"}
|
||||
assert _leer_renta_anticipada(tabla) == 40000.0
|
||||
|
||||
|
||||
def test_ra_blindaje_toma_no_confunde_con_deposito():
|
||||
# Solo la fila de toma → no es RA (ni depósito) → 0.
|
||||
tabla = {"TOMA A CUENTA RENTA ANTICIPADA": "$100,000.00"}
|
||||
assert _leer_renta_anticipada(tabla) == 0.0
|
||||
|
||||
|
||||
def test_blindaje_renta_anticipada_vs_toma():
|
||||
# La fila TOMA aparece PRIMERO: sin blindaje, la RA agarraría 235,200.
|
||||
tabla = {
|
||||
|
||||
Reference in new issue
Block a user