feat: Enhance Pedimentos creation and validation logic in frontend and backend

This commit is contained in:
2025-11-12 10:42:15 -06:00
parent a5c1bab201
commit 67a309912c
6 changed files with 223 additions and 75 deletions

View File

@@ -39,7 +39,16 @@ class PedimentosBase(BaseModel):
class PedimentosCreate(PedimentosBase):
"""Schema for creating a new Pedimento"""
pass
# Override to make required fields non-optional
year: str = Field(..., max_length=2, description="Year")
customs_office: str = Field(..., max_length=2, description="Customs office")
license: str = Field(..., max_length=4, description="License")
pedimento_number: str = Field(..., max_length=7, description="Pedimento number")
client_id: int = Field(..., description="Client ID")
operation_type: int = Field(..., description="Operation type")
pedimento_type: int = Field(..., description="Pedimento type")
regime: str = Field(..., max_length=3, description="Regime")
status: str = Field(..., max_length=30, description="Status")
class PedimentosUpdate(BaseModel):

View File

@@ -14,7 +14,7 @@ router = TenantCRUDRoutes(
update_schema=PedimentosUpdate,
response_schema=PedimentosResponse,
prefix="", # No prefix here, will be added in main router
tags=[],
tags=["a76 / pedimentos"], # Tag for Swagger documentation
resource_name="Pedimento",
id_name="pedimento_id",
enable_list=True, # Enable GET / with pagination

View File

@@ -55,7 +55,7 @@ class PedimentosService:
@staticmethod
def get_by_id(
db: Session, pedimento_id: int, tenant_id: int
db: Session, pedimento_id: int, tenant_id: int, company_id: int = None
) -> Optional[Pedimentos]:
"""
Get a pedimento by ID
@@ -64,19 +64,23 @@ class PedimentosService:
db: Database session
pedimento_id: Pedimento ID
tenant_id: Tenant ID
company_id: Company ID (optional for backwards compatibility)
Returns:
Pedimento or None if not found
"""
return (
db.query(Pedimentos)
.filter(Pedimentos.id == pedimento_id, Pedimentos.tenant_id == tenant_id)
.first()
query = db.query(Pedimentos).filter(
Pedimentos.id == pedimento_id, Pedimentos.tenant_id == tenant_id
)
if company_id is not None:
query = query.filter(Pedimentos.company_id == company_id)
return query.first()
@staticmethod
def create(
db: Session, pedimento_data: PedimentosCreate, tenant_id: int
db: Session, pedimento_data: PedimentosCreate, tenant_id: int, company_id: int
) -> Pedimentos:
"""
Create a new pedimento
@@ -84,12 +88,15 @@ class PedimentosService:
Args:
db: Database session
pedimento_data: Pedimento creation data
tenant_id: Tenant ID
company_id: Company ID
Returns:
Created pedimento
"""
pedimento = Pedimentos(**pedimento_data.model_dump())
pedimento.tenant_id = 1
pedimento.tenant_id = tenant_id
pedimento.company_id = company_id
db.add(pedimento)
db.commit()
@@ -98,7 +105,7 @@ class PedimentosService:
@staticmethod
def update(
db: Session, pedimento_id: int, tenant_id: int, pedimento_data: PedimentosUpdate
db: Session, pedimento_id: int, tenant_id: int, pedimento_data: PedimentosUpdate, company_id: int = None
) -> Optional[Pedimentos]:
"""
Update a pedimento
@@ -108,11 +115,12 @@ class PedimentosService:
pedimento_id: Pedimento ID
tenant_id: Tenant ID
pedimento_data: Updated data
company_id: Company ID (optional for backwards compatibility)
Returns:
Updated pedimento or None if not found
"""
pedimento = PedimentosService.get_by_id(db, pedimento_id, tenant_id)
pedimento = PedimentosService.get_by_id(db, pedimento_id, tenant_id, company_id)
if not pedimento:
return None
@@ -125,7 +133,7 @@ class PedimentosService:
return pedimento
@staticmethod
def delete(db: Session, pedimento_id: int, tenant_id: int) -> bool:
def delete(db: Session, pedimento_id: int, tenant_id: int, company_id: int = None) -> bool:
"""
Delete a pedimento
@@ -133,14 +141,17 @@ class PedimentosService:
db: Database session
pedimento_id: Pedimento ID
tenant_id: Tenant ID
company_id: Company ID (optional for backwards compatibility)
Returns:
True if deleted, False if not found
"""
pedimento = PedimentosService.get_by_id(db, pedimento_id, tenant_id)
pedimento = PedimentosService.get_by_id(db, pedimento_id, tenant_id, company_id)
if not pedimento:
return False
db.delete(pedimento)
db.commit()
return True
db.commit()
return True