From 38e5050692243021b9a49befdf194d49360aa76b Mon Sep 17 00:00:00 2001 From: Juan Felipe Zapata Moreno Date: Fri, 30 Jan 2026 16:32:07 -0600 Subject: [PATCH] =?UTF-8?q?fix:=20ajustar=20validaci=C3=B3n=20de=20seriale?= =?UTF-8?q?s=20en=20solicitudes=20de=20devoluci=C3=B3n=20y=20restauraci?= =?UTF-8?q?=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Requests/App/ReturnStoreRequest.php | 4 ++-- app/Models/InventorySerial.php | 1 - app/Services/ReturnService.php | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/Http/Requests/App/ReturnStoreRequest.php b/app/Http/Requests/App/ReturnStoreRequest.php index 947af00..350de1f 100644 --- a/app/Http/Requests/App/ReturnStoreRequest.php +++ b/app/Http/Requests/App/ReturnStoreRequest.php @@ -111,8 +111,8 @@ public function withValidator($validator) ); } - // Validar seriales si fueron especificados - if (isset($item['serial_numbers'])) { + // Validar seriales solo si se proporcionaron (array vacío = sin serials) + if (!empty($item['serial_numbers'])) { if (count($item['serial_numbers']) !== $item['quantity_returned']) { $validator->errors()->add( "items.{$index}.serial_numbers", diff --git a/app/Models/InventorySerial.php b/app/Models/InventorySerial.php index a7d4ec3..7fef2ad 100644 --- a/app/Models/InventorySerial.php +++ b/app/Models/InventorySerial.php @@ -87,7 +87,6 @@ public function restoreFromReturn(): void $this->update([ 'status' => 'disponible', 'sale_detail_id' => null, - 'return_detail_id' => null, ]); } diff --git a/app/Services/ReturnService.php b/app/Services/ReturnService.php index 80d2699..2c66766 100644 --- a/app/Services/ReturnService.php +++ b/app/Services/ReturnService.php @@ -113,7 +113,7 @@ public function createReturn(array $data): Returns if ($inventory->track_serials) { // Validación de cantidad de seriales - if (isset($item['serial_numbers']) && is_array($item['serial_numbers'])) { + if (!empty($item['serial_numbers'])) { if (count($item['serial_numbers']) != $item['quantity_returned']) { throw new \Exception( "La cantidad de seriales proporcionados no coincide con la cantidad a devolver " . @@ -123,7 +123,7 @@ public function createReturn(array $data): Returns } // Gestionar seriales - if (isset($item['serial_numbers']) && is_array($item['serial_numbers'])) { + if (!empty($item['serial_numbers'])) { // Seriales específicos proporcionados foreach ($item['serial_numbers'] as $serialNumber) { $serial = InventorySerial::where('serial_number', $serialNumber)