Mecanismo sort para tablas
This commit is contained in:
@@ -115,6 +115,8 @@ class InvoiceService:
|
||||
skip: int = 0,
|
||||
limit: int = 100,
|
||||
filters: Optional[dict] = None,
|
||||
sort_by: Optional[str] = None,
|
||||
sort_order: Optional[str] = "asc",
|
||||
) -> Tuple[List[models.InvoiceHeader], int]:
|
||||
"""Get all invoices for a tenant/company with pagination and optional filters"""
|
||||
query = db.query(models.InvoiceHeader).filter(
|
||||
@@ -165,6 +167,20 @@ class InvoiceService:
|
||||
models.InvoiceComplianceMx.manifest_number.ilike(f"%{filters['manifest_number']}%")
|
||||
)
|
||||
|
||||
# Apply sorting
|
||||
if sort_by:
|
||||
# Simple column mapping
|
||||
# This can be improved to handle joins if needed
|
||||
column = getattr(models.InvoiceHeader, sort_by, None)
|
||||
if column:
|
||||
if sort_order == "desc":
|
||||
query = query.order_by(column.desc())
|
||||
else:
|
||||
query = query.order_by(column.asc())
|
||||
else:
|
||||
# Default sorting if none provided
|
||||
query = query.order_by(models.InvoiceHeader.id.desc())
|
||||
|
||||
total = query.count()
|
||||
items = query.offset(skip).limit(limit).all()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user