diff --git a/src/Traits/LocationTrait.php b/src/Traits/LocationTrait.php index ba30d71..fd7164d 100644 --- a/src/Traits/LocationTrait.php +++ b/src/Traits/LocationTrait.php @@ -4,6 +4,7 @@ use Stevebauman\Inventory\Exceptions\InvalidLocationException; use Illuminate\Support\Facades\Lang; +use Stevebauman\Inventory\Models\Location; /** * Trait LocationTrait. @@ -24,6 +25,18 @@ public function getLocation($location) { if ($this->isLocation($location)) { return $location; + } else if (is_numeric($location)) { + try { + $result = Location::where('id', '=', $location)->first(); + + return $result; + } catch (\Exception $e) { + $message = Lang::get('inventory::exceptions.InvalidLocationException', [ + 'location' => $location, + ]); + + throw new InvalidLocationException($message); + } } else { $message = Lang::get('inventory::exceptions.InvalidLocationException', [ 'location' => $location, diff --git a/tests/InventoryStockTest.php b/tests/InventoryStockTest.php index 8648012..a396fe2 100644 --- a/tests/InventoryStockTest.php +++ b/tests/InventoryStockTest.php @@ -285,4 +285,16 @@ public function testRollbackStockMovement() { $this->assertEquals($initialQuantity, $stock->quantity); } + + public function testNumericLocation() { + $location = $this->newLocation(); + + $item = $this->newInventory(); + + $item->createStockOnLocation(42, $location->id, "New stuff"); + + $newQuantity = $item->getTotalStock(); + + $this->assertEquals(42, $newQuantity); + } }