Skip to content
This repository was archived by the owner on Jan 14, 2020. It is now read-only.

Commit 3cdcd24

Browse files
authored
Merge pull request #36 from fielded/feat/product-supply-plan
Allow per-product supply plan
2 parents 5c69f80 + 14b02dc commit 3cdcd24

File tree

5 files changed

+33
-15
lines changed

5 files changed

+33
-15
lines changed

Diff for: dist/bundle.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@
139139
if (!(plans && plans.weeksOfStock)) {
140140
throw new Error('cannot find version of weeksOfStock for location ' + location._id + ' and date ' + date);
141141
}
142-
return plans.weeksOfStock;
142+
143+
return plans;
143144
};
144145

145146
var getTargetPopulations = function getTargetPopulations(location, date) {
@@ -194,7 +195,7 @@
194195
if (version === 1) {
195196
return {
196197
weeklyLevels: getWeeklyLevels(location, date),
197-
weeksOfStock: weeksOfStock,
198+
supplyPlan: weeksOfStock,
198199
monthlyTargetPopulations: monthlyTargetPopulations
199200
};
200201
}
@@ -204,7 +205,7 @@
204205

205206
return {
206207
weeklyLevels: weeklyLevels,
207-
weeksOfStock: weeksOfStock,
208+
supplyPlan: weeksOfStock,
208209
monthlyTargetPopulations: monthlyTargetPopulations
209210
};
210211
});
@@ -266,7 +267,7 @@
266267
}
267268

268269
var _locationFactors = locationFactors,
269-
weeksOfStock = _locationFactors.weeksOfStock,
270+
supplyPlan = _locationFactors.supplyPlan,
270271
weeklyLevels = _locationFactors.weeklyLevels,
271272
monthlyTargetPopulations = _locationFactors.monthlyTargetPopulations;
272273

@@ -283,8 +284,15 @@
283284
presentation = parseInt(product.presentation, 10);
284285
}
285286

286-
index[productId] = Object.keys(weeksOfStock).reduce(function (productThresholds, threshold) {
287-
var level = weeklyLevel * weeksOfStock[threshold];
287+
// Original version 1 plans only allow
288+
// one supply plan for all products
289+
var productPlan = supplyPlan.weeksOfStock;
290+
if (supplyPlan.version === 2) {
291+
productPlan = supplyPlan.products[productId];
292+
}
293+
294+
index[productId] = Object.keys(productPlan).reduce(function (productThresholds, threshold) {
295+
var level = weeklyLevel * productPlan[threshold];
288296
var roundedLevel = Math.ceil(level / presentation) * presentation;
289297
productThresholds[threshold] = roundedLevel;
290298

Diff for: dist/bundle.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)