@darkpos/pricing 1.0.39 → 1.0.41

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.
@@ -0,0 +1,73 @@
1
+ {
2
+ "location": {},
3
+ "status": {
4
+ "picked": {
5
+ "value": false,
6
+ "date": ""
7
+ },
8
+ "paid": {
9
+ "value": false,
10
+ "date": ""
11
+ },
12
+ "tracker": []
13
+ },
14
+ "name": "Dummy Pants 1",
15
+ "description": "Dummy Pants 1",
16
+ "pieces": 1,
17
+ "modifiersTotalAmount": 0,
18
+ "total": 2,
19
+ "totalPaid": 0,
20
+ "price": 2,
21
+ "quantity": 1,
22
+ "path": ",66da070aac2d4ae39904050f,66da131a81cf1303bc32a2c7,",
23
+ "notes": [],
24
+ "serial": null,
25
+ "sku": "DUN-PAN1",
26
+ "modifiers": [],
27
+ "_id": "66ec759cd57e32c3455724a0",
28
+ "weight": null,
29
+ "properties": null,
30
+ "hasInventory": true,
31
+ "inventoryType": "pull",
32
+ "category": null,
33
+ "priceLevels": [
34
+ {
35
+ "value": 10,
36
+ "tags": [
37
+ "default"
38
+ ]
39
+ },
40
+ {
41
+ "value": 2,
42
+ "tags": [
43
+ "vip"
44
+ ]
45
+ },
46
+ {
47
+ "value": 10,
48
+ "tags": [
49
+ "default",
50
+ "press only"
51
+ ]
52
+ },
53
+ {
54
+ "value": 2,
55
+ "tags": [
56
+ "vip",
57
+ "press only"
58
+ ]
59
+ }
60
+ ],
61
+ "costLevels": [],
62
+ "itemId": "66da11fdac2d4ae39904465e",
63
+ "menuRuleId": "66da132381cf1303bc32a2c8",
64
+ "__typename": "OrderItem",
65
+ "subTotals": {
66
+ "_included": 0,
67
+ "_xincluded": 0,
68
+ "_direct": 0,
69
+ "_xdirect": 0,
70
+ "_simple": 2,
71
+ "_actual": 2
72
+ }
73
+ }
@@ -0,0 +1,73 @@
1
+ {
2
+ "location": {},
3
+ "status": {
4
+ "picked": {
5
+ "value": false,
6
+ "date": ""
7
+ },
8
+ "paid": {
9
+ "value": false,
10
+ "date": ""
11
+ },
12
+ "tracker": []
13
+ },
14
+ "name": "Dummy Pants 2",
15
+ "description": "Dummy Pants 2",
16
+ "pieces": 1,
17
+ "modifiersTotalAmount": 0,
18
+ "total": 2,
19
+ "totalPaid": 0,
20
+ "price": 2,
21
+ "quantity": 1,
22
+ "path": ",66da070aac2d4ae39904050f,66da131a81cf1303bc32a2c7,",
23
+ "notes": [],
24
+ "serial": null,
25
+ "sku": "DUN-PAN2",
26
+ "modifiers": [],
27
+ "_id": "66ec759cd57e32c3455724a0",
28
+ "weight": null,
29
+ "properties": null,
30
+ "hasInventory": true,
31
+ "inventoryType": "pull",
32
+ "category": null,
33
+ "priceLevels": [
34
+ {
35
+ "value": 10,
36
+ "tags": [
37
+ "default"
38
+ ]
39
+ },
40
+ {
41
+ "value": 2,
42
+ "tags": [
43
+ "vip"
44
+ ]
45
+ },
46
+ {
47
+ "value": 10,
48
+ "tags": [
49
+ "default",
50
+ "press only"
51
+ ]
52
+ },
53
+ {
54
+ "value": 2,
55
+ "tags": [
56
+ "vip",
57
+ "press only"
58
+ ]
59
+ }
60
+ ],
61
+ "costLevels": [],
62
+ "itemId": "66da11fdac2d4ae39904465e",
63
+ "menuRuleId": "66da132381cf1303bc32a2c8",
64
+ "__typename": "OrderItem",
65
+ "subTotals": {
66
+ "_included": 0,
67
+ "_xincluded": 0,
68
+ "_direct": 0,
69
+ "_xdirect": 0,
70
+ "_simple": 2,
71
+ "_actual": 2
72
+ }
73
+ }
@@ -0,0 +1,73 @@
1
+ {
2
+ "location": {},
3
+ "status": {
4
+ "picked": {
5
+ "value": false,
6
+ "date": ""
7
+ },
8
+ "paid": {
9
+ "value": false,
10
+ "date": ""
11
+ },
12
+ "tracker": []
13
+ },
14
+ "name": "Dummy Pants 3",
15
+ "description": "Dummy Pants 3",
16
+ "pieces": 1,
17
+ "modifiersTotalAmount": 0,
18
+ "total": 2,
19
+ "totalPaid": 0,
20
+ "price": 2,
21
+ "quantity": 1,
22
+ "path": ",66da070aac2d4ae39904050f,66da131a81cf1303bc32a2c7,",
23
+ "notes": [],
24
+ "serial": null,
25
+ "sku": "DUN-PAN3",
26
+ "modifiers": [],
27
+ "_id": "66ec759cd57e32c3455724a0",
28
+ "weight": null,
29
+ "properties": null,
30
+ "hasInventory": true,
31
+ "inventoryType": "pull",
32
+ "category": null,
33
+ "priceLevels": [
34
+ {
35
+ "value": 10,
36
+ "tags": [
37
+ "default"
38
+ ]
39
+ },
40
+ {
41
+ "value": 2,
42
+ "tags": [
43
+ "vip"
44
+ ]
45
+ },
46
+ {
47
+ "value": 10,
48
+ "tags": [
49
+ "default",
50
+ "press only"
51
+ ]
52
+ },
53
+ {
54
+ "value": 2,
55
+ "tags": [
56
+ "vip",
57
+ "press only"
58
+ ]
59
+ }
60
+ ],
61
+ "costLevels": [],
62
+ "itemId": "66da11fdac2d4ae39904465e",
63
+ "menuRuleId": "66da132381cf1303bc32a2c8",
64
+ "__typename": "OrderItem",
65
+ "subTotals": {
66
+ "_included": 0,
67
+ "_xincluded": 0,
68
+ "_direct": 0,
69
+ "_xdirect": 0,
70
+ "_simple": 2,
71
+ "_actual": 2
72
+ }
73
+ }
@@ -0,0 +1,36 @@
1
+ const usePricing = require('../../index');
2
+ const mockStores = require('../mocks/stores');
3
+ const orderMock = require('../modifier/mocks/orderMock.json');
4
+ const item1Mock = require('../mocks/items/item1Mock.json');
5
+ const item2Mock = require('../mocks/items/item2Mock.json');
6
+ const item3Mock = require('../mocks/items/item3Mock.json');
7
+
8
+ const session = {
9
+ store: mockStores[0],
10
+ };
11
+
12
+ const pricingService = usePricing(session);
13
+
14
+ describe('Create suborder', () => {
15
+ test('Create a suborder with one order', () => {
16
+ const subOrders = pricingService.order.createSuborder(orderMock);
17
+ const order = {
18
+ ...orderMock,
19
+ orders: subOrders,
20
+ };
21
+ expect(order.orders).toHaveLength(1);
22
+ expect(subOrders).toHaveLength(1);
23
+ });
24
+
25
+ test('Create suborder with multiple items in the order', () => {
26
+ const multipleItemsOrderMock = {
27
+ ...orderMock,
28
+ items: [item1Mock, item2Mock, item3Mock], // assuming items is an array of items
29
+ };
30
+ const subOrders = pricingService.order.createSuborder(
31
+ multipleItemsOrderMock
32
+ );
33
+
34
+ expect(subOrders[0].items).toHaveLength(3); // Suborders should match number of items
35
+ });
36
+ });
@@ -0,0 +1,89 @@
1
+ const usePricing = require('../../index');
2
+ const mockStores = require('../mocks/stores');
3
+ const orderMock = require('../modifier/mocks/orderMock.json');
4
+
5
+ const session = {
6
+ store: mockStores[0],
7
+ };
8
+
9
+ const pricingService = usePricing(session);
10
+
11
+ const mockItem = {
12
+ location: {},
13
+ status: {
14
+ picked: {
15
+ value: false,
16
+ date: '',
17
+ },
18
+ paid: {
19
+ value: false,
20
+ date: '',
21
+ },
22
+ tracker: [],
23
+ },
24
+ name: 'Andre Pants 2',
25
+ description: 'Andre Pants 2',
26
+ pieces: 1,
27
+ modifiersTotalAmount: 0,
28
+ total: 2,
29
+ totalPaid: 0,
30
+ price: 2,
31
+ quantity: 1,
32
+ path: ',66da070aac2d4ae39904050f,66da131a81cf1303bc32a2c7,',
33
+ notes: [],
34
+ serial: null,
35
+ sku: 'AND-PAN2',
36
+ modifiers: [],
37
+ _id: '66ec759cd57e32c3455724a0',
38
+ weight: null,
39
+ properties: null,
40
+ hasInventory: true,
41
+ inventoryType: 'pull',
42
+ category: null,
43
+ priceLevels: [
44
+ {
45
+ value: 10,
46
+ tags: ['default'],
47
+ },
48
+ {
49
+ value: 2,
50
+ tags: ['vip'],
51
+ },
52
+ {
53
+ value: 10,
54
+ tags: ['default', 'press only'],
55
+ },
56
+ {
57
+ value: 2,
58
+ tags: ['vip', 'press only'],
59
+ },
60
+ ],
61
+ costLevels: [],
62
+ itemId: '66da11fdac2d4ae39904465e',
63
+ menuRuleId: '66da132381cf1303bc32a2c8',
64
+ __typename: 'OrderItem',
65
+ subTotals: {
66
+ _included: 0,
67
+ _xincluded: 0,
68
+ _direct: 0,
69
+ _xdirect: 0,
70
+ _simple: 2,
71
+ _actual: 2,
72
+ },
73
+ };
74
+
75
+ describe('Get sub order', () => {
76
+ test('Get a suborder with one item', () => {
77
+ const order = orderMock;
78
+ const create = pricingService.order.getSuborder({ order });
79
+ const newSubOrders = [create(order.items, 1)];
80
+ expect(newSubOrders).toHaveLength(1);
81
+ });
82
+ test('Get a suborder with multiple items', () => {
83
+ const order = orderMock;
84
+ const create = pricingService.order.getSuborder({ order });
85
+ order.items = [...order.items, mockItem];
86
+ const newSubOrders = [create(order.items, 2)];
87
+ expect(newSubOrders).toHaveLength(1);
88
+ });
89
+ });
@@ -1,4 +1,4 @@
1
- const Status = require('./Status');
1
+ const Status = require('./status');
2
2
  const Modifier = require('./Modifier');
3
3
 
4
4
  module.exports = {
@@ -1,5 +1,4 @@
1
1
  module.exports = () =>
2
2
  function getItemModifiers(item) {
3
-
4
3
  return item.modifiers;
5
4
  };
@@ -1,5 +1,5 @@
1
1
  module.exports = ({ actions }) =>
2
- function getItemsTotalPieces(items) {
2
+ function getItemsTotalQuantity(items) {
3
3
  return items.reduce(
4
4
  (total, item) => total + actions.getTotalQuantity(item),
5
5
  0
@@ -6,5 +6,4 @@ module.exports = ({ utils }) =>
6
6
  (totalPrice, item) => utils.math.add(totalPrice, item.price),
7
7
  0
8
8
  );
9
-
10
9
  };
package/lib/item/index.js CHANGED
@@ -11,10 +11,8 @@ const create = require('./create');
11
11
  const hasModifier = require('./hasModifier');
12
12
  const isSelected = require('./isSelected');
13
13
  const hasModifiers = require('./hasModifiers');
14
- const openRecommendationDialog = require('./openRecommendationDialog');
15
14
  const addIndirectModifier = require('./addIndirectModifier');
16
15
  const calculate = require('./calculate');
17
- const filterByDirectModifiers = require('./filterByDirectModifiers');
18
16
  const getItemPrice = require('./getItemPrice');
19
17
  const getDepartmentModifiers = require('./getDepartmentModifiers');
20
18
  const hasSubscription = require('./hasSubscription');
@@ -62,10 +60,8 @@ const itemActions = (deps = {}) => {
62
60
  hasModifier: hasModifier(innerDeps),
63
61
  isSelected: isSelected(innerDeps),
64
62
  hasModifiers: hasModifiers(innerDeps),
65
- openRecommendationDialog: openRecommendationDialog(innerDeps),
66
63
  addIndirectModifier: addIndirectModifier(innerDeps),
67
64
  calculate: calculate(innerDeps),
68
- filterByDirectModifiers: filterByDirectModifiers(innerDeps),
69
65
  getItemPrice: getItemPrice(innerDeps),
70
66
  getDepartmentModifiers: getDepartmentModifiers(innerDeps),
71
67
  hasSubscription: hasSubscription(innerDeps),
@@ -23,10 +23,10 @@ module.exports = ({ _, constants, utils, localization, actions }) => {
23
23
  const maxAmountProp = actions.getProperty(modifier, 'maxAmount');
24
24
 
25
25
  if (!options.skip) {
26
- const maxAmountCalc =
26
+ const maxAmountCalc =
27
27
  actions.isFixedAdd(modifier) || actions.isAmountOverride(modifier)
28
- ? amount
29
- : math.mul(options.price, options.quantity);
28
+ ? amount
29
+ : math.mul(options.price, options.quantity);
30
30
 
31
31
  const maxAmount = maxAmountProp
32
32
  ? math.min(maxAmountProp, maxAmountCalc)
@@ -1,6 +1,5 @@
1
- module.exports = ({ _, actions }) => {
2
-
3
- return function createCreditModifier(modifier = {}) {
1
+ module.exports = ({ _, actions }) =>
2
+ function createCreditModifier(modifier = {}) {
4
3
  const { customerStoredCredit, ...rest } = _.cloneDeep(modifier);
5
4
  if (!customerStoredCredit) return null;
6
5
  let creditModifier;
@@ -27,4 +26,3 @@ module.exports = ({ _, actions }) => {
27
26
  };
28
27
  return creditModifier;
29
28
  };
30
- };
@@ -1,5 +1,5 @@
1
- module.exports = ({ actions }) => {
2
- return function getItemModifiers({ modifiers, customer, cache }) {
1
+ module.exports = ({ actions }) =>
2
+ function getItemModifiers({ modifiers, customer, cache }) {
3
3
  const matchedModifiers = actions.getMatchTagsModifiers({
4
4
  modifiers,
5
5
  entity: customer,
@@ -34,4 +34,3 @@ module.exports = ({ actions }) => {
34
34
  modifierId: each.modifierId || each._id,
35
35
  }));
36
36
  };
37
- };
@@ -0,0 +1,17 @@
1
+ module.exports = ({ actions }) =>
2
+ function createSuborder(order) {
3
+ const create = actions.getSuborder({ order });
4
+ let subOrders = order.orders || [];
5
+ const newSubOrders = [create(order.items, 1)];
6
+ subOrders = [...subOrders, ...newSubOrders].map((subOrder, idx) => ({
7
+ ...subOrder,
8
+ displayId: `${order.displayId}-${idx + 1}`,
9
+ }));
10
+
11
+ subOrders = actions.spreadModifiers({
12
+ parentOrder: order,
13
+ subOrders,
14
+ });
15
+
16
+ return subOrders;
17
+ };
@@ -0,0 +1,49 @@
1
+ module.exports = ({ utils, _, settings }) => {
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
+ };
12
+ const getSubOrder =
13
+ ({ order }) =>
14
+ (items, index) => {
15
+ let displayId = '';
16
+ if (orderSettings.allowSuborder)
17
+ displayId = `${order.displayId}-${index}`;
18
+ else if (index === 1) displayId = order.displayId;
19
+
20
+ return {
21
+ ...order,
22
+ _id: helpers.getObjectID(),
23
+ displayId,
24
+ discount: 0,
25
+ tax: 0,
26
+ totalPaid: 0,
27
+ total: 0,
28
+ status: {
29
+ order: 'open',
30
+ delivery: order.status.delivery,
31
+ detailed: order.status.detailed,
32
+ fullyPaid: false,
33
+ fullyPicked: false,
34
+ },
35
+ parentId: orderSettings.allowSuborder ? order._id : null,
36
+ items,
37
+ modifiers: [],
38
+ notes: [
39
+ ...(order.notes || []),
40
+ {
41
+ ...noteDefaults,
42
+ message: `Suborder from ${order.displayId}`, // ask about this message
43
+ },
44
+ ],
45
+ };
46
+ };
47
+
48
+ return getSubOrder;
49
+ };
@@ -86,6 +86,8 @@ const validateFixedModifiersTotal = require('./validateFixedModifiersTotal');
86
86
  const markModifiersAsLocked = require('./markModifiersAsLocked');
87
87
  const removeModifiers = require('./removeModifiers');
88
88
  const addModifiers = require('./addModifiers');
89
+ const createSuborder = require('./createSuborder');
90
+ const getSuborder = require('./getSuborder');
89
91
 
90
92
  const orderActions = (deps = {}) => {
91
93
  const actions = {};
@@ -184,6 +186,8 @@ const orderActions = (deps = {}) => {
184
186
  markModifiersAsLocked: markModifiersAsLocked(innerDeps),
185
187
  removeModifiers: removeModifiers(innerDeps),
186
188
  addModifiers: addModifiers(innerDeps),
189
+ createSuborder: createSuborder(innerDeps),
190
+ getSuborder: getSuborder(innerDeps),
187
191
  });
188
192
 
189
193
  Object.keys(freezedActions).forEach(actionName => {
@@ -48,8 +48,10 @@ module.exports = ({ settings, _, moment }) => {
48
48
  // day condition stays working until addDaysCounter is greater than loop
49
49
  if (
50
50
  !shouldSkip ||
51
+ // eslint-disable-next-line no-loop-func
51
52
  !closedDays.some(closedDay => closedDay.date.isSame(endDateTZ, 'day'))
52
53
  ) {
54
+ // eslint-disable-next-line no-plusplus
53
55
  addDaysCounter++;
54
56
  }
55
57
  }
@@ -1,14 +1,5 @@
1
- module.exports = ({ utils, _, itemActions, modifierActions, settings }) => {
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
- };
1
+ module.exports = ({ utils, _, actions, itemActions, modifierActions }) => {
2
+ const { helpers } = utils;
12
3
 
13
4
  const joinItemQuantity = orders =>
14
5
  orders.map(order => {
@@ -39,42 +30,6 @@ module.exports = ({ utils, _, itemActions, modifierActions, settings }) => {
39
30
  return { ...order, items };
40
31
  });
41
32
 
42
- const getOrder =
43
- ({ order, name }) =>
44
- (items, index) => {
45
- let displayId = '';
46
- if (orderSettings.allowSuborder)
47
- displayId = `${order.displayId}-${index}`;
48
- else if (index === 1) displayId = order.displayId;
49
-
50
- return {
51
- ...order,
52
- _id: helpers.getObjectID(),
53
- displayId,
54
- discount: 0,
55
- tax: 0,
56
- totalPaid: 0,
57
- total: 0,
58
- status: {
59
- order: 'open',
60
- delivery: order.status.delivery,
61
- detailed: order.status.detailed,
62
- fullyPaid: false,
63
- fullyPicked: false,
64
- },
65
- parentId: orderSettings.allowSuborder ? order._id : null,
66
- items,
67
- modifiers: [],
68
- notes: [
69
- ...(order.notes || []),
70
- {
71
- ...noteDefaults,
72
- message: `Split from ${order.displayId}, for department ${name}`,
73
- },
74
- ],
75
- };
76
- };
77
-
78
33
  const getDepartmentName = item => {
79
34
  const deps = itemActions.getDepartmentModifiers(item);
80
35
  return (deps.length && deps[0].name) || 'other';
@@ -91,7 +46,7 @@ module.exports = ({ utils, _, itemActions, modifierActions, settings }) => {
91
46
 
92
47
  orders.forEach(each => {
93
48
  const [name, newItems] = each;
94
- const create = getOrder({ order, name });
49
+ const create = actions.getSuborder({ order, name });
95
50
  // Assuming there is one department in the item
96
51
  const department = itemActions.getDepartmentModifiers(newItems[0])[0];
97
52
  const departmentName = getDepartmentName(newItems[0]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darkpos/pricing",
3
- "version": "1.0.39",
3
+ "version": "1.0.41",
4
4
  "description": "Pricing calculator",
5
5
  "author": "Dark POS",
6
6
  "license": "ISC",
@@ -36,5 +36,5 @@
36
36
  "supertest": "^6.2.3",
37
37
  "supervisor": "^0.12.0"
38
38
  },
39
- "gitHead": "810d5db51e47904e9813b4abdf5867d823117e4c"
39
+ "gitHead": "0ab9e8f6bf59ef671ffb2005712a5ec6f998b36e"
40
40
  }
@@ -1,13 +0,0 @@
1
- /**
2
- * Remove order modifiers from items
3
- */
4
- module.exports = ({ modifierActions }) =>
5
- //
6
- function filterByDirectModifiers(items = []) {
7
- return items.map(item => ({
8
- ...item,
9
- modifiers: (item.modifiers || []).filter(modifier =>
10
- modifierActions.isDirect(modifier)
11
- ),
12
- }));
13
- };
@@ -1,4 +0,0 @@
1
- module.exports = () =>
2
- function openRecommendationDialog(item) {
3
- return !!(item && item.openRecommendationDialog);
4
- };