Merge branch 'develop' of https://github.com/snipe/snipe-it into develop

This commit is contained in:
snipe 2022-01-18 14:50:35 -08:00
commit a26119c262
4 changed files with 34 additions and 12 deletions

View file

@ -54,7 +54,7 @@ class AssetsController extends Controller
{
\Log::debug(Route::currentRouteName());
$filter_non_deprecable_assets = false;
/**
* This looks MAD janky (and it is), but the AssetsController@index does a LOT of heavy lifting throughout the
@ -68,6 +68,7 @@ class AssetsController extends Controller
* which would have been far worse of a mess. *sad face* - snipe (Sept 1, 2021)
*/
if (Route::currentRouteName()=='api.depreciation-report.index') {
$filter_non_deprecable_assets = true;
$transformer = 'App\Http\Transformers\DepreciationReportTransformer';
$this->authorize('reports.view');
} else {
@ -118,6 +119,12 @@ class AssetsController extends Controller
'model.category', 'model.manufacturer', 'model.fieldset','supplier'); //it might be tempting to add 'assetlog' here, but don't. It blows up update-heavy users.
if($filter_non_deprecable_assets) {
$non_deprecable_models = AssetModel::select('id')->whereNotNull('depreciation_id')->get();
$assets->InModelList($non_deprecable_models->toArray());
}
// These are used by the API to query against specific ID numbers.
// They are also used by the individual searches on detail pages like
// locations, etc.

View file

@ -178,6 +178,7 @@ class ItemImporter extends Importer
*/
public function createOrFetchAssetModel(array $row)
{
$condition = array();
$asset_model_name = $this->findCsvMatch($row, 'asset_model');
$asset_modelNumber = $this->findCsvMatch($row, 'model_number');
// TODO: At the moment, this means we can't update the model number if the model name stays the same.
@ -189,8 +190,16 @@ class ItemImporter extends Importer
} elseif ((empty($asset_model_name)) && (empty($asset_modelNumber))) {
$asset_model_name = 'Unknown';
}
if ((!empty($asset_model_name)) && (empty($asset_modelNumber))) {
$condition[] = ['name', '=', $asset_model_name];
} elseif ((!empty($asset_model_name)) && (!empty($asset_modelNumber))) {
$condition[] = ['name', '=', $asset_model_name];
$condition[] = ['model_number', '=', $asset_modelNumber];
}
$editingModel = $this->updating;
$asset_model = AssetModel::where(['name' => $asset_model_name, 'model_number' => $asset_modelNumber])->first();
$asset_model = AssetModel::where($condition)->first();
if ($asset_model) {
if (! $this->updating) {
@ -201,7 +210,11 @@ class ItemImporter extends Importer
$this->log('Matching Model found, updating it.');
$item = $this->sanitizeItemForStoring($asset_model, $editingModel);
$item['name'] = $asset_model_name;
$item['model_number'] = $asset_modelNumber;
if(!empty($asset_modelNumber)){
$item['model_number'] = $asset_modelNumber;
}
$asset_model->update($item);
$asset_model->save();
$this->log('Asset Model Updated');

View file

@ -34,7 +34,9 @@
</div>
<!-- Custom Fieldset -->
@livewire('custom-field-set-default-values-for-model',["model_id" => $item->id])
@if (isset($item->id))
@livewire('custom-field-set-default-values-for-model',["model_id" => $item->id])
@endif
@include ('partials.forms.edit.notes')
@include ('partials.forms.edit.requestable', ['requestable_text' => trans('admin/models/general.requestable')])

View file

@ -296,7 +296,7 @@ Route::group(['prefix' => 'v1', 'middleware' => 'api'], function () {
); // end depreciations API routes
Route::post('reports/depreciation',
Route::get('reports/depreciation',
[
Api\AssetsController::class,
'index'
@ -368,18 +368,18 @@ Route::group(['prefix' => 'v1', 'middleware' => 'api'], function () {
});
Route::resource('fields',
Route::resource('fieldsets',
Api\CustomFieldsetsController::class,
['names' =>
[
'index' => 'api.customfields.index',
'show' => 'api.customfields.show',
'update' => 'api.customfields.update',
'store' => 'api.customfields.store',
'destroy' => 'api.customfields.destroy',
'index' => 'api.fieldsets.index',
'show' => 'api.fieldsets.show',
'update' => 'api.fieldsets.update',
'store' => 'api.fieldsets.store',
'destroy' => 'api.fieldsets.destroy',
],
'except' => ['create', 'edit'],
'parameters' => ['field' => 'field_id'],
'parameters' => ['fieldset' => 'fieldset_id'],
]
); // end custom fieldsets API routes