feat: Enhance invoice management with operation and invoice type filters, update dialog defaults, and modify routes for improved functionality

This commit is contained in:
2025-12-12 08:44:09 -06:00
parent e5f6162ffb
commit a07aeb7b12
11 changed files with 238 additions and 60 deletions

View File

@@ -8,5 +8,6 @@ class InvoiceTypeDTO(BaseModel):
description: str
note: Optional[str] = None
type: Optional[str] = None
operation: Optional[str] = None
model_config = ConfigDict(from_attributes=True)

View File

@@ -1,4 +1,4 @@
from typing import Any, Dict
from typing import Any, Dict, Optional
from core.database import get_core_db
from core.security import get_current_user, has_role
@@ -11,17 +11,28 @@ from .models import InvoiceType
router = APIRouter(prefix="/invoice-types")
@router.get("/", response_model=Dict[str, Any])
@router.get("/", response_model=dict)
def list_invoice_types(
page: int = Query(1, ge=1, description="Número de página"),
page_size: int = Query(50, ge=1, le=100, description="Tamaño de página"),
page: int = Query(1, ge=1),
page_size: int = Query(50, ge=1, le=100),
type: Optional[str] = Query(None, description="Filter by type"),
operation: Optional[str] = Query(None, description="Filter by operation type (imp, exp, both)"),
db: Session = Depends(get_core_db),
current_user: dict = Depends(get_current_user),
):
skip = (page - 1) * page_size
query = db.query(InvoiceType)
items = query.offset(skip).limit(page_size).all()
# Filter by operation if provided
if operation:
query = query.filter(
(InvoiceType.operation == operation) | (
InvoiceType.operation == "both")
)
if type == "imp" and operation == "CR":
query = query.filter(InvoiceType.operation != "exp")
total = query.count()
items = query.offset((page - 1) * page_size).limit(page_size).all()
return {
"items": [InvoiceTypeDTO.model_validate(obj) for obj in items],
"total": total,

View File

@@ -30,47 +30,47 @@ seed = [
),
# === TIPOS DE EXPORTACION ===
("DONAC", "DONACION", "", "both", "both"),
("EXDEF", "EXPORTACION DEFINITIVA", "", "material", "both"),
("DONAC", "DONACION", "", "both", "exp"),
("EXDEF", "EXPORTACION DEFINITIVA", "", "material", "exp"),
(
"MATDE",
"MATERIA PRIMA O MATERIAL DEVUELTO",
"ESTE PROCESO CONSISTE EN SOLO DESCARGAR LAS PARTES DADAS DE ALTA EN MATERIALES QUE SON RETORNADAS SIN NINGUNA MODIFICACION (A1)",
"material",
"both",
"exp",
),
(
"NODES",
"NO HACE DESCARGA",
"ESTE PROCESO DE ACTUALIZACION CONSISTE EN EXPORTAR UNA MERCANCIA Y NO DESCARGAR, POR LO TANTO NO EXISTE REPORTE DE DESCARGAS Y NO AFECTA SALDOS.",
"both",
"both",
"exp",
),
(
"PTERM",
"PRODUCTO TERMINADO Y VIRTUALES",
"EL PRODUCTO TERMINADO Y VIRTUALES DESCARGARAN: 1) APARTIR DE LOS COMPONENTES DE CADA PRODUCTO TERMINADO REGISTRADO EN LAS PARTIDAS DE EXPORTACION. 2) POR PARTE, CON LAS OPCIONES DE PODER DESCARGAR POR SUSTITUTO Y POR CLASE EN CASO DE INSUFICIENCIAS DEL COMPONENTE.",
"material",
"both",
"exp",
),
(
"REPAR",
"REPARACION",
"PROCESO QUE CONSISTE EN DOS ETAPAS: 1) DESCARGA EL PRODUCTO DE REPARACION QUE SE IMPORTO PARA REPARA, 2) DESCARGA EL LISTADO DE COMPONENTES QUE SE AGREGO AL PRODUCTO DE REPARACION",
"material",
"both",
"exp",
),
("SCRAP", "SCRAP", "", "both", "both"),
("SCRAP", "SCRAP", "", "both", "exp"),
(
"VEMEX",
"VENTAS EN MEXICO",
"ESTE PROCESO CONSISTE EN LA VENTA EN EL MERCADO NACIONAL DE LOS PRODUCTOS.",
"both",
"both",
"exp",
),
("VIRTU", "VIRTUALES", "", "material", "both"),
("VIRTU", "VIRTUALES", "", "material", "exp"),
# === ACTIVOS FIJOS (AMBAS OPERACIONES) ===
("AFIJO", "ACTIVO FIJO", "", "fixed asset", "both"),
("REEXP", "REEXPEDICION", "", "fixed asset", "both"),
("AFIJO", "ACTIVO FIJO", "", "fixed asset", "exp"),
("REEXP", "REEXPEDICION", "", "fixed asset", "exp"),
]