up
This commit is contained in:
@@ -48,6 +48,41 @@ class InventarioDistribucionTest extends TestCase
|
||||
$pivot = \DB::table('variante_bodega')->where('variante_id', $variant->id)->where('bodega_id', $bodega->id)->first();
|
||||
$this->assertNotNull($pivot);
|
||||
$this->assertEquals(3, $pivot->stock);
|
||||
|
||||
// El inventario padre debe quedar ligado al producto si se creó automáticamente
|
||||
$inv->refresh();
|
||||
$this->assertNotNull($inv->producto_id);
|
||||
$this->assertEquals($variant->producto_id, $inv->producto_id);
|
||||
}
|
||||
|
||||
public function test_distribution_creates_and_links_product_when_missing()
|
||||
{
|
||||
$categoria = \App\Models\Categoria::create(['nombre' => 'Ropa']);
|
||||
|
||||
$op = OrdenProduccion::create(['numero_orden' => 'OP-0100', 'prenda_modelo' => 'PrendaX', 'referencia' => 'PX-01', 'cantidad_total' => 10, 'metros_requeridos' => 0, 'fecha_inicio' => now(), 'fecha_entrega_estimada' => now()->addDays(7)]);
|
||||
|
||||
$inv = InventarioPrenda::create(['orden_produccion_id' => $op->id, 'cantidad_terminada' => 5, 'cantidad_disponible' => 5, 'fecha_ingreso' => now(), 'estado' => 'en_bodega', 'producto_id' => null]);
|
||||
|
||||
// Crear distribución sin producto previo
|
||||
$dist = InventarioPrendaDistribucion::create([
|
||||
'inventario_prenda_id' => $inv->id,
|
||||
'bodega_id' => 1,
|
||||
'color_id' => null,
|
||||
'size_id' => null,
|
||||
'cantidad' => 2,
|
||||
]);
|
||||
|
||||
// Verificar que se creó un producto y que el inventario padre quedó ligado
|
||||
$inv->refresh();
|
||||
$this->assertNotNull($inv->producto_id);
|
||||
|
||||
$producto = \App\Models\Producto::find($inv->producto_id);
|
||||
$this->assertNotNull($producto);
|
||||
|
||||
// Y que la distribución llevó stock al producto en la bodega
|
||||
$pivot = \DB::table('producto_bodega')->where('producto_id', $producto->id)->where('bodega_id', 1)->first();
|
||||
$this->assertNotNull($pivot);
|
||||
$this->assertEquals(2, $pivot->stock);
|
||||
}
|
||||
|
||||
public function test_creating_inventario_with_excessive_distributions_throws_validation_exception()
|
||||
|
||||
Reference in New Issue
Block a user