feat: marca Uriel Jareth Consulting, API segura para agentes, aprobacion humana y webhooks HMAC
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import date, datetime
|
||||
import re
|
||||
from datetime import date, datetime, timedelta
|
||||
|
||||
|
||||
IVA_RATE = 0.16
|
||||
@@ -8,11 +9,12 @@ IVA_RATE = 0.16
|
||||
# Tarifa por hora sugerida para partidas personalizadas (Hora Centinela).
|
||||
TARIFA_HORA_DEFAULT = 700
|
||||
|
||||
# Modelos de cobro de una partida (espejo del frontend TS).
|
||||
# Modelos de cobro de una partida (espejo exacto de src/lib/calculators.ts).
|
||||
MODELOS_COBRO: dict[str, str] = {
|
||||
"fijo": "Precio fijo",
|
||||
"horas": "Por horas",
|
||||
"retainer": "Retainer (minimo + adicionales)",
|
||||
"demanda": "Bajo demanda / por hora",
|
||||
}
|
||||
|
||||
# Doble propuesta: cada partida va en la Opcion 1, la 2 o en ambas (espejo del TS).
|
||||
@@ -39,7 +41,7 @@ PLANES_BUCEFALO = [
|
||||
{"nivel": "empresarial", "label": "Empresarial", "precio": 7500},
|
||||
]
|
||||
|
||||
ESTADOS_COTIZACION = ["borrador", "enviada", "aprobada", "rechazada"]
|
||||
ESTADOS_COTIZACION = ["borrador", "aprobada", "enviada", "aceptada", "rechazada", "vencida"]
|
||||
|
||||
FINANCIAMIENTO_PLANES = [
|
||||
{"meses": 3, "tasa": 0.077, "comision": 2.5, "montoMinimo": 300},
|
||||
@@ -58,8 +60,12 @@ BONOS = [
|
||||
]
|
||||
|
||||
|
||||
def _r2(n: float) -> float:
|
||||
return round(n + 1e-12, 2) if n >= 0 else -round(-n + 1e-12, 2)
|
||||
|
||||
|
||||
def calcular_precio_horas(horas: float, tarifa_hora: float) -> float:
|
||||
return round((horas or 0) * (tarifa_hora or 0), 2)
|
||||
return _r2((horas or 0) * (tarifa_hora or 0))
|
||||
|
||||
|
||||
def describir_retainer(monto_minimo: float, horas_incluidas: float, tarifa_hora: float) -> str:
|
||||
@@ -81,6 +87,8 @@ def detalle_modelo(serv: dict) -> str:
|
||||
serv.get("horasIncluidas") or 0,
|
||||
serv.get("tarifaHora") or 0,
|
||||
)
|
||||
if modelo == "demanda":
|
||||
return f"{format_currency(serv.get('tarifaHora') or 0)}/hr · segun consumo"
|
||||
horas = serv.get("horas")
|
||||
tarifa = serv.get("tarifaHora")
|
||||
if (modelo == "horas" or serv.get("esPersonalizado")) and horas and tarifa:
|
||||
@@ -91,20 +99,51 @@ def detalle_modelo(serv: dict) -> str:
|
||||
def calcular_totales_opcion(servicios: list[dict], opcion: str) -> dict:
|
||||
"""Totales de una opcion: suma sus partidas + las marcadas 'ambas'.
|
||||
|
||||
Espejo de calcularTotalesOpcion en TS. Respeta la regla de retainer: el total
|
||||
usa `precio`, no `horas x tarifa`. Las horas son informativas.
|
||||
Espejo exacto de calcularTotalesOpcion en TS. Respeta la regla de retainer:
|
||||
el total usa precio, no horas x tarifa. Las horas son informativas.
|
||||
"""
|
||||
rel = [s for s in servicios if s.get("opcion") == "ambas" or s.get("opcion") == opcion]
|
||||
total_unico = sum((s.get("precio") or 0) for s in rel if s.get("tipoPago") == "unico")
|
||||
total_mensual = sum((s.get("precio") or 0) for s in rel if s.get("tipoPago") == "mensual")
|
||||
horas = sum((s.get("horas") or 0) for s in rel)
|
||||
return {
|
||||
"totalUnico": round(total_unico, 2),
|
||||
"totalMensual": round(total_mensual, 2),
|
||||
"horas": round(horas, 2),
|
||||
"totalUnico": _r2(total_unico),
|
||||
"totalMensual": _r2(total_mensual),
|
||||
"horas": _r2(horas),
|
||||
}
|
||||
|
||||
|
||||
def calcular_totales_cotizacion(
|
||||
servicios: list[dict],
|
||||
incluir_iva: bool = True,
|
||||
) -> dict:
|
||||
"""Espejo exacto de calcularTotalesCotizacion en src/lib/calculators.ts."""
|
||||
activos = [s for s in servicios if s.get("seleccionado", True) is not False]
|
||||
subtotal_unico = _r2(sum((s.get("precio") or 0) for s in activos if s.get("tipoPago") == "unico"))
|
||||
subtotal_mensual = _r2(sum((s.get("precio") or 0) for s in activos if s.get("tipoPago") == "mensual"))
|
||||
|
||||
iva_unico = _r2(subtotal_unico * IVA_RATE) if incluir_iva else 0.0
|
||||
iva_mensual = _r2(subtotal_mensual * IVA_RATE) if incluir_iva else 0.0
|
||||
|
||||
total_unico = _r2(subtotal_unico + iva_unico)
|
||||
total_mensual = _r2(subtotal_mensual + iva_mensual)
|
||||
|
||||
return {
|
||||
"subtotalUnico": subtotal_unico,
|
||||
"subtotalMensual": subtotal_mensual,
|
||||
"ivaUnico": iva_unico,
|
||||
"ivaMensual": iva_mensual,
|
||||
"totalUnico": total_unico,
|
||||
"totalMensual": total_mensual,
|
||||
"totalPrimerAnio": _r2(total_unico + total_mensual * 12),
|
||||
"incluyeIva": incluir_iva,
|
||||
}
|
||||
|
||||
|
||||
def con_iva(monto: float, incluir_iva: bool = True) -> float:
|
||||
return _r2((monto or 0) * (1 + IVA_RATE if incluir_iva else 1))
|
||||
|
||||
|
||||
def bucefalo_precio(nivel: str) -> float:
|
||||
for p in PLANES_BUCEFALO:
|
||||
if p["nivel"] == nivel:
|
||||
@@ -113,32 +152,37 @@ def bucefalo_precio(nivel: str) -> float:
|
||||
|
||||
|
||||
def calcular_vigencia(fecha: datetime | date) -> datetime:
|
||||
"""Suma exactamente 15 dias habiles (lunes a viernes), espejo de calculators.ts."""
|
||||
if isinstance(fecha, datetime):
|
||||
vigencia = fecha.replace()
|
||||
else:
|
||||
vigencia = datetime.combine(fecha, datetime.min.time())
|
||||
dias_habiles = 0
|
||||
while dias_habiles < 15:
|
||||
vigencia = vigencia.replace(day=vigencia.day + 1) if vigencia.day < 28 else vigencia + __import__("datetime").timedelta(days=1)
|
||||
vigencia = vigencia + __import__("datetime").timedelta(days=1)
|
||||
dia = vigencia.weekday()
|
||||
if dia < 5:
|
||||
vigencia = vigencia + timedelta(days=1)
|
||||
if vigencia.weekday() < 5:
|
||||
dias_habiles += 1
|
||||
return vigencia
|
||||
|
||||
|
||||
def calcular_financiamiento(monto: float, meses: int, tasa: float, comision: float, iva: float = IVA_RATE) -> dict:
|
||||
def calcular_financiamiento(
|
||||
monto: float,
|
||||
meses: int,
|
||||
tasa: float,
|
||||
comision: float,
|
||||
iva: float = IVA_RATE,
|
||||
) -> dict:
|
||||
comision_total = (monto * comision) / 100
|
||||
monto_con_comision = monto + comision_total
|
||||
pago_mensual = monto_con_comision * (1 + tasa) / meses
|
||||
iva_mensual = pago_mensual * iva
|
||||
total_mensual = pago_mensual + iva_mensual
|
||||
return {
|
||||
"pagoMensual": round(pago_mensual, 2),
|
||||
"ivaMensual": round(iva_mensual, 2),
|
||||
"totalMensual": round(total_mensual, 2),
|
||||
"comisionTotal": round(comision_total, 2),
|
||||
"granTotal": round(total_mensual * meses, 2),
|
||||
"pagoMensual": _r2(pago_mensual),
|
||||
"ivaMensual": _r2(iva_mensual),
|
||||
"totalMensual": _r2(total_mensual),
|
||||
"comisionTotal": _r2(comision_total),
|
||||
"granTotal": _r2(total_mensual * meses),
|
||||
}
|
||||
|
||||
|
||||
@@ -151,7 +195,6 @@ def generar_numero_cotizacion(iniciales: str, secuencia: int) -> str:
|
||||
|
||||
|
||||
def sanitize_filename(name: str) -> str:
|
||||
import re
|
||||
name = re.sub(r"[^\w\s.\-]", "", name)
|
||||
name = re.sub(r"\s+", " ", name)
|
||||
return name.strip()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""Excel Generator for Cotizador E3 — port of src/lib/excel-builder.ts using openpyxl.
|
||||
"""Excel Generator for Cotizador — Uriel Jareth Consulting — port of src/lib/excel-builder.ts using openpyxl.
|
||||
|
||||
Mantiene paridad de layout con el builder de TypeScript: mismas columnas, merges,
|
||||
celdas dinámicas (wrapText + altura calculada) para que el texto nunca se salga.
|
||||
@@ -94,10 +94,10 @@ def generate_cotizacion_excel(data: dict[str, Any], saved: bool = False) -> byte
|
||||
data: dict with quotation data (same as PDF generator)
|
||||
saved: if True, uses real quotation number instead of "BORRADOR"
|
||||
"""
|
||||
config_color = data.get("colorPrimario", "#2563eb")
|
||||
config_color = data.get("colorPrimario") or "#0400C4"
|
||||
PRIMARY = _argb(config_color)
|
||||
PRIMARY_LIGHT = _argb(config_color, alpha="18")
|
||||
SECONDARY = _argb(data.get("colorSecundario", "#1e293b"))
|
||||
SECONDARY = _argb(data.get("colorSecundario") or "#0F172A")
|
||||
WHITE = "FFFFFFFF"
|
||||
LIGHT_BG = "FFF8FAFC"
|
||||
MUTED = "FF64748B"
|
||||
@@ -118,8 +118,7 @@ def generate_cotizacion_excel(data: dict[str, Any], saved: bool = False) -> byte
|
||||
light_fill = PatternFill(start_color=LIGHT_BG, end_color=LIGHT_BG, fill_type="solid")
|
||||
white_fill = PatternFill(start_color=WHITE, end_color=WHITE, fill_type="solid")
|
||||
|
||||
razon_social = data.get("razonSocial", "Cotizador E3")
|
||||
domicilio_fiscal = data.get("domicilioFiscal")
|
||||
razon_social = data.get("razonSocial") or "Uriel Jareth Consulting"
|
||||
cliente_nombre = data.get("clienteNombre", "")
|
||||
cliente_empresa = data.get("clienteEmpresa", "")
|
||||
asesor_nombre = data.get("asesorNombre", "")
|
||||
@@ -135,7 +134,7 @@ def generate_cotizacion_excel(data: dict[str, Any], saved: bool = False) -> byte
|
||||
numero_label = data.get("numero", "BORRADOR") if saved else "BORRADOR"
|
||||
|
||||
wb = Workbook()
|
||||
wb.properties.creator = "Cotizador E3"
|
||||
wb.properties.creator = "Cotizador — Uriel Jareth Consulting"
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
# HOJA RESUMEN
|
||||
@@ -525,12 +524,7 @@ def generate_cotizacion_excel(data: dict[str, Any], saved: bool = False) -> byte
|
||||
dw.merge_cells(f"B{r}:J{r}")
|
||||
dw[f"B{r}"].value = razon_social
|
||||
dw[f"B{r}"].font = Font(bold=True, size=10, name="Calibri", color=PRIMARY)
|
||||
if domicilio_fiscal:
|
||||
r += 1
|
||||
dw.merge_cells(f"B{r}:J{r}")
|
||||
dw[f"B{r}"].value = domicilio_fiscal
|
||||
dw[f"B{r}"].font = iva_font
|
||||
_set_wrapped(dw, r, "B", domicilio_fiscal, ent_width, font_size=9)
|
||||
# Decision de marca: no imprimir domicilio fiscal ni ciudad en documentos generados.
|
||||
|
||||
output = io.BytesIO()
|
||||
wb.save(output)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""PDF Generator for Cotizador E3 — port of pdf-generator.ts using ReportLab."""
|
||||
"""PDF Generator for Cotizador — Uriel Jareth Consulting — port of pdf-generator.ts using ReportLab."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -15,8 +15,8 @@ from reportlab.lib.utils import ImageReader
|
||||
|
||||
from app.services.calculators import FASES_SHORT, PLANES_BUCEFALO, bucefalo_precio, detalle_modelo, calcular_totales_opcion
|
||||
|
||||
PRIMARY_DEFAULT = "#2563eb"
|
||||
DARK_DEFAULT = "#1e293b"
|
||||
PRIMARY_DEFAULT = "#0400C4"
|
||||
DARK_DEFAULT = "#0F172A"
|
||||
MUTED = "#64748b"
|
||||
BORDER = "#cbd5e1"
|
||||
LIGHT_BG = "#f1f5f9"
|
||||
|
||||
Reference in New Issue
Block a user