-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ANGOLASUP-909: changed pack and doses logic in order fulfillment (#175)
* ANGOLASUO-909: second request * code cleanup and test fixes
- Loading branch information
1 parent
5e14d44
commit 8ee3d6f
Showing
9 changed files
with
627 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"shipmentView.unit": "Unit", | ||
"shipmentView.fillQuantityInDoses": "Fill Quantity (in Doses)", | ||
"shipmentView.fillQuantityTotal": "Fill Quantity (Total)", | ||
"shipmentView.quantitiesProvidedInDoses": "These quantities are always provided in Doses" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* This program is part of the OpenLMIS logistics management information system platform software. | ||
* Copyright © 2017 VillageReach | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under the terms | ||
* of the GNU Affero General Public License as published by the Free Software Foundation, either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU Affero General Public License for more details. You should have received a copy of | ||
* the GNU Affero General Public License along with this program. If not, see | ||
* http://www.gnu.org/licenses. For additional information contact [email protected]. | ||
*/ | ||
|
||
(function() { | ||
|
||
'use strict'; | ||
|
||
/** | ||
* @ngdoc service | ||
* @name shipment-view.ShipmentViewLineItemGroup | ||
* | ||
* @description | ||
* Represents a group of line items or line item groups. | ||
*/ | ||
angular | ||
.module('shipment-view') | ||
.factory('ShipmentViewLineItemGroup', ShipmentViewLineItemGroup); | ||
|
||
ShipmentViewLineItemGroup.inject = ['ShipmentViewLineItem', 'classExtender']; | ||
|
||
function ShipmentViewLineItemGroup(ShipmentViewLineItem, classExtender) { | ||
|
||
classExtender.extend(ShipmentViewLineItemGroup, ShipmentViewLineItem); | ||
|
||
ShipmentViewLineItemGroup.prototype.getAvailableSoh = getAvailableSoh; | ||
ShipmentViewLineItemGroup.prototype.getFillQuantity = getFillQuantity; | ||
ShipmentViewLineItemGroup.prototype.getOrderQuantity = getOrderQuantity; | ||
|
||
return ShipmentViewLineItemGroup; | ||
|
||
/** | ||
* @ngdoc method | ||
* @methodOf shipment-view.ShipmentViewLineItemGroup | ||
* @name ShipmentViewLineItemGroup | ||
* @constructor | ||
* | ||
* @description | ||
* Creates an instance of the ShipmentViewLineItemGroup. | ||
* | ||
* @param {Object} config configuration object used when creating new instance of the class | ||
*/ | ||
function ShipmentViewLineItemGroup(config) { | ||
this.super(config); | ||
this.orderQuantity = config.orderQuantity; | ||
this.lineItems = config.lineItems; | ||
this.isMainGroup = config.isMainGroup; | ||
this.noStockAvailable = this.getAvailableSoh() === 0; | ||
this.isLot = false; | ||
} | ||
|
||
/** | ||
* @ngdoc method | ||
* @methodOf shipment-view.ShipmentViewLineItemGroup | ||
* @name getAvailableSoh | ||
* | ||
* @description | ||
* Returns a sum of all stock available for the children line items/line item groups. | ||
* | ||
* @return {number} the sum of all available stock on hand for the whole group | ||
*/ | ||
function getAvailableSoh() { | ||
return this.lineItems.reduce(function(availableSoh, lineItem) { | ||
return availableSoh + lineItem.getAvailableSoh(); | ||
}, 0); | ||
} | ||
|
||
/** | ||
* @ngdoc method | ||
* @methodOf shipment-view.ShipmentViewLineItemGroup | ||
* @name getFillQuantity | ||
* | ||
* @description | ||
* Returns a sum of all fill quantities for the children line items/line item groups. | ||
* | ||
* @return {number} the sum of all fill quantities for the whole group | ||
*/ | ||
function getFillQuantity() { | ||
return this.lineItems.reduce(function(fillQuantity, lineItem) { | ||
return fillQuantity + lineItem.getFillQuantity(); | ||
}, 0); | ||
} | ||
|
||
/** | ||
* @ngdoc method | ||
* @methodOf shipment-view.ShipmentViewLineItemGroup | ||
* @name getOrderQuantity | ||
* | ||
* @description | ||
* Returns an ordered quantity for the commodity type related with the line item. | ||
* | ||
* @return {number} the ordered quantity for the commodity type related with the | ||
* line item | ||
*/ | ||
function getOrderQuantity() { | ||
if (this.orderQuantity === undefined || this.orderQuantity === null) { | ||
return; | ||
} | ||
return this.orderQuantity; | ||
} | ||
} | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* This program is part of the OpenLMIS logistics management information system platform software. | ||
* Copyright © 2017 VillageReach | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under the terms | ||
* of the GNU Affero General Public License as published by the Free Software Foundation, either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU Affero General Public License for more details. You should have received a copy of | ||
* the GNU Affero General Public License along with this program. If not, see | ||
* http://www.gnu.org/licenses. For additional information contact [email protected]. | ||
*/ | ||
|
||
(function() { | ||
|
||
'use strict'; | ||
|
||
/** | ||
* @ngdoc service | ||
* @name shipment-view.ShipmentViewLineItem | ||
* | ||
* @description | ||
* Represents a single shipment view line item. It can represent either a single lot or a | ||
* generic orderable. | ||
*/ | ||
angular | ||
.module('shipment-view') | ||
.factory('ShipmentViewLineItem', ShipmentViewLineItem); | ||
|
||
function ShipmentViewLineItem() { | ||
|
||
ShipmentViewLineItem.prototype.getAvailableSoh = getAvailableSoh; | ||
ShipmentViewLineItem.prototype.getFillQuantity = getFillQuantity; | ||
ShipmentViewLineItem.prototype.getRemainingSoh = getRemainingSoh; | ||
ShipmentViewLineItem.prototype.getOrderQuantity = getOrderQuantity; | ||
|
||
return ShipmentViewLineItem; | ||
|
||
/** | ||
* @ngdoc method | ||
* @methodOf shipment-view.ShipmentViewLineItem | ||
* @name ShipmentViewLineItem | ||
* @constructor | ||
* | ||
* @description | ||
* Creates an instance of the ShipmentViewLineItem. | ||
* | ||
* @param {Object} config configuration object used when creating new instance of the class | ||
*/ | ||
function ShipmentViewLineItem(config) { | ||
this.productCode = config.productCode; | ||
this.productName = config.productName; | ||
this.lot = config.lot; | ||
this.vvmStatus = config.vvmStatus; | ||
this.shipmentLineItem = config.shipmentLineItem; | ||
this.netContent = config.netContent; | ||
this.isLot = true; | ||
this.orderQuantity = config.orderQuantity; | ||
} | ||
|
||
/** | ||
* @ngdoc method | ||
* @methodOf shipment-view.ShipmentViewLineItem | ||
* @name getAvailableSoh | ||
* | ||
* @description | ||
* Returns available stock on hand for the commodity type or lot. | ||
* | ||
* @return {number} the available stock on hand for the specific commodity type or | ||
* lot | ||
*/ | ||
function getAvailableSoh() { | ||
return this.shipmentLineItem.stockOnHand; | ||
} | ||
|
||
/** | ||
* @ngdoc method | ||
* @methodOf shipment-view.ShipmentViewLineItem | ||
* @name getFillQuantity | ||
* | ||
* @description | ||
* Returns available stock on hand for the commodity type or lot. | ||
* | ||
* @return {number} the fill quantity for the specific commodity type or lot | ||
*/ | ||
function getFillQuantity() { | ||
return this.shipmentLineItem.quantityShipped || 0; | ||
} | ||
|
||
/** | ||
* @ngdoc method | ||
* @methodOf shipment-view.ShipmentViewLineItem | ||
* @name getRemainingSoh | ||
* | ||
* @description | ||
* Returns the remaining stock after fulfilling the order for a specific commodity type or | ||
* lot | ||
* | ||
* @return {number} the remaining stock after fulfilling the order for a specific | ||
* commodity type or lot | ||
*/ | ||
function getRemainingSoh() { | ||
return this.getAvailableSoh() - this.getFillQuantity(); | ||
} | ||
|
||
/** | ||
* @ngdoc method | ||
* @methodOf shipment-view.ShipmentViewLineItem | ||
* @name getOrderQuantity | ||
* | ||
* @description | ||
* Returns an ordered quantity for the commodity type related with the line item. | ||
* | ||
* @return {number} the ordered quantity for the commodity type related with the | ||
* line item | ||
*/ | ||
function getOrderQuantity() { | ||
if (this.orderQuantity === undefined || this.orderQuantity === null) { | ||
return; | ||
} | ||
return this.orderQuantity; | ||
} | ||
} | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* This program is part of the OpenLMIS logistics management information system platform software. | ||
* Copyright © 2017 VillageReach | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under the terms | ||
* of the GNU Affero General Public License as published by the Free Software Foundation, either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU Affero General Public License for more details. You should have received a copy of | ||
* the GNU Affero General Public License along with this program. If not, see | ||
* http://www.gnu.org/licenses. For additional information contact [email protected]. | ||
*/ | ||
|
||
describe('ShipmentViewLineItem', function() { | ||
|
||
var shipmentViewLineItem, ShipmentViewLineItem, OrderableDataBuilder, orderable; | ||
|
||
beforeEach(function() { | ||
module('shipment-view'); | ||
|
||
inject(function($injector) { | ||
ShipmentViewLineItem = $injector.get('ShipmentViewLineItem'); | ||
OrderableDataBuilder = $injector.get('OrderableDataBuilder'); | ||
}); | ||
|
||
orderable = new OrderableDataBuilder() | ||
.withNetContent(5) | ||
.buildJson(); | ||
|
||
shipmentViewLineItem = new ShipmentViewLineItem(orderable); | ||
}); | ||
|
||
describe('constructor', function() { | ||
|
||
it('should set net content', function() { | ||
var result = new ShipmentViewLineItem(orderable); | ||
|
||
expect(result.netContent).toEqual(orderable.netContent); | ||
}); | ||
|
||
}); | ||
|
||
describe('getRemainingSoh', function() { | ||
|
||
beforeEach(function() { | ||
spyOn(shipmentViewLineItem, 'getAvailableSoh'); | ||
spyOn(shipmentViewLineItem, 'getFillQuantity'); | ||
}); | ||
|
||
it('should return quantity in packs by default', function() { | ||
shipmentViewLineItem.getAvailableSoh.andReturn(160); | ||
shipmentViewLineItem.getFillQuantity.andReturn(33); | ||
|
||
var result = shipmentViewLineItem.getRemainingSoh(); | ||
|
||
expect(result).toEqual(127); | ||
}); | ||
}); | ||
|
||
describe('getOrderQuantity', function() { | ||
|
||
it('should return 0 if order quantity is equal to zero', function() { | ||
var lineItem = new ShipmentViewLineItem({ | ||
orderQuantity: 0, | ||
lineItems: [] | ||
}); | ||
|
||
var result = lineItem.getOrderQuantity(false); | ||
|
||
expect(result).toBe(0); | ||
}); | ||
|
||
it('should return undefined if order quantity is undefined', function() { | ||
var lineItem = new ShipmentViewLineItem({ | ||
lineItems: [] | ||
}); | ||
|
||
var result = lineItem.getOrderQuantity(false); | ||
|
||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
it('should return undefined if order quantity is null', function() { | ||
var lineItem = new ShipmentViewLineItem({ | ||
orderQuantity: null, | ||
lineItems: [] | ||
}); | ||
|
||
var result = lineItem.getOrderQuantity(false); | ||
|
||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
}); | ||
|
||
}); |
Oops, something went wrong.