From 1036a2edb5cde3c20f7e5ae436337034ea9ad9b5 Mon Sep 17 00:00:00 2001 From: hreyes Date: Fri, 17 Apr 2026 12:36:05 -0600 Subject: [PATCH] fix/conductores-longitud-placa --- ...8b9c0d1e2_driver_transporter_key_length.py | 39 ++ .../modules/a76/transportation/drivers/dto.py | 7 +- .../a76/transportation/drivers/models.py | 2 +- .../drivers/create-edit-dialog.svelte | 654 ++++++++++++------ .../transporters/create-edit-dialog.svelte | 20 +- .../general_catalogs/drivers/+page.svelte | 62 +- 6 files changed, 500 insertions(+), 284 deletions(-) create mode 100644 backend/alembic/versions/f7a8b9c0d1e2_driver_transporter_key_length.py 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} -
-
- - {#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 + -
- - -
+ + +
-
- - -
+ +
+ + {#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} +
-
- - -
+ +
+ + +
-
- - -
+ +
+ + +
-
- - -
+ +
+ + +
+
+ + + + {formData.class_type || '— Opcional —'} + + + — Vacío — + {#each CLASE_OPCIONES as c} + {c} + {/each} + + +
-
- - -
+ +
+ + +
-
- - -
+ +
+ + +
-
- - -
+ +
+ + +
-
- - - - {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} - - -
+ +
+ + +
-
- - -
+ +
+ + +
+
+ + + + {formData.gender || '— Opcional —'} + + + — Vacío — + M — Masculino + F — Femenino + + +
-
- - -
+ +
+ + + + {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} + + +
-
- - -
-
+ +
+ + + + {formData.hazardous_material_auth || '— Opcional —'} + + + — Vacío — + SI + NO + + +
+
+ + +
+ +
+ + + + +
+ + +
+ + +
+
+ + +
+ + +
+

Primera Identificación

+
+ +
+ + + + {FORMA_ID_OPCIONES.find((o) => o.value === formData.id_key1)?.label || '— Opcional —'} + + + — Vacío — + {#each FORMA_ID_OPCIONES as o} + {o.label} + {/each} + + +
+
+ + +
+
+ + +
+
+ + + + {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_ID_OPCIONES.find((o) => o.value === formData.id_key2)?.label || '— Opcional —'} + + + — Vacío — + {#each FORMA_ID_OPCIONES as o} + {o.label} + {/each} + + +
+
+ + +
+
+ + +
+
+ + + + {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} + + +
+ +
+
+ - - + +
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 @@
- +
- +
@@ -249,7 +249,7 @@
- +
@@ -293,7 +293,7 @@
- +
@@ -345,7 +345,7 @@
- +
@@ -356,23 +356,23 @@
- +
- +
- +
- +
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 @@