Merge branch 'feature/table-invoice' into feature/API-COBE
This commit is contained in:
@@ -3,9 +3,10 @@ Service layer for Pedimentos CRUD operations
|
||||
"""
|
||||
|
||||
import logging
|
||||
import re
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from sqlalchemy import desc
|
||||
from sqlalchemy import desc, func
|
||||
from sqlalchemy.orm import Session, joinedload
|
||||
from sqlalchemy.orm import selectinload
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
@@ -95,10 +96,21 @@ class PedimentosService:
|
||||
if filters.get("status"):
|
||||
query = query.filter(Pedimentos.status == filters["status"])
|
||||
if filters.get("client_id"):
|
||||
query = query.filter(
|
||||
Pedimentos.client_id == filters["client_id"])
|
||||
query = query.filter(Pedimentos.client_id == filters["client_id"])
|
||||
if filters.get("year"):
|
||||
query = query.filter(Pedimentos.year == filters["year"])
|
||||
if filters.get("pedimento"):
|
||||
raw_value = str(filters["pedimento"])
|
||||
# Normalizar: dejar solo dígitos (ignorar guiones, espacios, etc.)
|
||||
normalized = re.sub(r"\D", "", raw_value)
|
||||
if normalized:
|
||||
ped_key_expr = func.concat(
|
||||
func.coalesce(Pedimentos.year, ""),
|
||||
func.coalesce(func.substr(Pedimentos.customs_office, 1, 2), ""),
|
||||
func.coalesce(Pedimentos.license, ""),
|
||||
func.coalesce(Pedimentos.pedimento_number, ""),
|
||||
)
|
||||
query = query.filter(ped_key_expr.ilike(f"%{normalized}%"))
|
||||
|
||||
total = query.count()
|
||||
|
||||
|
||||
@@ -15,11 +15,22 @@ router = APIRouter(prefix="/incoterms")
|
||||
async def list_incoterms(
|
||||
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"),
|
||||
code: str = Query(None, description="Filtrar por clave"),
|
||||
description: str = Query(None, description="Filtrar por descripción"),
|
||||
db: Session = Depends(get_core_db),
|
||||
current_user: dict = Depends(get_current_user),
|
||||
):
|
||||
skip = (page - 1) * page_size
|
||||
query = db.query(Incoterm)
|
||||
|
||||
if code:
|
||||
query = query.filter(Incoterm.code.ilike(f"%{code}%"))
|
||||
if description:
|
||||
query = query.filter(
|
||||
(Incoterm.description_es.ilike(f"%{description}%")) |
|
||||
(Incoterm.description_en.ilike(f"%{description}%"))
|
||||
)
|
||||
|
||||
items = query.offset(skip).limit(page_size).all()
|
||||
total = query.count()
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user