up
This commit is contained in:
@@ -12,6 +12,7 @@ class InventarioPrenda extends Model
|
||||
'cantidad_disponible',
|
||||
'fecha_ingreso',
|
||||
'estado',
|
||||
'producto_id',
|
||||
];
|
||||
|
||||
public function ordenProduccion()
|
||||
@@ -19,6 +20,11 @@ class InventarioPrenda extends Model
|
||||
return $this->belongsTo(OrdenProduccion::class);
|
||||
}
|
||||
|
||||
public function producto()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Producto::class, 'producto_id');
|
||||
}
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($inventario) {
|
||||
@@ -36,6 +42,16 @@ class InventarioPrenda extends Model
|
||||
}
|
||||
|
||||
$op = $inventario->ordenProduccion;
|
||||
|
||||
// Priorizar producto explícito si fue seleccionado
|
||||
if ($inventario->producto_id) {
|
||||
$producto = \App\Models\Producto::find($inventario->producto_id);
|
||||
if ($producto && ! $producto->variants()->exists()) {
|
||||
$producto->increment('stock', $inventario->cantidad_terminada);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $op) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user