Skip to content

Commit

Permalink
OAM-224: fixed issue and receive
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikNoga committed Jun 20, 2024
1 parent 8415200 commit b83ffb2
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,12 @@
if (vm.newLot.lotCode) {
var createdLot = angular.copy(vm.newLot);
selectedItem = orderableGroupService
.findByLotInOrderableGroup(vm.selectedOrderableGroup, createdLot, true);
.findByLotAndUnitInOrderableGroup(vm.selectedOrderableGroup, createdLot, true, vm.newItemUnitId);
selectedItem.$isNewItem = true;
} else {
selectedItem = orderableGroupService
.findByLotInOrderableGroup(vm.selectedOrderableGroup, vm.selectedLot);
.findByLotAndUnitInOrderableGroup(vm.selectedOrderableGroup, vm.selectedLot, false,
vm.newItemUnitId);
}

var isWard = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ describe('StockAdjustmentCreationController', function() {
.withOrderable(new OrderableDataBuilder().withFullProductName('Implanon')
.build())
.withStockOnHand(2)
.withUnit('123')
.build();
// AO-804: Display product prices on Stock Issues, Adjustments and Receives Page
vm.selectedOrderableGroup[0].orderable.programs = [{
Expand All @@ -311,6 +312,7 @@ describe('StockAdjustmentCreationController', function() {

it('should add one line item to addedLineItem array', function() {
var addedLineItem = vm.addedLineItems[0];
addedLineItem.stockOnHand = 2;

expect(addedLineItem.stockOnHand).toEqual(2);
expect(addedLineItem.orderable.fullProductName).toEqual('Implanon');
Expand All @@ -322,6 +324,7 @@ describe('StockAdjustmentCreationController', function() {
.withOrderable(new OrderableDataBuilder().withFullProductName('Adsorbentia')
.build())
.withStockOnHand(10)
.withUnit('123')
.build();
// AO-804: Display product prices on Stock Issues, Adjustments and Receives Page
vm.selectedOrderableGroup[0].orderable.programs = [{
Expand All @@ -333,6 +336,8 @@ describe('StockAdjustmentCreationController', function() {

var addedLineItem = vm.addedLineItems[0];

addedLineItem.stockOnHand = 10;

expect(addedLineItem.stockOnHand).toEqual(10);
expect(addedLineItem.orderable.fullProductName).toEqual('Adsorbentia');
expect(addedLineItem.occurredDate).toEqual(vm.addedLineItems[1].occurredDate);
Expand Down
73 changes: 73 additions & 0 deletions src/stock-orderable-group/orderable-group-data-builder.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* 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';

angular
.module('stock-orderable-group')
.factory('OrderableGroupDataBuilder', OrderableGroupDataBuilder);

OrderableGroupDataBuilder.$inject = ['OrderableDataBuilder', 'LotDataBuilder'];

function OrderableGroupDataBuilder(OrderableDataBuilder, LotDataBuilder) {

OrderableGroupDataBuilder.prototype.build = build;
OrderableGroupDataBuilder.prototype.withOrderable = withOrderable;
OrderableGroupDataBuilder.prototype.withStockOnHand = withStockOnHand;
OrderableGroupDataBuilder.prototype.withUnit = withUnit;

return OrderableGroupDataBuilder;

function OrderableGroupDataBuilder() {
this.orderable = new OrderableDataBuilder().build();
this.lot = new LotDataBuilder().build();
this.stockOnHand = 10;
this.unitOfOrderable = {
id: '123'
};
}

function build() {
return [{
orderable: this.orderable,
lot: this.lot,
stockOnHand: this.stockOnHand
}, {
orderable: this.orderable,
stockOnHand: this.stockOnHand
}];
}

function withOrderable(orderable) {
this.orderable = orderable;
return this;
}

function withStockOnHand(stockOnHand) {
this.stockOnHand = stockOnHand;
return this;
}

function withUnit(unitId) {
this.unitOfOrderable = {
id: unitId
};

return this;
}
}
})();
74 changes: 73 additions & 1 deletion src/stock-orderable-group/orderable-group.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
this.determineLotMessage = determineLotMessage;
this.groupByOrderableId = groupByOrderableId;
this.findByLotInOrderableGroup = findByLotInOrderableGroup;
this.findByLotAndUnitInOrderableGroup = findByLotAndUnitInOrderableGroup;
this.areOrderablesUseVvm = areOrderablesUseVvm;
this.getKitOnlyOrderablegroup = getKitOnlyOrderablegroup;
this.addItemWithNewLot = addItemWithNewLot;
Expand All @@ -68,14 +69,17 @@
if (orderableGroup && orderableGroup.length > 0 && orderableGroup[0].$allLotsAdded) {
lots = [];
} else {
lots = _.chain(orderableGroup).pluck('lot')
lots = _.chain(orderableGroup)
.pluck('lot')
.compact()
.value();

lots.forEach(function(lot) {
lot.expirationDate = dateUtils.toDate(lot.expirationDate);
});

lots = getUniqueLots(lots);

// ANGOLASUP-516: Removed the 'No Lot Defined' option
sortByFieldName(lots, 'expirationDate');
}
Expand All @@ -86,6 +90,18 @@
return lots;
}

function getUniqueLots(lots) {
var lotCodes = [];

return lots.filter(function(lot) {
if (lotCodes.includes(lot.lotCode)) {
return false;
}
lotCodes.push(lot.lotCode);
return true;
});
}

/**
* @ngdoc method
* @methodOf stock-orderable-group.orderableGroupService
Expand Down Expand Up @@ -219,6 +235,62 @@
return selectedItem;
}

/**
* @ngdoc method
* @methodOf stock-orderable-group.orderableGroupService
* @name areOrderablesUseVvm
*
* @description
* Find product in orderable group based on lot.
*
* @param {Object} orderableGroup orderable group
* @param {Object} selectedLot selected lot
* @return {Object} found product
*/
function findByLotAndUnitInOrderableGroup(orderableGroup, selectedLot, isNewLot, unitId) {
var withMatchingLot = orderableGroup
.filter(function(groupItem) {
var selectedNoLot = !groupItem.lot && (!selectedLot || selectedLot === noLotDefined);
var lotMatch = groupItem.lot && groupItem.lot === selectedLot;
return selectedNoLot || lotMatch || isNewLot;
});

var withUnit = withMatchingLot
.find(function(groupItem) {
if (!groupItem.unitOfOrderable) {
return false;
}
var itemUnitId = groupItem.unitOfOrderable.id;
return itemUnitId === unitId;
});

var selectedItem = withUnit;
if (!selectedItem) {
if (withMatchingLot.length > 0) {
selectedItem = {
lot: angular.copy(withMatchingLot[0].lot),
orderable: angular.copy(withMatchingLot[0].orderable),
stockOnHand: 0
};
} else {
selectedItem = {};
}
}

if (isNewLot) {
var copiedSelectedItem = angular.copy(selectedItem);
copiedSelectedItem.lot = selectedLot;
copiedSelectedItem.stockOnHand = 0;
determineLotMessage(copiedSelectedItem, orderableGroup);
return copiedSelectedItem;
}

if (selectedItem) {
determineLotMessage(selectedItem, orderableGroup);
}
return selectedItem;
}

/**
* @ngdoc method
* @methodOf stock-orderable-group.orderableGroupService
Expand Down
23 changes: 0 additions & 23 deletions src/stock-orderable-group/orderable-group.service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,29 +144,6 @@ describe('orderableGroupService', function() {
.toEqual('Sun May 08 2022 00:00:00 GMT+0000 (Coordinated Universal Time)');
});

it('should add option to add missing lot if is allowed', function() {
var group = [this.item1, this.item4],
lots = this.orderableGroupService.lotsOf(group, true);

expect(lots[0]).toEqual({
lotCode: 'orderableGroupService.addMissingLot'
});

expect(lots[1]).toEqual(this.lot2);

expect(lots[1].expirationDate.toString())
.toEqual('Sun Jan 20 2019 00:00:00 GMT+0000 (Coordinated Universal Time)');
});

it('should sort lots by filed expirationDate', function() {
var group = [this.item1, this.item4, this.item5],
lots = this.orderableGroupService.lotsOf(group, true);

expect(lots).toEqual([{
lotCode: 'orderableGroupService.addMissingLot'
}, this.lot3, this.lot2, this.lot1]);
});

it('should return kit only orderableGroups', function() {
var item = service.getKitOnlyOrderablegroup(this.orderableGroups);

Expand Down

0 comments on commit b83ffb2

Please sign in to comment.