@tallyui/pos 5.2.0 → 5.3.0

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/index.d.ts CHANGED
@@ -2682,6 +2682,7 @@ declare const UPDATE_UNSENDABLE_MESSAGE = "The store can't accept this change ye
2682
2682
  * `register_session_unknown` is not shown, because the store counts the order once its session arrives (ADR-078).
2683
2683
  * A `total_mismatch` whose rounding bridge is within ADR-048's tolerance (|`bridgeMinor`| ≤ ⌈(lines + fees + shipping) / 2⌉)
2684
2684
  * is not shown for itself: the row's notice says it.
2685
+ * A connector declaring `discountsAreTaxedRows` adds the discounted lines to that row count.
2685
2686
  * A refused order is left out once its finalized successor is in `orders`.
2686
2687
  * Pending updates marked `UPDATE_UNSENDABLE` are shown until a person acts.
2687
2688
  * An order a cashier marked handled (`markAttentionHandled`) is left out while its `commandId` is the one it was marked
@@ -2691,6 +2692,7 @@ declare const UPDATE_UNSENDABLE_MESSAGE = "The store can't accept this change ye
2691
2692
  */
2692
2693
  declare function needsAttention(orders: PosOrder[], options?: {
2693
2694
  stuckCommandIds?: readonly string[];
2695
+ discountsAreTaxedRows?: boolean;
2694
2696
  }): PosOrder[];
2695
2697
 
2696
2698
  /**
package/dist/index.js CHANGED
@@ -8978,14 +8978,16 @@ function canPayRestOnStore(order) {
8978
8978
  // src/pos-order/needs-attention.ts
8979
8979
  var UPDATE_UNSENDABLE = "update_unsendable";
8980
8980
  var UPDATE_UNSENDABLE_MESSAGE = "The store can't accept this change yet. Ask the owner to update the POS plugin, then press Retry.";
8981
- function roundingBridgeTolerance(order) {
8982
- return Math.ceil((order.lines.length + (order.fees?.length ?? 0) + (order.shipping?.length ?? 0)) / 2);
8981
+ function discountedLineCount(order) {
8982
+ return order.lines.filter((line) => (order.coupons ?? []).reduce((discount, coupon) => discount + (coupon.carried && coupon.lines ? coupon.lines.find(({ lineId }) => lineId === line.id)?.discountMinor ?? 0 : 0), netDiscountMinor(line, order)) > 0).length;
8983
+ }
8984
+ function roundingBridgeTolerance(order, discountsAreTaxedRows) {
8985
+ return Math.ceil((order.lines.length + (order.fees?.length ?? 0) + (order.shipping?.length ?? 0) + (discountsAreTaxedRows ? discountedLineCount(order) : 0)) / 2);
8983
8986
  }
8984
8987
  function needsAttention(orders, options = {}) {
8985
8988
  const replaced = replacedOrderIds(orders);
8986
8989
  return orders.filter((order) => {
8987
- const tolerance = roundingBridgeTolerance(order);
8988
- return order.syncStatus === "rejected" && !settledOnStore(order) || order.syncStatus === "pending" && order.error?.code === UPDATE_UNSENDABLE || (order.localWarnings?.length ?? 0) > 0 || order.syncStatus === "applied" && knownWarnings(order.warnings).some((warning) => warning.code !== "register_session_unknown" && !(warning.code === "total_mismatch" && warning.bridgeMinor !== void 0 && Math.abs(warning.bridgeMinor) <= tolerance)) || order.lateSessionId !== void 0 || order.syncStatus === "pending" && options.stuckCommandIds?.includes(order.commandId) === true;
8990
+ return order.syncStatus === "rejected" && !settledOnStore(order) || order.syncStatus === "pending" && order.error?.code === UPDATE_UNSENDABLE || (order.localWarnings?.length ?? 0) > 0 || order.syncStatus === "applied" && knownWarnings(order.warnings).some((warning) => warning.code !== "register_session_unknown" && !(warning.code === "total_mismatch" && warning.bridgeMinor !== void 0 && Math.abs(warning.bridgeMinor) <= roundingBridgeTolerance(order, options.discountsAreTaxedRows === true))) || order.lateSessionId !== void 0 || order.syncStatus === "pending" && options.stuckCommandIds?.includes(order.commandId) === true;
8989
8991
  }).filter((order) => !replaced.has(order.id) && !(order.attentionHandledFor !== void 0 && order.attentionHandledFor === order.commandId && storeOrderLeft(order) === void 0)).sort((a, b) => b.createdAt.localeCompare(a.createdAt));
8990
8992
  }
8991
8993
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tallyui/pos",
3
- "version": "5.2.0",
3
+ "version": "5.3.0",
4
4
  "type": "module",
5
5
  "description": "Shared POS business logic for Tally UI — tax, orders, payments, discounts, receipts",
6
6
  "main": "./dist/index.js",
@@ -35,20 +35,20 @@
35
35
  "mustache": "^4.2.0"
36
36
  },
37
37
  "peerDependencies": {
38
- "@tallyui/core": "^5.2.0",
38
+ "@tallyui/core": "^5.3.0",
39
39
  "react": ">=18",
40
40
  "rxdb": "~17.5.0",
41
41
  "rxjs": ">=7"
42
42
  },
43
43
  "devDependencies": {
44
- "@tallyui/core": "5.2.0",
44
+ "@tallyui/core": "5.3.0",
45
45
  "@types/react": ">=18",
46
46
  "react": "^19.2.4",
47
47
  "rxdb": "17.5.0",
48
48
  "rxjs": "7.8.2",
49
- "@tallyui/connector-medusa": "5.2.0",
50
- "@tallyui/connector-woocommerce": "5.2.0",
51
- "@tallyui/database": "5.2.0"
49
+ "@tallyui/connector-medusa": "5.3.0",
50
+ "@tallyui/connector-woocommerce": "5.3.0",
51
+ "@tallyui/database": "5.3.0"
52
52
  },
53
53
  "scripts": {
54
54
  "build": "tsup",
@@ -87,7 +87,7 @@ export const editedSku = (line: PosOrderLine) => !line.custom && line.catalogueS
87
87
  * its stored taxLines are after the coupon. Otherwise tax comes from stored taxLines after D, recomputed before a
88
88
  * store-priced coupon, and from `taxMicros` before D.
89
89
  */
90
- function netDiscountMinor(line: PosOrderLine, order: Pick<PosOrder, 'pricesIncludeTax' | 'taxRounding' | 'coupons' | 'currency'>): number {
90
+ export function netDiscountMinor(line: PosOrderLine, order: Pick<PosOrder, 'pricesIncludeTax' | 'taxRounding' | 'coupons' | 'currency'>): number {
91
91
  if (!(line.taxInclusive ?? order.pricesIncludeTax) || line.discountMinor === 0) return line.discountMinor;
92
92
  const woocommerce = order.taxRounding?.granularity === 'woocommerce', stored: readonly LineTaxLine[] = line.taxLines;
93
93
  const afterDiscount = line.unitPriceMinor * line.quantity - line.discountMinor;
@@ -1,4 +1,5 @@
1
1
  import { knownWarnings } from '@tallyui/core';
2
+ import { netDiscountMinor } from './command';
2
3
  import { replacedOrderIds } from './reopened';
3
4
  import { storeOrderLeft } from './store-order-left';
4
5
  import { settledOnStore } from './store-settlement';
@@ -8,9 +9,14 @@ import type { PosOrder } from './types';
8
9
  export const UPDATE_UNSENDABLE = 'update_unsendable';
9
10
  export const UPDATE_UNSENDABLE_MESSAGE = "The store can't accept this change yet. Ask the owner to update the POS plugin, then press Retry.";
10
11
 
11
- /** ADR-048's T = ⌈(lines + surcharges) / 2⌉, applied once to the whole order: stored lines, fees and shipping rows. */
12
- function roundingBridgeTolerance(order: PosOrder): number {
13
- return Math.ceil((order.lines.length + (order.fees?.length ?? 0) + (order.shipping?.length ?? 0)) / 2);
12
+ function discountedLineCount(order: PosOrder): number {
13
+ return order.lines.filter((line) => (order.coupons ?? []).reduce((discount, coupon) => discount + (coupon.carried && coupon.lines
14
+ ? coupon.lines.find(({ lineId }) => lineId === line.id)?.discountMinor ?? 0 : 0), netDiscountMinor(line, order)) > 0).length;
15
+ }
16
+
17
+ /** ADR-048's T = ⌈rows / 2⌉ counts lines, fees and shipping once per order, adding discounted lines for a connector declaring `discountsAreTaxedRows`. */
18
+ function roundingBridgeTolerance(order: PosOrder, discountsAreTaxedRows: boolean): number {
19
+ return Math.ceil((order.lines.length + (order.fees?.length ?? 0) + (order.shipping?.length ?? 0) + (discountsAreTaxedRows ? discountedLineCount(order) : 0)) / 2);
14
20
  }
15
21
 
16
22
  /**
@@ -21,6 +27,7 @@ function roundingBridgeTolerance(order: PosOrder): number {
21
27
  * `register_session_unknown` is not shown, because the store counts the order once its session arrives (ADR-078).
22
28
  * A `total_mismatch` whose rounding bridge is within ADR-048's tolerance (|`bridgeMinor`| ≤ ⌈(lines + fees + shipping) / 2⌉)
23
29
  * is not shown for itself: the row's notice says it.
30
+ * A connector declaring `discountsAreTaxedRows` adds the discounted lines to that row count.
24
31
  * A refused order is left out once its finalized successor is in `orders`.
25
32
  * Pending updates marked `UPDATE_UNSENDABLE` are shown until a person acts.
26
33
  * An order a cashier marked handled (`markAttentionHandled`) is left out while its `commandId` is the one it was marked
@@ -28,15 +35,14 @@ function roundingBridgeTolerance(order: PosOrder): number {
28
35
  * sale whose order the store created (`storeOrderLeft`, #1101). A refused sale whose store order is settled on the store
29
36
  * (`settledOnStore`: cancelled or gone, #1101) is not shown for its refusal; any other reason above still shows it.
30
37
  */
31
- export function needsAttention(orders: PosOrder[], options: { stuckCommandIds?: readonly string[] } = {}): PosOrder[] {
38
+ export function needsAttention(orders: PosOrder[], options: { stuckCommandIds?: readonly string[]; discountsAreTaxedRows?: boolean } = {}): PosOrder[] {
32
39
  const replaced = replacedOrderIds(orders);
33
40
  return orders.filter((order) => {
34
- const tolerance = roundingBridgeTolerance(order);
35
41
  return (order.syncStatus === 'rejected' && !settledOnStore(order))
36
42
  || (order.syncStatus === 'pending' && order.error?.code === UPDATE_UNSENDABLE)
37
43
  || (order.localWarnings?.length ?? 0) > 0
38
44
  || (order.syncStatus === 'applied' && knownWarnings(order.warnings).some((warning) => warning.code !== 'register_session_unknown'
39
- && !(warning.code === 'total_mismatch' && warning.bridgeMinor !== undefined && Math.abs(warning.bridgeMinor) <= tolerance)))
45
+ && !(warning.code === 'total_mismatch' && warning.bridgeMinor !== undefined && Math.abs(warning.bridgeMinor) <= roundingBridgeTolerance(order, options.discountsAreTaxedRows === true))))
40
46
  || order.lateSessionId !== undefined
41
47
  || (order.syncStatus === 'pending' && options.stuckCommandIds?.includes(order.commandId) === true);
42
48
  })