feat: fix R1 pedimento duplication and improve invoice report exports

- Fix bidirectional R1 resolution in all report query builders (Temporary,
  Definitive, Repair, Export, ExportRepair): use JOIN on
  pedimento_rectification_origin in both directions so the rectified
  pedimento number is resolved correctly and not duplicated.
- Restore original CSV export format (ValorComercialMN, ValorMPTemp,
  ValorAgre as separate columns); compute them from item_line_financials
  SUM instead of invoice-level header totals which were always 0.
- Rename CSV column "PEDIMENTO RECTIFICACION" to "PEDIMENTO R1" in both
  backend csv_utils.py and frontend manual download.
- Harden temporary invoice update validator to safely handle null
  compliance_mx / logistics objects without crashing.
- Add R1 rectification fields (es_rectificacion, pedimento_original, etc.)
  to the pedimento other-data form and initialize their default state.
- Remove default companyId parameter from pedimentosApi methods to avoid
  hardcoded company ID 1.
- Minor: whitespace cleanup, error handler adjustments, keyboard manager
  fix.
This commit is contained in:
Galindo97
2026-02-20 10:00:22 -06:00
parent 6088d934f6
commit 7b704e0744
25 changed files with 919 additions and 524 deletions

View File

@@ -91,16 +91,19 @@ async def integrity_error_handler(
},
)
# Intentar extraer información útil del error
error_message = "Error de integridad en la base de datos"
orig_msg = str(exc.orig).lower()
if "unique constraint" in orig_msg or "duplicate key" in orig_msg:
error_message = "El registro ya existe. Verifica los campos únicos."
elif "foreign key" in orig_msg:
error_message = "Referencia inválida a otro registro."
elif "not null" in orig_msg:
error_message = "Falta un campo requerido."
# Check for unique/duplicate key violations (English and Spanish)
if any(kw in orig_msg for kw in ["unique constraint", "duplicate key", "duplicada", "unicidad", "ya existe"]):
error_message = "El registro ya existe. Verifica los campos únicos (Año, Aduana, Patente, Número, etc.)."
# Check for foreign key violations (English and Spanish)
elif any(kw in orig_msg for kw in ["foreign key", "foránea", "referencia"]):
error_message = "Referencia inválida a otro registro. Verifica las categorías y catálogos seleccionados."
# Check for not null violations (English and Spanish)
elif any(kw in orig_msg for kw in ["not null", "no nulo", "valor nulo"]):
error_message = "Falta un campo requerido. Asegúrate de llenar todos los datos obligatorios."
else:
error_message = "Error de integridad en la base de datos"
return JSONResponse(
status_code=status.HTTP_409_CONFLICT,