diff --git a/backend/alembic/versions/f7a8b9c0d1e2_driver_transporter_key_length.py b/backend/alembic/versions/f7a8b9c0d1e2_driver_transporter_key_length.py new file mode 100644 index 00000000..c5ba8e21 --- /dev/null +++ b/backend/alembic/versions/f7a8b9c0d1e2_driver_transporter_key_length.py @@ -0,0 +1,39 @@ +"""fix driver transporter_key length and validations + +Revision ID: f7a8b9c0d1e2 +Revises: e76_app_settings +Create Date: 2026-04-17 00:00:00.000000 + +""" + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "f7a8b9c0d1e2" +down_revision = "e76_app_settings" +branch_labels = None +depends_on = None + + +def upgrade() -> None: + op.alter_column( + "driver", + "transporter_key", + schema="a76", + existing_type=sa.String(length=5), + type_=sa.String(length=30), + existing_nullable=False, + ) + + +def downgrade() -> None: + op.alter_column( + "driver", + "transporter_key", + schema="a76", + existing_type=sa.String(length=30), + type_=sa.String(length=5), + existing_nullable=False, + ) \ No newline at end of file diff --git a/backend/api/v1/modules/a76/transportation/drivers/dto.py b/backend/api/v1/modules/a76/transportation/drivers/dto.py index e67daee0..5366d209 100644 --- a/backend/api/v1/modules/a76/transportation/drivers/dto.py +++ b/backend/api/v1/modules/a76/transportation/drivers/dto.py @@ -1,10 +1,13 @@ from typing import Optional -from pydantic import BaseModel +from pydantic import BaseModel, Field + + +TRANSPORTER_KEY_MAX_LENGTH = 30 class DriverBaseDTO(BaseModel): - transporter_key: str + transporter_key: str = Field(..., max_length=TRANSPORTER_KEY_MAX_LENGTH) driver_id: Optional[int] = None line: int driver_name: Optional[str] = None diff --git a/backend/api/v1/modules/a76/transportation/drivers/models.py b/backend/api/v1/modules/a76/transportation/drivers/models.py index dc6d7ee9..57aed494 100644 --- a/backend/api/v1/modules/a76/transportation/drivers/models.py +++ b/backend/api/v1/modules/a76/transportation/drivers/models.py @@ -10,7 +10,7 @@ class Driver(Base, TenantScopedMixin, TimestampMixin): ) transporter_key = Column( - String(5), + String(30), ForeignKey("a76.transporter.transporter_key", ondelete="CASCADE"), primary_key=True, nullable=False, diff --git a/frontend/src/lib/components/dashboard/transportation/drivers/create-edit-dialog.svelte b/frontend/src/lib/components/dashboard/transportation/drivers/create-edit-dialog.svelte index 875c7c47..ca480f5e 100644 --- a/frontend/src/lib/components/dashboard/transportation/drivers/create-edit-dialog.svelte +++ b/frontend/src/lib/components/dashboard/transportation/drivers/create-edit-dialog.svelte @@ -1,6 +1,7 @@ - + {title} - {isEdit - ? 'Modifica los datos del conductor' - : 'Completa los datos para crear un nuevo conductor'} + {isEdit ? 'Modifica los datos del conductor' : 'Completa los datos para crear un nuevo conductor'} - { - e.preventDefault(); - handleSubmit(); - }} - class="space-y-6" - > + { e.preventDefault(); handleSubmit(); }} class="space-y-4"> {#if error} - - {error} - + {error} {/if} - - - Transportista * - {#if isEdit} - - {:else} - - - {transportersLoading - ? 'Cargando transportistas...' - : transporters.length === 0 - ? 'No hay transportistas' - : transporters.find((t) => t.transporter_key === formData.transporter_key) - ? `${formData.transporter_key} - ${transporters.find((t) => t.transporter_key === formData.transporter_key)?.name || ''}` - : 'Seleccionar transportista'} - - - {#each transporters as t} - - {t.transporter_key} — {t.name || t.short_name || 'Sin nombre'} - - {/each} - {#if !transportersLoading && transporters.length === 0} - - No hay transportistas. Crea uno en el catálogo Transportistas. - - {/if} - - - {/if} - + + + 1) Generales + 2) Identificaciones + - - Línea * - - + + + - - Nombre del Conductor - - + + + Transportista * + {#if isEdit} + + {:else} + + + {transportersLoading + ? 'Cargando...' + : transporters.find((t) => t.transporter_key === formData.transporter_key) + ? `${formData.transporter_key} — ${transporters.find((t) => t.transporter_key === formData.transporter_key)?.name || ''}` + : 'Seleccionar transportista'} + + + {#each transporters as t} + + {t.transporter_key} — {t.name || t.short_name || 'Sin nombre'} + + {/each} + {#if !transportersLoading && transporters.length === 0} + No hay transportistas. Crea uno primero. + {/if} + + + {/if} + - - Nombre - - + + + Línea * + + - - Apellido - - + + + * Clave Conductor * + + - - Número de Licencia - - + + + Número de Licencia + + + + Clase + + + {formData.class_type || '— Opcional —'} + + + — Vacío — + {#each CLASE_OPCIONES as c} + {c} + {/each} + + + - - Número de Placa/Insignia - - + + + Núm. Gafete + + - - Express Line ID - - + + + Núm. Gafete Único + + - - ACE ID - - + + + Nombre(s) + + - - País de Nacimiento (clave americana) - - - {countriesLoading - ? 'Cargando países...' - : formData.birth_country - ? `${formData.birth_country} — ${countries.find((c) => c.ame_key === formData.birth_country)?.description_es ?? ''}` - : '— Opcional —'} - - - — Vacío — - {#each countries as c} - - {c.ame_key} — {c.description_es} - - {/each} - - - + + + Apellido Paterno + + - - Auth. Material Peligroso - - + + + Fecha de Nacimiento + + + + Género (F o M) + + + {formData.gender || '— Opcional —'} + + + — Vacío — + M — Masculino + F — Femenino + + + - - Estado Material Peligroso - - + + + País Nacimiento + + + {countriesLoading ? 'Cargando...' : formData.birth_country ? `${formData.birth_country} — ${countries.find((c) => c.ame_key === formData.birth_country)?.description_es ?? ''}` : '— Opcional —'} + + + — Vacío — + {#each countries as c} + {c.ame_key} — {c.description_es} + {/each} + + + - - Tipo de Clase - - - + + + ¿Autorizado Mat. Peligroso? + + + {formData.hazardous_material_auth || '— Opcional —'} + + + — Vacío — + SI + NO + + + + + Estado de Autorización + + + + + + + + + + + + + Permiso Línea Express + + + + Identificación ACE + + + + + + Primera Identificación + + + + Forma de Identificación 1 + + + {FORMA_ID_OPCIONES.find((o) => o.value === formData.id_key1)?.label || '— Opcional —'} + + + — Vacío — + {#each FORMA_ID_OPCIONES as o} + {o.label} + {/each} + + + + + Núm. Identificación 1 + + + + Estado ID 1 + + + + País ID 1 + + + {formData.id_country1 ? `${formData.id_country1} — ${countries.find((c) => c.ame_key === formData.id_country1)?.description_es ?? ''}` : '— Opcional —'} + + + — Vacío — + {#each countries as c} + {c.ame_key} — {c.description_es} + {/each} + + + + + + + Segunda Identificación + + + + Forma de Identificación 2 + + + {FORMA_ID_OPCIONES.find((o) => o.value === formData.id_key2)?.label || '— Opcional —'} + + + — Vacío — + {#each FORMA_ID_OPCIONES as o} + {o.label} + {/each} + + + + + Núm. Identificación 2 + + + + Estado ID 2 + + + + País ID 2 + + + {formData.id_country2 ? `${formData.id_country2} — ${countries.find((c) => c.ame_key === formData.id_country2)?.description_es ?? ''}` : '— Opcional —'} + + + — Vacío — + {#each countries as c} + {c.ame_key} — {c.description_es} + {/each} + + + + + + + - - Cancelar - - - {loading ? 'Guardando...' : isEdit ? 'Actualizar' : 'Crear'} - + Cancelar + {loading ? 'Guardando...' : isEdit ? 'Actualizar' : 'Crear'} diff --git a/frontend/src/lib/components/dashboard/transportation/transporters/create-edit-dialog.svelte b/frontend/src/lib/components/dashboard/transportation/transporters/create-edit-dialog.svelte index 8d2b931f..a39db20b 100644 --- a/frontend/src/lib/components/dashboard/transportation/transporters/create-edit-dialog.svelte +++ b/frontend/src/lib/components/dashboard/transportation/transporters/create-edit-dialog.svelte @@ -213,7 +213,7 @@ bind:value={formData.transporter_key} disabled={isEdit} required - maxlength={23} + maxlength={30} /> @@ -234,12 +234,12 @@ RFC - + Responsable - + @@ -249,7 +249,7 @@ Código CAAT - + @@ -293,7 +293,7 @@ Calle y Número - + @@ -345,7 +345,7 @@ C.P. - + @@ -356,23 +356,23 @@ Servidor FTP - + Usuario - + Contraseña - + Directorio - + diff --git a/frontend/src/routes/dashboard/general_catalogs/drivers/+page.svelte b/frontend/src/routes/dashboard/general_catalogs/drivers/+page.svelte index 778c613c..8f19bbcd 100644 --- a/frontend/src/routes/dashboard/general_catalogs/drivers/+page.svelte +++ b/frontend/src/routes/dashboard/general_catalogs/drivers/+page.svelte @@ -1,6 +1,4 @@
Primera Identificación
Segunda Identificación