@darkpos/pricing 1.0.108 → 1.0.109

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.
@@ -1689,4 +1689,146 @@ describe('Item actions', () => {
1689
1689
  description: '$7.59 discount (-$7.59)',
1690
1690
  });
1691
1691
  });
1692
+
1693
+ test('Should use a price override modifier and quantity override modifier in combination accordingly', () => {
1694
+ const overridePriceMod = {
1695
+ _id: '675354ee39a47228afd1f1a4',
1696
+ attributes: ['override'],
1697
+ modifierId: '6751f7eeb60c71cefee138ee',
1698
+ name: 'Override item price fixed 0',
1699
+ tags: ['default', 'all'],
1700
+ direct: true,
1701
+ properties: {
1702
+ override: {
1703
+ type: 'fixed',
1704
+ field: 'price',
1705
+ fixedValue: 0,
1706
+ multiplier: false,
1707
+ },
1708
+ },
1709
+ };
1710
+ const overrideQuantityMod = {
1711
+ _id: '675354ee39a47228afd1f1a5',
1712
+ attributes: ['override'],
1713
+ modifierId: '6751f7eeb60c71cefee138ff',
1714
+ name: 'Override item quantity fixed 20',
1715
+ tags: ['default', 'all'],
1716
+ direct: true,
1717
+ properties: {
1718
+ override: {
1719
+ type: 'fixed',
1720
+ field: 'quantity',
1721
+ fixedValue: 20,
1722
+ multiplier: false,
1723
+ },
1724
+ },
1725
+ };
1726
+
1727
+ const itemWithModifierAmountFixed10 = {
1728
+ name: "Men's 3pc Tuxedo",
1729
+ pieces: 1,
1730
+ price: 10,
1731
+ quantity: 1,
1732
+ modifiers: [overridePriceMod, overrideQuantityMod],
1733
+ _id: '675354e939a47228afd1f199',
1734
+ itemId: '62cdbfd01ee1b400193281ee',
1735
+ };
1736
+ const newItem = pricingService.item.calculate(
1737
+ itemWithModifierAmountFixed10
1738
+ );
1739
+ expect(newItem.price).toBe(0);
1740
+ expect(newItem.total).toBe(0);
1741
+ expect(newItem.quantity).toBe(20);
1742
+ expect(newItem).toHaveProperty('price', 0);
1743
+ expect(newItem.modifiers[0]).toHaveProperty('_computed', {
1744
+ amount: 0,
1745
+ description: 'Override item price fixed 0 ($0.00/Unit)',
1746
+ });
1747
+
1748
+ expect(newItem.modifiers[1]).toHaveProperty('_computed', {
1749
+ amount: 0,
1750
+ description: 'Override item quantity fixed 20',
1751
+ });
1752
+
1753
+ expect(newItem).toHaveProperty('subTotals', {
1754
+ _included: 0,
1755
+ _xincluded: 0,
1756
+ _direct: 0,
1757
+ _xdirect: 0,
1758
+ _simple: 0,
1759
+ _actual: 0,
1760
+ });
1761
+ });
1762
+
1763
+ test('Should use a total override modifier and quantity override modifier in combination accordingly', () => {
1764
+ const overrideTotalMod = {
1765
+ _id: '675354ee39a47228afd1f1a4',
1766
+ attributes: ['override'],
1767
+ modifierId: '6751f7eeb60c71cefee138ee',
1768
+ name: 'Override item total fixed 0',
1769
+ tags: ['default', 'all'],
1770
+ direct: true,
1771
+ properties: {
1772
+ override: {
1773
+ type: 'fixed',
1774
+ field: 'total',
1775
+ fixedValue: 0,
1776
+ multiplier: false,
1777
+ },
1778
+ sort: 2,
1779
+ },
1780
+ };
1781
+ const overrideQuantityMod = {
1782
+ _id: '675354ee39a47228afd1f1a5',
1783
+ attributes: ['override'],
1784
+ modifierId: '6751f7eeb60c71cefee138ff',
1785
+ name: 'Override item quantity fixed 20',
1786
+ tags: ['default', 'all'],
1787
+ direct: true,
1788
+ properties: {
1789
+ override: {
1790
+ type: 'fixed',
1791
+ field: 'quantity',
1792
+ fixedValue: 20,
1793
+ multiplier: false,
1794
+ },
1795
+ sort: 1,
1796
+ },
1797
+ };
1798
+
1799
+ const itemWithModifierAmountFixed10 = {
1800
+ name: "Men's 3pc Tuxedo",
1801
+ pieces: 1,
1802
+ price: 10,
1803
+ quantity: 1,
1804
+ modifiers: [overrideTotalMod, overrideQuantityMod],
1805
+ _id: '675354e939a47228afd1f199',
1806
+ itemId: '62cdbfd01ee1b400193281ee',
1807
+ };
1808
+ const newItem = pricingService.item.calculate(
1809
+ itemWithModifierAmountFixed10
1810
+ );
1811
+ expect(newItem.price).toBe(10);
1812
+ expect(newItem.total).toBe(0);
1813
+ expect(newItem.quantity).toBe(20);
1814
+ expect(newItem.modifiers[0]).toHaveProperty('_computed', {
1815
+ amount: 0,
1816
+ description: 'Override item quantity fixed 20',
1817
+ });
1818
+
1819
+ expect(newItem.modifiers[1]).toHaveProperty('_computed', {
1820
+ amount: -200,
1821
+ description: 'Override item total fixed 0 (-$200.00)',
1822
+ });
1823
+
1824
+ expect(newItem).toHaveProperty('subTotals', {
1825
+ _included: 0,
1826
+ _xincluded: -200,
1827
+ undefined: -200,
1828
+ _direct: -200,
1829
+ _xdirect: 0,
1830
+ _simple: 200,
1831
+ _actual: 200,
1832
+ });
1833
+ });
1692
1834
  });
@@ -99,7 +99,7 @@ module.exports = ({ _, utils, actions, modifierActions }) => {
99
99
  );
100
100
  });
101
101
 
102
- const price = parseFloat(
102
+ let price = parseFloat(
103
103
  actions.getPriceWithoutModifiers({
104
104
  price: item.price,
105
105
  modifiers: validatedModifiers,
@@ -174,6 +174,7 @@ module.exports = ({ _, utils, actions, modifierActions }) => {
174
174
  overwrittenPrice: item.price,
175
175
  };
176
176
  item.price = priceOverride;
177
+ price = priceOverride;
177
178
  }
178
179
 
179
180
  if (modifierActions.isQuantityOverride(modifier)) {
@@ -182,7 +183,7 @@ module.exports = ({ _, utils, actions, modifierActions }) => {
182
183
  ...(item.properties ? item.properties : {}),
183
184
  overwrittenQuantity: item.quantity,
184
185
  };
185
- subTotals._simple = math.mul(price, newQuantity);
186
+ subTotals._simple = math.mul(item.price, newQuantity);
186
187
  item.quantity = parseInt(newQuantity, 10);
187
188
  quantity = parseInt(newQuantity, 10);
188
189
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darkpos/pricing",
3
- "version": "1.0.108",
3
+ "version": "1.0.109",
4
4
  "description": "Pricing calculator",
5
5
  "author": "Dark POS",
6
6
  "license": "ISC",
@@ -54,5 +54,5 @@
54
54
  "supertest": "^6.2.3",
55
55
  "supervisor": "^0.12.0"
56
56
  },
57
- "gitHead": "263ab257a926d73b861d12ae2ccfdb46b7d162ee"
57
+ "gitHead": "a971788284c326a00e19c914ffbfdc22f1069c72"
58
58
  }