up
This commit is contained in:
@@ -50,11 +50,35 @@ class Confeccion extends Model
|
||||
}
|
||||
});
|
||||
|
||||
// Cuando se completa la confección → avanzar OP
|
||||
static::updated(function ($confeccion) {
|
||||
// Crear traslado cuando la confección tenga recepción (en creación y en actualización)
|
||||
$createTrasladoFn = function ($confeccion) {
|
||||
if ($confeccion->cantidad_recibida !== null) {
|
||||
// Evitar duplicados
|
||||
$exists = \App\Models\TrasladoPrenda::where('referencia_type', self::class)
|
||||
->where('referencia_id', $confeccion->id)
|
||||
->exists();
|
||||
|
||||
if (! $exists) {
|
||||
$destino = 'tintoreria';
|
||||
|
||||
\App\Models\TrasladoPrenda::crearDesdeReferencia(
|
||||
$confeccion,
|
||||
'confeccion',
|
||||
$destino
|
||||
);
|
||||
|
||||
// Marcar el paso como terminado y avanzar la OP incluso si fue parcial
|
||||
$confeccion->ordenProduccion?->avanzarEstado();
|
||||
}
|
||||
}
|
||||
|
||||
// Mantener el comportamiento anterior: si está completo, también avanzamos (por seguridad)
|
||||
if ($confeccion->estado === 'completo') {
|
||||
$confeccion->ordenProduccion?->avanzarEstado();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
static::updated($createTrasladoFn);
|
||||
static::saved($createTrasladoFn);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user