@darkpos/pricing 1.0.64 → 1.0.66

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.
@@ -146,4 +146,222 @@ describe('getModifierTags Function', () => {
146
146
  },
147
147
  ]);
148
148
  });
149
+
150
+ test('get group modifiers including Payment modifiers', () => {
151
+ const item = {
152
+ modifiers: [
153
+ {
154
+ _id: '67d9b80aefebb298f78a9045',
155
+ attributes: ['group'],
156
+ modifierId: '62cdbfd01ee1b4001932816a',
157
+ _parentId: null,
158
+ locked: null,
159
+ name: 'White',
160
+ sku: '',
161
+ description: 'Color: White',
162
+ group: 'Color',
163
+ type: null,
164
+ tags: ['default', 'all'],
165
+ order: null,
166
+ included: false,
167
+ direct: true,
168
+ hidden: false,
169
+ print: false,
170
+ required: true,
171
+ recommended: false,
172
+ default: false,
173
+ code: null,
174
+ properties: {
175
+ override: null,
176
+ group: {
177
+ displayType: 'card',
178
+ includeInGroup: true,
179
+ singleValue: true,
180
+ compact: true,
181
+ enableAutoPopup: false,
182
+ displayReplacePrompt: true,
183
+ promptMessage: '',
184
+ modifiers: [],
185
+ items: [],
186
+ values: ['RegularItem'],
187
+ manualModifiers: 'test1, asd,123',
188
+ },
189
+ sort: null,
190
+ label: {
191
+ text: 'White Label',
192
+ align: 'center',
193
+ backgroundColor: 'rgba(76,175,80,1)',
194
+ },
195
+ color: 'rgba(0,150,136,1)',
196
+ },
197
+ _computed: {
198
+ amount: 0,
199
+ description: 'White',
200
+ },
201
+ conditions: {
202
+ valid: true,
203
+ rules: [],
204
+ },
205
+ compute: null,
206
+ _createdAt: '2025-03-18T18:15:35.300Z',
207
+ _updatedAt: '2025-03-18T18:15:35.300Z',
208
+ __typename: 'Modifier',
209
+ addModifiers: [],
210
+ delModifiers: [],
211
+ },
212
+ {
213
+ _id: '67d9b810efebb298f78a9046',
214
+ attributes: [],
215
+ modifierId: '670d7f7e746d1ae0f847aba6',
216
+ _parentId: null,
217
+ locked: false,
218
+ name: 'CASH 20% DISCOUNT',
219
+ sku: '',
220
+ description: '',
221
+ group: 'Offers',
222
+ type: 'discount',
223
+ tags: ['default', 'all'],
224
+ order: null,
225
+ included: false,
226
+ direct: true,
227
+ hidden: false,
228
+ print: true,
229
+ required: false,
230
+ recommended: false,
231
+ default: false,
232
+ code: '',
233
+ properties: {
234
+ override: null,
235
+ sort: null,
236
+ },
237
+ _computed: {
238
+ amount: 0,
239
+ description: 'CASH 20% DISCOUNT',
240
+ },
241
+ conditions: {
242
+ valid: false,
243
+ rules: [
244
+ {
245
+ key: 'paymentMethods',
246
+ value: ['cash-cash'],
247
+ operand: '$in',
248
+ },
249
+ {
250
+ key: 'paymentTypes',
251
+ value: ['cash'],
252
+ operand: '$in',
253
+ },
254
+ ],
255
+ },
256
+ compute: {
257
+ type: 'percentage',
258
+ action: 'subtract',
259
+ amount: 20,
260
+ },
261
+ _createdAt: '2025-03-18T18:15:35.300Z',
262
+ _updatedAt: '2025-03-18T18:15:35.300Z',
263
+ __typename: 'Modifier',
264
+ addModifiers: [],
265
+ delModifiers: [],
266
+ },
267
+ {
268
+ name: 'CRC 5.10 discount',
269
+ sku: '',
270
+ description: '',
271
+ group: '',
272
+ type: 'discount',
273
+ attributes: [],
274
+ color: '',
275
+ backgroundColor: '',
276
+ icon: '',
277
+ url: '',
278
+ code: '',
279
+ tags: [],
280
+ order: 0,
281
+ included: false,
282
+ direct: true,
283
+ hidden: false,
284
+ required: false,
285
+ print: true,
286
+ delModifiers: [],
287
+ addModifiers: [],
288
+ conditions: null,
289
+ compute: {
290
+ action: 'subtract',
291
+ amount: 5.1,
292
+ type: 'fixed',
293
+ },
294
+ properties: {
295
+ override: null,
296
+ sort: null,
297
+ isCalculatedPaymentModifier: true,
298
+ },
299
+ _id: '67d9b8dee71fee48f592ce3a',
300
+ modifierId: '670d7f7e746d1ae0f847aba6',
301
+ __typename: 'Modifier',
302
+ _parentId: '67d9b810efebb298f78a9046',
303
+ _computed: {
304
+ amount: -5.1,
305
+ description: 'CRC 5.10 discount (-CRC 5.10)',
306
+ },
307
+ locked: false,
308
+ },
309
+ {
310
+ _id: '67d9b8470d733f348225eeac',
311
+ attributes: [],
312
+ modifierId: '670d7f7e746d1ae0f847aba6',
313
+ _parentId: '67d9b810efebb298f78a9046',
314
+ locked: true,
315
+ name: 'CRC 37.50 discount',
316
+ sku: '',
317
+ description: '',
318
+ group: '',
319
+ type: 'discount',
320
+ tags: [],
321
+ order: 0,
322
+ included: false,
323
+ direct: true,
324
+ hidden: false,
325
+ print: true,
326
+ required: false,
327
+ recommended: false,
328
+ default: false,
329
+ code: '',
330
+ properties: {
331
+ override: null,
332
+ sort: null,
333
+ isCalculatedPaymentModifier: true,
334
+ paymentId: '67d9b846837593e11861065d',
335
+ },
336
+ _computed: {
337
+ amount: -37.5,
338
+ description: 'CRC 37.50 discount (-CRC 37.50)',
339
+ },
340
+ conditions: {
341
+ valid: true,
342
+ },
343
+ compute: {
344
+ type: 'fixed',
345
+ action: 'subtract',
346
+ amount: 37.5,
347
+ },
348
+ _createdAt: '2025-03-18T18:15:35.300Z',
349
+ _updatedAt: '2025-03-18T18:15:35.300Z',
350
+ __typename: 'Modifier',
351
+ addModifiers: [],
352
+ delModifiers: [],
353
+ },
354
+ ],
355
+ };
356
+
357
+ const result = pricingServiceGroupModifiers.item.getModifierTags({ item });
358
+
359
+ expect(result).toHaveLength(2);
360
+ expect(result[0].label.replace(/\s/g, '')).toEqual(
361
+ '1CRC5.10discount(-CRC5.10)'
362
+ );
363
+ expect(result[1].label.replace(/\s/g, '')).toEqual(
364
+ '1CRC37.50discount(-CRC37.50)'
365
+ );
366
+ });
149
367
  });
@@ -1,10 +1,10 @@
1
- const getGroupedModifiersFunction = require('../../lib/modifier/getGroupedModifiers');
1
+ const usePricing = require('../../index');
2
2
 
3
- describe('getGroupedModifiers Function', () => {
4
- const getGroupedModifiers = getGroupedModifiersFunction();
3
+ const pricingService = usePricing();
5
4
 
5
+ describe('pricingService.modifier.getGroupedModifiers Function', () => {
6
6
  test('should return an empty array if no tags are provided', () => {
7
- const result = getGroupedModifiers([]);
7
+ const result = pricingService.modifier.getGroupedModifiers([]);
8
8
  expect(result).toEqual([]);
9
9
  });
10
10
 
@@ -15,7 +15,7 @@ describe('getGroupedModifiers Function', () => {
15
15
  { label: 'Modifier 1', data: { modifierId: 'mod1' }, quantity: 1 },
16
16
  ];
17
17
 
18
- const result = getGroupedModifiers(tags);
18
+ const result = pricingService.modifier.getGroupedModifiers(tags);
19
19
 
20
20
  expect(result).toEqual([
21
21
  { label: '2 Modifier 1', data: { modifierId: 'mod1' }, quantity: 2 },
@@ -29,7 +29,7 @@ describe('getGroupedModifiers Function', () => {
29
29
  { label: 'Modifier 2', data: { modifierId: 'mod2' }, quantity: 1 },
30
30
  ];
31
31
 
32
- const result = getGroupedModifiers(tags);
32
+ const result = pricingService.modifier.getGroupedModifiers(tags);
33
33
 
34
34
  expect(result).toEqual([
35
35
  { label: '1 Modifier 1', data: { modifierId: 'mod1' }, quantity: 1 },
@@ -45,7 +45,7 @@ describe('getGroupedModifiers Function', () => {
45
45
 
46
46
  const originalTagsCopy = [...tags];
47
47
 
48
- getGroupedModifiers(tags);
48
+ pricingService.modifier.getGroupedModifiers(tags);
49
49
 
50
50
  expect(tags).toEqual(originalTagsCopy); // Ensure original array is not mutated
51
51
  });
@@ -56,7 +56,7 @@ describe('getGroupedModifiers Function', () => {
56
56
  { label: 'Modifier 1', data: { modifierId: 'mod1' }, quantity: 1 },
57
57
  ];
58
58
 
59
- const result = getGroupedModifiers(tags);
59
+ const result = pricingService.modifier.getGroupedModifiers(tags);
60
60
 
61
61
  expect(result).toEqual([
62
62
  { label: '2 Modifier 1', data: { modifierId: 'mod1' }, quantity: 2 },
@@ -55,7 +55,21 @@ describe('Order actions', () => {
55
55
  expect(cashPercentageDiscountOrder).toHaveProperty('subTotals', {
56
56
  discount: -1,
57
57
  });
58
- expect(cashPercentageDiscountOrder.items[0].modifiers).toHaveLength(1);
58
+ expect(cashPercentageDiscountOrder.items[0].modifiers).toHaveLength(2);
59
+
60
+ expect(cashPercentageDiscountOrder.items[0].modifiers[0]._computed).toEqual(
61
+ expect.objectContaining({
62
+ amount: 0,
63
+ description: 'CASH 10% DISCOUNT',
64
+ })
65
+ );
66
+
67
+ expect(cashPercentageDiscountOrder.items[0].modifiers[1]._computed).toEqual(
68
+ expect.objectContaining({
69
+ amount: -1,
70
+ description: '$1.00 discount (-$1.00)',
71
+ })
72
+ );
59
73
 
60
74
  expect(cashPercentageDiscountOrder.items[0].modifiers[0]._computed).toEqual(
61
75
  expect.objectContaining({
@@ -211,7 +225,7 @@ describe('Order actions', () => {
211
225
  expect(cashFixedDiscountOrder).toHaveProperty('subTotals', {
212
226
  discount: -2,
213
227
  });
214
- expect(cashFixedDiscountOrder.items[0].modifiers).toHaveLength(1);
228
+ expect(cashFixedDiscountOrder.items[0].modifiers).toHaveLength(2);
215
229
 
216
230
  cashFixedDiscountOrder = pricingService.order.calculate(
217
231
  { items: [orderItem] },
@@ -301,7 +315,7 @@ describe('Order actions', () => {
301
315
  expect(cashFixedDiscountOrder).toHaveProperty('subTotals', {
302
316
  fee: 2,
303
317
  });
304
- expect(cashFixedDiscountOrder.items[0].modifiers).toHaveLength(1);
318
+ expect(cashFixedDiscountOrder.items[0].modifiers).toHaveLength(2);
305
319
 
306
320
  cashFixedDiscountOrder = pricingService.order.calculate(
307
321
  { items: [orderItem] },
@@ -464,7 +478,7 @@ describe('Order actions', () => {
464
478
  fee: 0.675,
465
479
  });
466
480
 
467
- expect(testOrder.items[0].modifiers).toHaveLength(2);
481
+ expect(testOrder.items[0].modifiers).toHaveLength(3);
468
482
 
469
483
  expect(testOrder.items[0].modifiers[0]._computed).toEqual(
470
484
  expect.objectContaining({
@@ -924,7 +938,7 @@ describe('Order actions', () => {
924
938
  attributes: [],
925
939
  modifierId: '670d7f7e746d1ae0f847aba6',
926
940
  _parentId: '671818d60e5dd150d983090a',
927
- locked: false,
941
+ locked: true,
928
942
  name: '$2.59 discount',
929
943
  sku: '',
930
944
  description: '',
@@ -1091,7 +1105,7 @@ describe('Order actions', () => {
1091
1105
  tax: 0.675,
1092
1106
  });
1093
1107
 
1094
- expect(resultedOrder.items[0].modifiers).toHaveLength(6);
1108
+ expect(resultedOrder.items[0].modifiers).toHaveLength(7);
1095
1109
 
1096
1110
  expect(resultedOrder.items[0].modifiers[0]._computed).toEqual(
1097
1111
  expect.objectContaining({
@@ -29,9 +29,15 @@ module.exports = ({ _, utils, actions, modifierActions }) => {
29
29
  subTotals._simple = math.mul(price, quantity);
30
30
 
31
31
  const modifiers = [];
32
- const { modifiers: itemModifiers = [] } =
32
+ const { modifiers: itemModifiersPrev = [] } =
33
33
  actions.removeModifiersByQuantity(item);
34
34
 
35
+ const itemModifiers = [...itemModifiersPrev].filter(
36
+ mod =>
37
+ !modifierActions.isCalculatedPaymentModifier(mod) ||
38
+ modifierActions.isLocked(mod)
39
+ );
40
+
35
41
  const validatedModifiers = itemModifiers.map(each =>
36
42
  modifierActions.validate(each, {
37
43
  item,
@@ -143,10 +149,9 @@ module.exports = ({ _, utils, actions, modifierActions }) => {
143
149
  }
144
150
  );
145
151
 
146
- if (
147
- !modifierActions.isPaymentModifier(modifier) ||
148
- lockPaymentModifiers
149
- ) {
152
+ if (modifierActions.isPaymentModifier(modifier)) {
153
+ modifiers.push({ ..._modifier, locked: !!lockPaymentModifiers });
154
+ } else {
150
155
  modifiers.push(_modifier);
151
156
  }
152
157
 
@@ -1,5 +1,9 @@
1
1
  module.exports = ({ modifierActions, settings }) =>
2
- function getModifierTags({ item, skipGrouping = false }) {
2
+ function getModifierTags({
3
+ item,
4
+ includePaymentModifiers,
5
+ skipGrouping = false,
6
+ }) {
3
7
  const groupModifiers =
4
8
  settings && settings.order && settings.order.groupModifiers;
5
9
 
@@ -7,7 +11,11 @@ module.exports = ({ modifierActions, settings }) =>
7
11
 
8
12
  let modifierTags = item.modifiers
9
13
  .filter(
10
- each => modifierActions.isValid(each) && !modifierActions.isGroup(each)
14
+ each =>
15
+ (modifierActions.isValid(each) ||
16
+ (modifierActions.isPaymentModifier(each) &&
17
+ includePaymentModifiers)) &&
18
+ !modifierActions.isGroup(each)
11
19
  )
12
20
  .map(modifier => {
13
21
  const { name, _id } = modifier;
@@ -1,9 +1,11 @@
1
- module.exports = () =>
1
+ module.exports = ({ actions }) =>
2
2
  function getGroupedModifiers(tags) {
3
3
  return tags
4
4
  .reduce((acc, curr) => {
5
5
  const found = acc.find(
6
- item => item.data.modifierId === curr.data.modifierId
6
+ item =>
7
+ item.data.modifierId === curr.data.modifierId &&
8
+ !actions.isCalculatedPaymentModifier(curr.data)
7
9
  );
8
10
 
9
11
  if (found) {
@@ -140,6 +140,7 @@ const isFixedSubtract = require('./isFixedSubtract');
140
140
  const isQuantityMultiplier = require('./isQuantityMultiplier');
141
141
  const isCompute = require('./isCompute');
142
142
  const isFixedOverride = require('./isFixedOverride');
143
+ const isLocked = require('./isLocked');
143
144
 
144
145
  const modifierActions = (deps = {}) => {
145
146
  const actions = {};
@@ -293,6 +294,7 @@ const modifierActions = (deps = {}) => {
293
294
  isQuantityMultiplier: isQuantityMultiplier(innerDeps),
294
295
  isCompute: isCompute(innerDeps),
295
296
  isFixedOverride: isFixedOverride(innerDeps),
297
+ isLocked: isLocked(innerDeps),
296
298
  });
297
299
 
298
300
  Object.keys(freezedActions).forEach(actionName => {
@@ -0,0 +1,6 @@
1
+ module.exports = () =>
2
+ function isLocked(modifier) {
3
+ if (!modifier) return false;
4
+
5
+ return modifier.locked;
6
+ };
@@ -1,14 +1,7 @@
1
1
  module.exports = ({ utils, _, settings }) => {
2
2
  const orderSettings = _.get(settings, 'order');
3
- const { date, helpers } = utils;
4
- const noteDefaults = {
5
- message: '',
6
- attributes: [],
7
- date: date.toISOString(),
8
- user: null,
9
- url: '',
10
- __typename: 'Note',
11
- };
3
+ const { helpers } = utils;
4
+
12
5
  const getSubOrder =
13
6
  ({ order }) =>
14
7
  (items, index) => {
@@ -35,13 +28,7 @@ module.exports = ({ utils, _, settings }) => {
35
28
  parentId: orderSettings.allowSuborder ? order._id : null,
36
29
  items,
37
30
  modifiers: [],
38
- notes: [
39
- ...(order.notes || []),
40
- {
41
- ...noteDefaults,
42
- message: `Suborder from ${order.displayId}`, // ask about this message
43
- },
44
- ],
31
+ notes: order.notes || [],
45
32
  };
46
33
  };
47
34
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darkpos/pricing",
3
- "version": "1.0.64",
3
+ "version": "1.0.66",
4
4
  "description": "Pricing calculator",
5
5
  "author": "Dark POS",
6
6
  "license": "ISC",
@@ -23,6 +23,7 @@
23
23
  "test:conditionsNotMet": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/order/conditionsNotMet.test.js",
24
24
  "test:pickEndDate": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/order/pickEndDate.test.js",
25
25
  "test:modifier": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/modifier.test.js",
26
+ "test:paymentModifiers": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/order/order-payment-modifier.test.js",
26
27
  "lint": "eslint --quiet lib/"
27
28
  },
28
29
  "publishConfig": {
@@ -46,5 +47,5 @@
46
47
  "supertest": "^6.2.3",
47
48
  "supervisor": "^0.12.0"
48
49
  },
49
- "gitHead": "000ac6a4b480b4a219b1411d29cbd74f86aa9716"
50
+ "gitHead": "d007d8455487fed168f127c6b338dc4301a7da79"
50
51
  }