@merchi/sdk 1.42.31 → 1.42.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/pricing/estimate.js
CHANGED
|
@@ -272,6 +272,7 @@ export function estimateQuote(rules, selections) {
|
|
|
272
272
|
return { unsupported: rules.unsupported };
|
|
273
273
|
}
|
|
274
274
|
var groupCosts = [];
|
|
275
|
+
var groupUnitPrices = [];
|
|
275
276
|
var cost = 0;
|
|
276
277
|
var costPerUnit;
|
|
277
278
|
var groupQuantities;
|
|
@@ -287,12 +288,11 @@ export function estimateQuote(rules, selections) {
|
|
|
287
288
|
var totalQty = groupQuantities.reduce(function (a, b) { return a + b; }, 0);
|
|
288
289
|
var restricted = Boolean((_d = rules.product.discountGroup) === null || _d === void 0 ? void 0 : _d.groupRestricted);
|
|
289
290
|
var baseUnitPrice = unitPriceAt(rules, totalQty);
|
|
290
|
-
var perGroupCpu = [];
|
|
291
291
|
for (var gi = 0; gi < groups.length; gi++) {
|
|
292
292
|
var group = groups[gi];
|
|
293
293
|
var gQty = groupQuantities[gi];
|
|
294
294
|
var cpu = restricted ? unitPriceAt(rules, gQty) : baseUnitPrice;
|
|
295
|
-
|
|
295
|
+
groupUnitPrices.push(cpu);
|
|
296
296
|
// Server `VariationsGroups.update_cost` (variations_groups.py ~238):
|
|
297
297
|
// `if not self.quantity: self.group_cost = 0; return` — a zero-qty group
|
|
298
298
|
// contributes exactly 0 and adds NO field/variation costs.
|
|
@@ -330,7 +330,7 @@ export function estimateQuote(rules, selections) {
|
|
|
330
330
|
cost += groupCost;
|
|
331
331
|
}
|
|
332
332
|
costPerUnit = totalQty > 0
|
|
333
|
-
?
|
|
333
|
+
? groupUnitPrices.reduce(function (acc, cpu, i) { return acc + cpu * groupQuantities[i]; }, 0) / totalQty
|
|
334
334
|
: baseUnitPrice;
|
|
335
335
|
// Independent (job-level) field visibility is scoped to independent
|
|
336
336
|
// selections only (server `Jobs.selected_options` = job.variations,
|
|
@@ -419,6 +419,7 @@ export function estimateQuote(rules, selections) {
|
|
|
419
419
|
// `result["groupCost"] = self.group_cost` is serialized UNROUNDED
|
|
420
420
|
// (variations_groups.py ~154); round to 3dp to match the Numeric scale.
|
|
421
421
|
groupCosts: groupCosts.map(function (c) { return roundHalfEven(c, 3); }),
|
|
422
|
+
groupUnitPrices: groupUnitPrices.map(function (price) { return roundHalfEven(price, 3); }),
|
|
422
423
|
currency: rules.currency,
|
|
423
424
|
};
|
|
424
425
|
}
|
|
@@ -239,6 +239,17 @@ test('group product: weighted unit price and summed group costs', function () {
|
|
|
239
239
|
expect(r.groupCosts).toEqual([30, 70]);
|
|
240
240
|
expect(r.costPerUnit).toBe(10);
|
|
241
241
|
});
|
|
242
|
+
test('group-restricted tiers return each base rate independently of setup and the weighted average', function () {
|
|
243
|
+
var rules = __assign(__assign({}, base), { hasGroups: true, product: {
|
|
244
|
+
unitPrice: 0.52, setupPerGroup: true, setupPrice: 5, minimumPrice: null,
|
|
245
|
+
discountGroup: { groupRestricted: true, discounts: [{ lowerLimit: 150, amount: 20.8 }] },
|
|
246
|
+
} });
|
|
247
|
+
var quote = estimateQuote(rules, {
|
|
248
|
+
fieldValues: {}, groups: [149, 150].map(function (quantity) { return ({ quantity: quantity, fieldValues: {} }); }),
|
|
249
|
+
});
|
|
250
|
+
expect(quote.groupUnitPrices).toEqual([0.52, 0.412]);
|
|
251
|
+
expect(quote.groupCosts).toEqual([82.48, 66.8]);
|
|
252
|
+
});
|
|
242
253
|
test('product setupPrice applied once to job', function () {
|
|
243
254
|
var rules = __assign(__assign({}, base), { product: {
|
|
244
255
|
unitPrice: 10, minimumPrice: null, setupPrice: 25,
|
package/dist/pricing/types.d.ts
CHANGED
|
@@ -103,6 +103,8 @@ export interface QuoteResult {
|
|
|
103
103
|
taxAmount: number;
|
|
104
104
|
totalCost: number;
|
|
105
105
|
groupCosts: number[];
|
|
106
|
+
/** Base rates by variation group, before option and setup charges. */
|
|
107
|
+
groupUnitPrices?: number[];
|
|
106
108
|
currency: string;
|
|
107
109
|
}
|
|
108
110
|
export interface UnsupportedResult {
|
package/package.json
CHANGED
|
@@ -299,6 +299,21 @@ test('group product: weighted unit price and summed group costs', () => {
|
|
|
299
299
|
expect(r.costPerUnit).toBe(10);
|
|
300
300
|
});
|
|
301
301
|
|
|
302
|
+
test('group-restricted tiers return each base rate independently of setup and the weighted average', () => {
|
|
303
|
+
const rules: PricingRules = {
|
|
304
|
+
...base, hasGroups: true,
|
|
305
|
+
product: {
|
|
306
|
+
unitPrice: 0.52, setupPerGroup: true, setupPrice: 5, minimumPrice: null,
|
|
307
|
+
discountGroup: { groupRestricted: true, discounts: [{ lowerLimit: 150, amount: 20.8 }] },
|
|
308
|
+
},
|
|
309
|
+
};
|
|
310
|
+
const quote = estimateQuote(rules, {
|
|
311
|
+
fieldValues: {}, groups: [149, 150].map(quantity => ({ quantity, fieldValues: {} })),
|
|
312
|
+
}) as QuoteResult;
|
|
313
|
+
expect(quote.groupUnitPrices).toEqual([0.52, 0.412]);
|
|
314
|
+
expect(quote.groupCosts).toEqual([82.48, 66.8]);
|
|
315
|
+
});
|
|
316
|
+
|
|
302
317
|
test('product setupPrice applied once to job', () => {
|
|
303
318
|
const rules: PricingRules = {
|
|
304
319
|
...base,
|
package/src/pricing/estimate.ts
CHANGED
|
@@ -305,6 +305,7 @@ export function estimateQuote(
|
|
|
305
305
|
}
|
|
306
306
|
|
|
307
307
|
const groupCosts: number[] = [];
|
|
308
|
+
const groupUnitPrices: number[] = [];
|
|
308
309
|
let cost = 0;
|
|
309
310
|
let costPerUnit: number;
|
|
310
311
|
let groupQuantities: number[];
|
|
@@ -321,13 +322,12 @@ export function estimateQuote(
|
|
|
321
322
|
const totalQty = groupQuantities.reduce((a, b) => a + b, 0);
|
|
322
323
|
const restricted = Boolean(rules.product.discountGroup?.groupRestricted);
|
|
323
324
|
const baseUnitPrice = unitPriceAt(rules, totalQty);
|
|
324
|
-
const perGroupCpu: number[] = [];
|
|
325
325
|
|
|
326
326
|
for (let gi = 0; gi < groups.length; gi++) {
|
|
327
327
|
const group = groups[gi];
|
|
328
328
|
const gQty = groupQuantities[gi];
|
|
329
329
|
const cpu = restricted ? unitPriceAt(rules, gQty) : baseUnitPrice;
|
|
330
|
-
|
|
330
|
+
groupUnitPrices.push(cpu);
|
|
331
331
|
// Server `VariationsGroups.update_cost` (variations_groups.py ~238):
|
|
332
332
|
// `if not self.quantity: self.group_cost = 0; return` — a zero-qty group
|
|
333
333
|
// contributes exactly 0 and adds NO field/variation costs.
|
|
@@ -355,7 +355,7 @@ export function estimateQuote(
|
|
|
355
355
|
}
|
|
356
356
|
|
|
357
357
|
costPerUnit = totalQty > 0
|
|
358
|
-
?
|
|
358
|
+
? groupUnitPrices.reduce((acc, cpu, i) => acc + cpu * groupQuantities[i], 0) / totalQty
|
|
359
359
|
: baseUnitPrice;
|
|
360
360
|
|
|
361
361
|
// Independent (job-level) field visibility is scoped to independent
|
|
@@ -422,6 +422,7 @@ export function estimateQuote(
|
|
|
422
422
|
// `result["groupCost"] = self.group_cost` is serialized UNROUNDED
|
|
423
423
|
// (variations_groups.py ~154); round to 3dp to match the Numeric scale.
|
|
424
424
|
groupCosts: groupCosts.map((c) => roundHalfEven(c, 3)),
|
|
425
|
+
groupUnitPrices: groupUnitPrices.map((price) => roundHalfEven(price, 3)),
|
|
425
426
|
currency: rules.currency,
|
|
426
427
|
};
|
|
427
428
|
}
|
package/src/pricing/types.ts
CHANGED