diff --git a/backend/api/v1/modules/a76/customs_brokers/dto.py b/backend/api/v1/modules/a76/customs_brokers/dto.py index fa11b268..7f65b264 100644 --- a/backend/api/v1/modules/a76/customs_brokers/dto.py +++ b/backend/api/v1/modules/a76/customs_brokers/dto.py @@ -1,6 +1,6 @@ from typing import Optional -from pydantic import BaseModel +from pydantic import BaseModel, Field class CustomsBrokerBaseDTO(BaseModel): @@ -19,7 +19,7 @@ class CustomsBrokerBaseDTO(BaseModel): tax_id: Optional[str] = None personal_id: Optional[str] = None position: Optional[str] = None - license: Optional[str] = None + license: Optional[str] = Field(None, max_length=4, pattern=r"^\d*$") company: Optional[str] = None contact: Optional[str] = None @@ -27,7 +27,7 @@ class CustomsBrokerBaseDTO(BaseModel): class CustomsBrokerCreateDTO(CustomsBrokerBaseDTO): """Schema for creating a new CustomsBroker""" - broker_key: str + broker_key: str = Field(..., max_length=5, pattern=r"^[a-zA-Z0-9]+$", description="Clave única del agente aduanal (máx 5 caracteres)") class CustomsBrokerUpdateDTO(CustomsBrokerBaseDTO): @@ -51,7 +51,7 @@ class CustomsBrokerResponseDTO(CustomsBrokerBaseDTO): # Legacy DTO for backwards compatibility (if needed elsewhere) class CustomsBrokerDTO(BaseModel): type: Optional[str] = None - broker_key: str + broker_key: str = Field(..., max_length=5, pattern=r"^[a-zA-Z0-9]+$") name: Optional[str] = None address: Optional[str] = None postal_code: Optional[str] = None @@ -64,7 +64,7 @@ class CustomsBrokerDTO(BaseModel): tax_id: Optional[str] = None personal_id: Optional[str] = None position: Optional[str] = None - license: Optional[str] = None + license: Optional[str] = Field(None, max_length=4, pattern=r"^\d*$") company: Optional[str] = None contact: Optional[str] = None tenant_id: str @@ -100,13 +100,13 @@ class CustomsBrokerVUCreateDTO(BaseModel): class CustomsBrokerPersonnelDTO(BaseModel): - broker_key: str + broker_key: str = Field(..., max_length=5, pattern=r"^[a-zA-Z0-9]+$") line: int name: Optional[str] tax_id: Optional[str] personal_id: Optional[str] position: Optional[str] - license: Optional[str] + license: Optional[str] = Field(None, max_length=4, pattern=r"^\d*$") first_name: Optional[str] last_name: Optional[str] middle_name: Optional[str] diff --git a/frontend/src/lib/components/dashboard/customs_brokers/create-dialog.svelte b/frontend/src/lib/components/dashboard/customs_brokers/create-dialog.svelte index 0b4393ff..44bca734 100644 --- a/frontend/src/lib/components/dashboard/customs_brokers/create-dialog.svelte +++ b/frontend/src/lib/components/dashboard/customs_brokers/create-dialog.svelte @@ -1,221 +1,310 @@ - - - - {mode === "create" ? "Nuevo Agente Aduanal" : "Editar Agente Aduanal"} - - - Ingresa los datos generales del agente. La configuración de VU y Personal se gestiona aparte. - - + + + + {mode === 'create' ? 'Nuevo Agente Aduanal' : 'Editar Agente Aduanal'} + + + Ingresa los datos generales del agente. La configuración de VU y Personal se gestiona + aparte. + + -
- -
-

Identificación

-
-
- - -
-
- - -
-
-
-
- - -
-
- - -
-
- - -
-
-
+
+
+

Identificación

+
+
+ + { + const val = e.currentTarget.value.toUpperCase(); + if (val.length > 5) { + brokerKeyError = true; + formData.broker_key = val.slice(0, 5); + e.currentTarget.value = formData.broker_key; - + clearTimeout(brokerKeyTimeout); + brokerKeyTimeout = setTimeout(() => { + brokerKeyError = false; + }, 3000); + } else { + brokerKeyError = false; + formData.broker_key = val; + } + }} + placeholder="Ej. 550" + maxlength="6" + class={brokerKeyError ? 'border-red-500 focus-visible:ring-red-500' : ''} + disabled={mode === 'edit' || loading} + /> + {#if brokerKeyError} +

+ La clave no debe superar los 5 caracteres +

+ {/if} +
+
+ + { + const val = e.currentTarget.value.replace(/\D/g, ''); + if (val.length > 4) { + licenseError = true; + formData.license = val.slice(0, 4); + e.currentTarget.value = formData.license; -
-

Contacto

-
-
- - -
-
- - -
-
-
+ clearTimeout(licenseTimeout); + licenseTimeout = setTimeout(() => { + licenseError = false; + }, 3000); + } else { + licenseError = false; + formData.license = val; + } + }} + placeholder="Ej. 3421" + maxlength="5" + class={licenseError ? 'border-red-500 focus-visible:ring-red-500' : ''} + disabled={loading} + /> + {#if licenseError} +

+ La patente no debe superar los 4 dígitos +

+ {/if} +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
- + -
-

Dirección Fiscal

- -
- - -
+
+

Contacto

+
+
+ + +
+
+ + +
+
+
-
-
- - -
-
- - -
-
- - -
-
-
-
- - -
-
-
+ -
+
+

Dirección Fiscal

- - - - - - \ No newline at end of file +
+ + +
+ +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+
+
+ + + + + +
+
diff --git a/frontend/src/lib/components/dashboard/customs_brokers/edit-dialog.svelte b/frontend/src/lib/components/dashboard/customs_brokers/edit-dialog.svelte index e5bfeebb..147df888 100644 --- a/frontend/src/lib/components/dashboard/customs_brokers/edit-dialog.svelte +++ b/frontend/src/lib/components/dashboard/customs_brokers/edit-dialog.svelte @@ -1,10 +1,14 @@