Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Fixed deprecations on inventory module
Browse files Browse the repository at this point in the history
resolves #184
  • Loading branch information
jkleinsc committed Oct 26, 2015
1 parent 6259d85 commit dee722c
Show file tree
Hide file tree
Showing 24 changed files with 221 additions and 331 deletions.
1 change: 1 addition & 0 deletions app/controllers/abstract-report-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default Ember.ArrayController.extend(DateFormat, ModalHelper, NumberForma
progressMessage: 'Please wait while your report is generated.',
progressTitle: 'Generating Report',
reportColumns: null,
reportHeaders: null,
reportRows: [],
reportTitle: null,
reportType: null,
Expand Down
10 changes: 5 additions & 5 deletions app/inventory/adjust/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ import AbstractEditController from 'hospitalrun/controllers/abstract-edit-contro
import AdjustmentTypes from 'hospitalrun/mixins/inventory-adjustment-types';
import Ember from 'ember';
export default AbstractEditController.extend(AdjustmentTypes, {
needs: 'inventory',
inventoryController: Ember.inject.controller('inventory'),

expenseAccountList: Ember.computed.alias('controllers.inventory.expenseAccountList'),
expenseAccountList: Ember.computed.alias('inventoryController.expenseAccountList'),

title: 'Adjustment',

transactionTypeChanged: function() {
Ember.run.once(this, function() {
this.get('model').validate();
this.get('model').validate().catch();
});
}.observes('transactionType'),

updateButtonText: function() {
return this.get('transactionType');
}.property('transactionType'),
return this.get('model.transactionType');
}.property('model.transactionType'),

updateButtonAction: 'adjust',

Expand Down
12 changes: 5 additions & 7 deletions app/inventory/adjust/template.hbs
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
{{#modal-dialog
hideCancelButton=hideCancelButton
hideUpdateButton=hideUpdateButton
isUpdateDisabled=isUpdateDisabled
title=title
updateButtonAction=updateButtonAction
updateButtonText=updateButtonText }}
{{#em-form model=this submitButton=false }}
{{#em-form model=model submitButton=false }}
<div class="form-group">
<label class="control-label">Item</label>
<p class="form-control-static">{{adjustmentItem.name}}</p>
<p class="form-control-static">{{model.adjustmentItem.name}}</p>
</div>
<div class="form-group">
<label class="control-label">Adjustment For</label>
<p class="form-control-static">{{locationName}}</p>
<p class="form-control-static">{{model.locationName}}</p>
</div>
<div class="form-group">
<label class="control-label">Current Quantity</label>
<p class="form-control-static">{{quantity}}</p>
<p class="form-control-static">{{model.quantity}}</p>
</div>
<div class="row">
{{em-select class="col-sm-4" label="Adjustment Type"
Expand All @@ -28,7 +26,7 @@
{{em-text label="Reason" property="reason" rows=3 }}
<div class="row">
{{date-picker property="dateCompleted" label="Adjustment Date" class="col-sm-4 required"}}
{{select-or-typeahead property="expenseAccount" label="Expense To" list=expenseAccountList selection=expenseAccount class="col-sm-8"}}
{{select-or-typeahead property="expenseAccount" label="Expense To" list=expenseAccountList selection=model.expenseAccount class="col-sm-8"}}
</div>
{{/em-form}}
{{/modal-dialog}}
6 changes: 4 additions & 2 deletions app/inventory/barcode/controller.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import Ember from 'ember';
export default Ember.ObjectController.extend({
selectedPrinter: null,

barcodeUri: function() {
var id = this.get('id'),
name = this.get('name');
var id = this.get('model.id'),
name = this.get('model.name');
return Ember.$(document).JsBarcode(id, {
width: 1,
height: 20,
Expand Down
88 changes: 46 additions & 42 deletions app/inventory/batch/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import InventorySelection from 'hospitalrun/mixins/inventory-selection';
import Ember from 'ember';

export default AbstractEditController.extend(InventoryId, InventoryLocations, InventorySelection, {
needs: ['inventory'],

warehouseList: Ember.computed.alias('controllers.inventory.warehouseList'),
aisleLocationList: Ember.computed.alias('controllers.inventory.aisleLocationList'),
vendorList: Ember.computed.alias('controllers.inventory.vendorList'),
doingUpdate: false,
inventoryController: Ember.inject.controller('inventory'),
inventoryItems: null,
warehouseList: Ember.computed.alias('inventoryController.warehouseList'),
aisleLocationList: Ember.computed.alias('inventoryController.aisleLocationList'),
vendorList: Ember.computed.alias('inventoryController.vendorList'),
purchaseAttributes: [
'expirationDate',
'inventoryItem',
Expand All @@ -31,41 +32,41 @@ export default AbstractEditController.extend(InventoryId, InventoryLocations, In

lookupListsToUpdate: [{
name: 'aisleLocationList', // Name of property containing lookup list
property: 'aisleLocation', // Corresponding property on model that potentially contains a new value to add to the list
property: 'model.aisleLocation', // Corresponding property on model that potentially contains a new value to add to the list
id: 'aisle_location_list' // Id of the lookup list to update
}, {
name: 'vendorList', // Name of property containing lookup list
property: 'vendor', // Corresponding property on model that potentially contains a new value to add to the list
property: 'model.vendor', // Corresponding property on model that potentially contains a new value to add to the list
id: 'vendor_list' // Id of the lookup list to update
}, {
name: 'warehouseList', // Name of property containing lookup list
property: 'location', // Corresponding property on model that potentially contains a new value to add to the list
property: 'model.location', // Corresponding property on model that potentially contains a new value to add to the list
id: 'warehouse_list' // Id of the lookup list to update
}],

showDistributionUnit: function() {
return this._haveValidInventoryItem();
}.property('inventoryItemTypeAhead', 'inventoryItem'),
}.property('model.inventoryItemTypeAhead', 'model.inventoryItem'),

showInvoiceItems: function() {
var invoiceItems = this.get('invoiceItems');
var invoiceItems = this.get('model.invoiceItems');
return !Ember.isEmpty(invoiceItems);
}.property('invoiceItems.[]'),
}.property('model.invoiceItems.[]'),

totalReceived: function() {
var invoiceItems = this.get('invoiceItems'),
var invoiceItems = this.get('model.invoiceItems'),
total = 0;
if (!Ember.isEmpty('invoiceItems')) {
total = invoiceItems.reduce(function(previousValue, item) {
return previousValue + Number(item.get('purchaseCost'));
}, total);
}
var purchaseCost = this.get('purchaseCost');
if (this.get('isValid') && !Ember.isEmpty(purchaseCost)) {
var purchaseCost = this.get('model.purchaseCost');
if (this.get('model.isValid') && !Ember.isEmpty(purchaseCost)) {
total += Number(purchaseCost);
}
return total;
}.property('invoiceItems.[].purchaseCost', 'isValid', 'purchaseCost'),
}.property('model.invoiceItems.[].purchaseCost', 'model.isValid', 'model.purchaseCost'),

updateButtonText: 'Save',

Expand All @@ -75,7 +76,7 @@ export default AbstractEditController.extend(InventoryId, InventoryLocations, In
this.generateId().then(function(inventoryId) {
var inventoryItem = this.store.createRecord('inventory', {
id: inventoryId,
name: this.get('inventoryItemTypeAhead'),
name: this.get('model.inventoryItemTypeAhead'),
quantity: 0, // Needed for validation purposes
skipSavePurchase: true
});
Expand All @@ -85,11 +86,11 @@ export default AbstractEditController.extend(InventoryId, InventoryLocations, In

_addInventoryItem: function() {
var model = this.get('model'),
inventoryItemTypeAhead = this.get('inventoryItemTypeAhead'),
purchaseCost = this.get('purchaseCost'),
quantity = this.get('quantity');
model.validate().then(function() {
if (this.get('isValid') && !Ember.isEmpty(inventoryItemTypeAhead) && !Ember.isEmpty(quantity) && !Ember.isEmpty(purchaseCost)) {
inventoryItemTypeAhead = this.get('model.inventoryItemTypeAhead'),
purchaseCost = this.get('model.purchaseCost'),
quantity = this.get('model.quantity');
return model.validate().then(function() {
if (this.get('model.isValid') && !Ember.isEmpty(inventoryItemTypeAhead) && !Ember.isEmpty(quantity) && !Ember.isEmpty(purchaseCost)) {
if (this._haveValidInventoryItem()) {
this._addInvoiceItem();
} else {
Expand All @@ -105,22 +106,23 @@ export default AbstractEditController.extend(InventoryId, InventoryLocations, In
},

_addInvoiceItem: function() {
var invoiceItems = this.get('invoiceItems'),
itemProperties = this.getProperties(this.get('purchaseAttributes')),
var model = this.get('model'),
invoiceItems = model.get('invoiceItems'),
itemProperties = model.getProperties(this.get('purchaseAttributes')),
invoiceItem = Ember.Object.create(itemProperties);
invoiceItems.addObject(invoiceItem);
this.set('expirationDate');
this.set('inventoryItem');
this.set('inventoryItemTypeAhead');
this.set('lotNumber');
this.set('purchaseCost');
this.set('quantity');
this.set('selectedInventoryItem');
this.set('vendorItemNo');
model.set('expirationDate');
model.set('inventoryItem');
model.set('inventoryItemTypeAhead');
model.set('lotNumber');
model.set('purchaseCost');
model.set('quantity');
model.set('selectedInventoryItem');
model.set('vendorItemNo');
},

_findInventoryItem: function(purchase) {
var invoiceItems = this.get('invoiceItems'),
var invoiceItems = this.get('model.invoiceItems'),
inventoryId = purchase.get('inventoryItem');
if (!Ember.isEmpty(inventoryId)) {
var invoiceItem = invoiceItems.find(function(item) {
Expand All @@ -133,8 +135,8 @@ export default AbstractEditController.extend(InventoryId, InventoryLocations, In
},

_haveValidInventoryItem: function() {
var inventoryItemTypeAhead = this.get('inventoryItemTypeAhead'),
inventoryItem = this.get('inventoryItem');
var inventoryItemTypeAhead = this.get('model.inventoryItemTypeAhead'),
inventoryItem = this.get('model.inventoryItem');
if (Ember.isEmpty(inventoryItemTypeAhead) || Ember.isEmpty(inventoryItem)) {
return false;
} else {
Expand All @@ -149,14 +151,15 @@ export default AbstractEditController.extend(InventoryId, InventoryLocations, In
},

_savePurchases: function() {
var purchaseDefaults = this.getProperties([
var model = this.get('model'),
purchaseDefaults = model.getProperties([
'dateReceived',
'vendor',
'invoiceNo',
'location',
'aisleLocation',
'giftInKind']),
invoiceItems = this.get('invoiceItems'),
invoiceItems = model.get('invoiceItems'),
inventoryPurchase,
savePromises = [];
invoiceItems.forEach(function(invoiceItem) {
Expand Down Expand Up @@ -202,7 +205,7 @@ export default AbstractEditController.extend(InventoryId, InventoryLocations, In
},

addedNewInventoryItem: function(inventoryItem) {
this.set('inventoryItem', inventoryItem);
this.set('model.inventoryItem', inventoryItem);
this._addInvoiceItem();
this.send('closeModal');
if (this.get('doingUpdate')) {
Expand All @@ -211,7 +214,7 @@ export default AbstractEditController.extend(InventoryId, InventoryLocations, In
},

removeItem: function(removeInfo) {
var invoiceItems = this.get('invoiceItems'),
var invoiceItems = this.get('model.invoiceItems'),
item = removeInfo.itemToRemove;
invoiceItems.removeObject(item);
this.send('closeModal');
Expand All @@ -231,10 +234,11 @@ export default AbstractEditController.extend(InventoryId, InventoryLocations, In
*/
update: function() {
this.set('doingUpdate', true);
var addingNewInventory = this._addInventoryItem();
if (!addingNewInventory) {
this._savePurchases();
}
this._addInventoryItem().then(function(addingNewInventory) {
if (!addingNewInventory) {
this._savePurchases();
}
});
}
}
});
30 changes: 15 additions & 15 deletions app/inventory/batch/template.hbs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{{#edit-panel editPanelProps=editPanelProps}}
{{#em-form model=this submitButton=false }}
{{#em-form model=model submitButton=false }}
<div class="row">
{{date-picker property="dateReceived" label="Date Received" class="col-sm-4 required"}}
{{select-or-typeahead property="vendor" label="Vendor" list=vendorList selection=vendor className="col-sm-4 required"}}
{{select-or-typeahead property="vendor" label="Vendor" list=vendorList selection=model.vendor className="col-sm-4 required"}}
{{em-input property="invoiceNo" label="Invoice Number" class="col-sm-4"}}
</div>
<div class="row">
{{select-or-typeahead property="location" label="Location" list=warehouseList selection=location className="col-sm-5"}}
{{select-or-typeahead property="aisleLocation" label="Aisle Location" list=aisleLocationList selection=aisleLocation className="col-sm-5"}}
{{select-or-typeahead property="location" label="Location" list=warehouseList selection=model.location className="col-sm-5"}}
{{select-or-typeahead property="aisleLocation" label="Aisle Location" list=aisleLocationList selection=model.aisleLocation className="col-sm-5"}}
<div class="form-group col-sm-2">
<label class="control-label">Gift In Kind</label>
{{em-checkbox label="Gift In Kind" property="giftInKind"}}
Expand All @@ -31,7 +31,7 @@
<div class="form-group col-sm-1">
<label class="control-label">Unit</label>
{{#if showDistributionUnit}}
<p class="form-control-static">{{inventoryItem.distributionUnit}}</p>
<p class="form-control-static">{{model.inventoryItem.distributionUnit}}</p>
{{/if}}
</div>
{{em-input property="purchaseCost" label="Purchase Cost" class="col-sm-2 required"}}
Expand All @@ -51,7 +51,7 @@
</div>
</div>
</div>
{{#if invoiceItems}}
{{#if model.invoiceItems}}
<h3>Invoice Items</h3>
<table class="table">
<tr class="table-header">
Expand All @@ -63,39 +63,39 @@
<th>Expiration Date</th>
<th>Action</th>
</tr>
{{#each invoiceItems}}
{{#each model.invoiceItems as |invoiceItem|}}
<tr>
<td class="col-sm-2">
{{inventoryItem.name}}
{{invoiceItem.inventoryItem.name}}
</td>
<td class="col-sm-2">
<div class="input-group">
{{input class="form-control" value=quantity }}
{{input class="form-control" value=invoiceItem.quantity }}
<span class="input-group-addon">
{{inventoryItem.distributionUnit}}
{{invoiceItem.inventoryItem.distributionUnit}}
</span>
</div>
</td>
<td class="col-sm-2">
<div class="form-group">
{{input class="form-control" value=purchaseCost }}
{{input class="form-control" value=invoiceItem.purchaseCost }}
</div>
</td>
<td class="col-sm-2">
<div class="form-group">
{{input class="form-control" value=vendorItemNo }}
{{input class="form-control" value=invoiceItem.vendorItemNo }}
</div>
</td>
<td class="col-sm-2">
<div class="form-group">
{{input class="form-control" value=lotNumber }}
{{input class="form-control" value=invoiceItem.lotNumber }}
</div>
</td>
<td class="col-sm-2">
{{date-picker property="expirationDate" minDate="now" model=this }}
{{date-picker property="expirationDate" minDate="now" model=invoiceItem }}
</td>
<td class="col-sm-1">
<button class="btn btn-default warning" {{action "showRemoveItem" this bubbles=false }}>
<button class="btn btn-default warning" {{action "showRemoveItem" invoiceItem bubbles=false }}>
<span class="octicon octicon-x"></span>Remove
</button>
</td>
Expand Down
4 changes: 1 addition & 3 deletions app/inventory/delete/template.hbs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{{#modal-dialog
hideCancelButton=hideCancelButton
hideUpdateButton=hideUpdateButton
isUpdateDisabled=isUpdateDisabled
title=title
updateButtonAction=updateButtonAction
updateButtonText=updateButtonText }}
<div class="alert alert-danger">
<span class="glyphicon glyphicon-warning-sign"></span>
Are you sure you wish to delete {{name}}?
Are you sure you wish to delete {{model.name}}?
</div>
{{/modal-dialog}}
Loading

0 comments on commit dee722c

Please sign in to comment.