Skip to content

feat: add weighted products and refund workflows - #537

Open
itsbkm wants to merge 4 commits into
mainfrom
codex/weighted-products-refunds
Open

feat: add weighted products and refund workflows#537
itsbkm wants to merge 4 commits into
mainfrom
codex/weighted-products-refunds

Conversation

@itsbkm

@itsbkm itsbkm commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add weighted product metadata, validation, and product-management controls for sale units, fractional quantities, and weight precision
  • add default scale-generated barcode parsing for issue Feature: Weighted products & scale-generated barcodes (electronic scale, stage 1) #365 and wire scans into POS/product-grid add-to-cart flows
  • allow held orders to round-trip fractional quantities
  • add refund persistence, idempotency, authorization, item/bill refund flows, and exclude refunded items from active KDS/order/bill math

Closes #365

Verification

  • npm run lint
  • npm run build
  • npm run build:frontend
  • npm run i18n:check
  • npm test
  • git diff --check
  • npx ts-node --transpile-only -P tests/tsconfig.json tests/issue-365-scale-barcode.test.ts
  • node tests/run-electron-node-test.cjs tests/issue-137-barcode.test.ts
  • node tests/run-electron-node-test.cjs tests/held-orders.test.ts
  • node tests/run-electron-node-test.cjs tests/schema-health.test.ts
  • node tests/run-electron-node-test.cjs tests/refunds.test.ts

Note: an initial full npm test attempt hit an unrelated existing Electron process on ports 3001/3002/3003. After clearing that local process, the full npm test run completed successfully.

@greptile-apps

greptile-apps Bot commented Aug 28, 2026

Copy link
Copy Markdown

Greptile Summary

The PR adds weighted-product sales and scale barcode support alongside authorized, idempotent bill and item refund workflows.

  • Adds weighted product metadata, precision validation, fractional held-order support, and scale barcode resolution.
  • Persists refunds and prevents duplicate refund processing.
  • Updates bill, report, KDS, tax, IPC, and cloud calculations to account for refunded items and event-dated refund movement.
  • Adds regression coverage for fractional quantities, scale barcodes, split checks, partial refunds, and cross-day refunds.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
main/services/refund.ts Implements refund validation, split-check ownership enforcement, manager approval, idempotency, and persisted item adjustments.
main/routes/reports.ts Uses payment and refund event dates consistently when calculating net revenue and payment-method movement.
main/routes/orders-validation.ts Enforces weighted-unit, fractional-quantity, and decimal-precision constraints at the order boundary.
main/routes/products.ts Validates and persists weighted-product metadata while rejecting fractional configuration for per-item products.
frontend/src/lib/scale-barcode.ts Parses default scale barcodes, resolves weighted products, and converts encoded grams into configured sale units.
main/db.ts Adds refund persistence, refund idempotency, and weighted-product schema migrations.

Sequence Diagram

sequenceDiagram
    participant POS
    participant API
    participant RefundService
    participant DB
    participant Reports
    POS->>API: Submit refund with manager PIN and idempotency key
    API->>RefundService: Validate request and authorization
    RefundService->>DB: Check bill balance and item allocation
    RefundService->>DB: Persist refund and adjustment atomically
    RefundService-->>POS: Return refund and updated bill
    Reports->>DB: Aggregate payments by paid_at
    Reports->>DB: Aggregate refunds by created_at
    Reports-->>POS: Return net event-dated revenue
Loading

Reviews (4): Last reviewed commit: "fix: enforce two-hour refund window" | Re-trigger Greptile

Comment thread main/services/refund.ts
Comment thread main/services/refund.ts
@itsbkm

itsbkm commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Addressed Greptile’s outside-diff fractional policy finding in acb65cb. Order creation, order append, and fractional held-order persistence now validate quantity against canonical product metadata, including allow_fractional_quantity and weight_precision. Whole-unit products reject decimals with HTTP 400; weighted products retain fractional support. Focused regressions and the full npm test suite pass.

Comment thread main/routes/reports.ts Outdated
Comment thread main/routes/orders-validation.ts
@itsbkm

itsbkm commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up d7e95bc enforces the product requirement that refunds may only be initiated within two hours of order creation. The check runs at the backend service boundary before PIN rate limiting and mutation; expired attempts return 409 and persist nothing. Event-date accounting remains necessary for valid refunds crossing midnight within that two-hour window. Focused refund suite: 46/46; backend build passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Weighted products & scale-generated barcodes (electronic scale, stage 1)

1 participant