Agregar en el Modal campo de Nro Operario back y front
This commit is contained in:
@@ -886,8 +886,12 @@ def create_inspection(
|
|||||||
if not checklist:
|
if not checklist:
|
||||||
raise HTTPException(status_code=404, detail="Checklist no encontrado")
|
raise HTTPException(status_code=404, detail="Checklist no encontrado")
|
||||||
|
|
||||||
|
# Crear inspección con el employee_code del mecánico actual
|
||||||
|
inspection_data = inspection.dict()
|
||||||
|
inspection_data['mechanic_employee_code'] = current_user.employee_code # Agregar código de operario automáticamente
|
||||||
|
|
||||||
db_inspection = models.Inspection(
|
db_inspection = models.Inspection(
|
||||||
**inspection.dict(),
|
**inspection_data,
|
||||||
mechanic_id=current_user.id,
|
mechanic_id=current_user.id,
|
||||||
max_score=checklist.max_score
|
max_score=checklist.max_score
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -110,6 +110,9 @@ class Inspection(Base):
|
|||||||
vehicle_km = Column(Integer)
|
vehicle_km = Column(Integer)
|
||||||
client_name = Column(String(200))
|
client_name = Column(String(200))
|
||||||
|
|
||||||
|
# Datos del mecánico
|
||||||
|
mechanic_employee_code = Column(String(50)) # Código de operario del mecánico
|
||||||
|
|
||||||
# Scoring
|
# Scoring
|
||||||
score = Column(Integer, default=0)
|
score = Column(Integer, default=0)
|
||||||
max_score = Column(Integer, default=0)
|
max_score = Column(Integer, default=0)
|
||||||
|
|||||||
@@ -152,6 +152,7 @@ class InspectionBase(BaseModel):
|
|||||||
vehicle_model: Optional[str] = None
|
vehicle_model: Optional[str] = None
|
||||||
vehicle_km: Optional[int] = None
|
vehicle_km: Optional[int] = None
|
||||||
client_name: Optional[str] = None
|
client_name: Optional[str] = None
|
||||||
|
mechanic_employee_code: Optional[str] = None
|
||||||
|
|
||||||
class InspectionCreate(InspectionBase):
|
class InspectionCreate(InspectionBase):
|
||||||
checklist_id: int
|
checklist_id: int
|
||||||
@@ -167,6 +168,7 @@ class Inspection(InspectionBase):
|
|||||||
id: int
|
id: int
|
||||||
checklist_id: int
|
checklist_id: int
|
||||||
mechanic_id: int
|
mechanic_id: int
|
||||||
|
mechanic_employee_code: Optional[str] = None
|
||||||
score: int
|
score: int
|
||||||
max_score: int
|
max_score: int
|
||||||
percentage: float
|
percentage: float
|
||||||
|
|||||||
@@ -3461,6 +3461,19 @@ function InspectionModal({ checklist, user, onClose, onComplete }) {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium text-gray-700 mb-1">
|
||||||
|
Código de Operario
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={user.employee_code || 'No asignado'}
|
||||||
|
readOnly
|
||||||
|
className="w-full px-3 py-2 border border-gray-200 rounded-lg bg-gray-50 text-gray-600 cursor-not-allowed"
|
||||||
|
title="Este código se asigna automáticamente del perfil del usuario"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="col-span-2">
|
<div className="col-span-2">
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-1">
|
<label className="block text-sm font-medium text-gray-700 mb-1">
|
||||||
Nombre del Cliente
|
Nombre del Cliente
|
||||||
|
|||||||
23
migrations/add_mechanic_employee_code_to_inspections.sql
Normal file
23
migrations/add_mechanic_employee_code_to_inspections.sql
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
-- Migración: Agregar campo mechanic_employee_code a la tabla inspections
|
||||||
|
-- Fecha: 2025-11-26
|
||||||
|
-- Descripción: Agrega un campo para almacenar el código de operario del mecánico que realiza la inspección
|
||||||
|
|
||||||
|
-- Agregar columna mechanic_employee_code a la tabla inspections
|
||||||
|
ALTER TABLE inspections
|
||||||
|
ADD COLUMN IF NOT EXISTS mechanic_employee_code VARCHAR(50);
|
||||||
|
|
||||||
|
-- Comentario descriptivo
|
||||||
|
COMMENT ON COLUMN inspections.mechanic_employee_code IS 'Código de operario del mecánico que realiza la inspección (copiado del perfil de usuario)';
|
||||||
|
|
||||||
|
-- Actualizar inspecciones existentes con el employee_code del mecánico correspondiente
|
||||||
|
UPDATE inspections i
|
||||||
|
SET mechanic_employee_code = u.employee_code
|
||||||
|
FROM users u
|
||||||
|
WHERE i.mechanic_id = u.id
|
||||||
|
AND i.mechanic_employee_code IS NULL;
|
||||||
|
|
||||||
|
-- Verificar que la columna se agregó correctamente
|
||||||
|
SELECT column_name, data_type, character_maximum_length
|
||||||
|
FROM information_schema.columns
|
||||||
|
WHERE table_name = 'inspections'
|
||||||
|
AND column_name = 'mechanic_employee_code';
|
||||||
Reference in New Issue
Block a user