Skip to content

Commit

Permalink
Delete asset-related data from inventory item when it is not an asset
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcameron committed Mar 3, 2022
1 parent 3f06aa4 commit fd67240
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
18 changes: 18 additions & 0 deletions client/src/modules/inventory/list/modals/actions.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function InventoryListActionsModalController(
vm.submit = submit;
vm.cancel = cancel;
vm.onSelectTags = onSelectTags;
vm.onChangeIsAsset = onChangeIsAsset;

// startup
startup();
Expand All @@ -49,11 +50,28 @@ function InventoryListActionsModalController(
vm.item.tags = tags;
}

// Immediately clear out asset-related data if we toggle the is_asset checkbox
// (prevent preserving this data when the toggle is clicked twice)
function onChangeIsAsset(isAsset) {
if (!isAsset) {
vm.item.reference_number = null;
vm.item.manufacturer_brand = null;
vm.item.manufacturer_model = null;
}
}

/** submit data */
function submit(form) {
if (form.$invalid) { return null; }
const record = util.filterFormElements(form, true);

// If it is NOT an asset, force deleting the asset-related fields
if (!record.is_asset) {
record.reference_number = null;
record.manufacturer_brand = null;
record.manufacturer_model = null;
}

// Handle the tags specially
if ('TagForm' in record) {
if (vm.item && vm.item.tags) {
Expand Down
5 changes: 4 additions & 1 deletion client/src/modules/inventory/list/modals/actions.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@

<div class="checkbox">
<label>
<input type="checkbox" name="is_asset" ng-true-value="1" ng-false-value="0" ng-model="$ctrl.item.is_asset">
<input type="checkbox"
name="is_asset" ng-true-value="1" ng-false-value="0"
ng-model="$ctrl.item.is_asset"
ng-change="$ctrl.onChangeIsAsset($ctrl.item.is_asset)">
<strong><span translate>INVENTORY.IS_IT_ASSET</span></strong>
</label>
</div>
Expand Down

0 comments on commit fd67240

Please sign in to comment.