Skip to content

Commit

Permalink
Merge pull request #35 from dvicklund/dev
Browse files Browse the repository at this point in the history
add ability to get location by id
  • Loading branch information
dvicklund authored Jun 10, 2022
2 parents 1020067 + bd944a5 commit 654e3ca
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Traits/LocationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Stevebauman\Inventory\Exceptions\InvalidLocationException;
use Illuminate\Support\Facades\Lang;
use Stevebauman\Inventory\Models\Location;

/**
* Trait LocationTrait.
Expand All @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions tests/InventoryStockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 654e3ca

Please sign in to comment.