feat: calculate real discount % from TARIFA vs RELACION.PRECIO
Joins TARIFA using EMPRESA.TARIFA to get the base price per exam, then calculates descuento = round((sum(TARIFA) - sum(PRECIO)) / sum(TARIFA) * 100) and sends it as integer percentage in the RDA header encabezado. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
15f6ca65db
commit
72973973d4
@@ -123,6 +123,14 @@ def agrupar_por_recepcion(rows: list) -> dict:
|
||||
return grupos
|
||||
|
||||
|
||||
def _calcular_descuento_pct(rows: list) -> int:
|
||||
total_cobrado = sum(float(r.get("PRECIO") or 0) for r in rows)
|
||||
total_tarifa = sum(float(r.get("PRECIO_TARIFA") or r.get("PRECIO") or 0) for r in rows)
|
||||
if total_tarifa > 0 and total_tarifa > total_cobrado:
|
||||
return round((total_tarifa - total_cobrado) / total_tarifa * 100)
|
||||
return 0
|
||||
|
||||
|
||||
def generar_rda_paciente(rows: list, default_profesional: str = "", default_especialidad: str = "",
|
||||
default_remisionante: str = "00", default_prefijo: str = "00",
|
||||
numero_override: str = "") -> dict:
|
||||
@@ -220,7 +228,7 @@ def generar_rda_paciente(rows: list, default_profesional: str = "", default_espe
|
||||
"numeroAutorizacion": autorizacion,
|
||||
"fechaAutorizacion": date.today().strftime("%d/%m/%Y"),
|
||||
"vigenciaAutorizacion": vigencia,
|
||||
"descuento": int(float(h.get("VALORDESC") or 0)),
|
||||
"descuento": _calcular_descuento_pct(rows),
|
||||
"detallePedido": detalle_pedido,
|
||||
"detalleFormaPago": [{
|
||||
"codigoFormaPago": cod_forma_pago,
|
||||
|
||||
Reference in New Issue
Block a user