Skip to content

A free open source IT asset/license management system

Make 'pending' assets properly requestable; use requestable scope

Brady Wetheringtonef463a37d815
diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php
index dd99668eac..85373833ae 100644
--- a/app/Http/Controllers/Api/AssetsController.php
+++ b/app/Http/Controllers/Api/AssetsController.php
@@ -937,7 +937,7 @@ class AssetsController extends Controller
$assets = Company::scopeCompanyables(Asset::select('assets.*'), 'company_id', 'assets')
->with('location', 'assetstatus', 'assetlog', 'company', 'defaultLoc','assignedTo',
- 'model.category', 'model.manufacturer', 'model.fieldset', 'supplier')->where('assets.requestable', '=', '1');
+ 'model.category', 'model.manufacturer', 'model.fieldset', 'supplier')->requestableAssets();
$offset = request('offset', 0);
$limit = $request->input('limit', 50);
diff --git a/app/Models/Asset.php b/app/Models/Asset.php
index 3c5ffbb8cb..49f2ca1ff3 100644
--- a/app/Models/Asset.php
+++ b/app/Models/Asset.php
@@ -1167,9 +1167,10 @@ class Asset extends Depreciable
{
return Company::scopeCompanyables($query->where('requestable', '=', 1))
->whereHas('assetstatus', function ($query) {
- $query->where('deployable', '=', 1)
- ->where('pending', '=', 0)
- ->where('archived', '=', 0);
+ $query->where(function ($query) {
+ $query->where('deployable', '=', 1)
+ ->where('archived', '=', 0); // you definitely can't request something that's archived
+ })->orWhere('pending', '=', 1); // we've decided that even though an asset may be 'pending', you can still request it
});
}