up
This commit is contained in:
@@ -33,6 +33,24 @@ class InventarioPrenda extends Model
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($inventario) {
|
||||
// Sincronizar producto desde la Orden de Producción si no se especificó
|
||||
if ($inventario->orden_produccion_id && ! $inventario->producto_id) {
|
||||
$op = \App\Models\OrdenProduccion::find($inventario->orden_produccion_id);
|
||||
if ($op && $op->producto_id) {
|
||||
$inventario->producto_id = $op->producto_id;
|
||||
}
|
||||
}
|
||||
|
||||
// Validar conflicto: si el OP tiene producto y difiere del seleccionado, bloquear
|
||||
if ($inventario->producto_id && $inventario->orden_produccion_id) {
|
||||
$op = \App\Models\OrdenProduccion::find($inventario->orden_produccion_id);
|
||||
if ($op && $op->producto_id && $op->producto_id != $inventario->producto_id) {
|
||||
throw \Illuminate\Validation\ValidationException::withMessages([
|
||||
'producto_id' => 'El producto seleccionado difiere del producto asociado a la Orden de Producción (fuente de verdad).',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Validación: la cantidad terminada no puede exceder lo recibido para esta OP (traslados a bodega)
|
||||
if ($inventario->orden_produccion_id) {
|
||||
$totalRecibido = \App\Models\TrasladoPrenda::where('orden_produccion_id', $inventario->orden_produccion_id)
|
||||
|
||||
Reference in New Issue
Block a user