|
78 | 78 | value: function decorateWithIndicators(stockCounts) {
|
79 | 79 | var _this2 = this;
|
80 | 80 |
|
| 81 | + var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; |
| 82 | + |
81 | 83 | var lgas = void 0;
|
82 | 84 | var states = void 0;
|
83 | 85 | var zones = void 0;
|
|
99 | 101 | });
|
100 | 102 | };
|
101 | 103 |
|
102 |
| - var decorateStockField = function decorateStockField(requiredAllocations, stockCount) { |
| 104 | + var decorateStockField = function decorateStockField(stockCount, requiredAllocations) { |
103 | 105 | var location = void 0;
|
104 | 106 | if (stockCount.location.national) {
|
105 | 107 | location = national;
|
|
108 | 110 | }
|
109 | 111 |
|
110 | 112 | var locationThresholds = void 0;
|
111 |
| - if (location && location.level === 'zone') { |
| 113 | + if (location && location.level === 'zone' && requiredAllocations) { |
112 | 114 | locationThresholds = _this2.thresholdsService.calculateThresholds(location, stockCount, products, requiredAllocations[location._id]);
|
113 | 115 | } else {
|
114 | 116 | locationThresholds = _this2.thresholdsService.calculateThresholds(location, stockCount, products);
|
|
223 | 225 | states = promiseResults.states;
|
224 | 226 | zones = promiseResults.zones || []; // not available for the state dashboard
|
225 | 227 | products = promiseResults.products;
|
226 |
| - national = promiseResults.national || []; |
227 |
| - |
228 |
| - nonZoneStockCounts = nonZoneStockCounts.map(decorateStockField.bind(null, null)).map(addReStockField); |
229 |
| - zoneStockCounts = zoneStockCounts.map(decorateStockField.bind(null, _this2.stateRequiredAllocationsByZone(nonZoneStockCounts))).map(addReStockField); |
| 228 | + national = promiseResults.national || {}; |
| 229 | + |
| 230 | + nonZoneStockCounts = nonZoneStockCounts.map(function (nonZoneStockCount) { |
| 231 | + return decorateStockField(nonZoneStockCount); |
| 232 | + }).map(addReStockField); |
| 233 | + zoneStockCounts = zoneStockCounts.map(function (zoneStockCount) { |
| 234 | + if (opts.requireChildAllocations === false) { |
| 235 | + return decorateStockField(zoneStockCount); |
| 236 | + } |
| 237 | + return decorateStockField(zoneStockCount, _this2.stateRequiredAllocationsByZone(nonZoneStockCounts)); |
| 238 | + }).map(addReStockField); |
230 | 239 |
|
231 | 240 | return nonZoneStockCounts.concat(zoneStockCounts).map(addStockLevelStatusField);
|
232 | 241 | };
|
|
0 commit comments