feat: add weighted products and refund workflows - #537
Conversation
Greptile SummaryThe PR adds weighted-product sales and scale barcode support alongside authorized, idempotent bill and item refund workflows.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| 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
Reviews (4): Last reviewed commit: "fix: enforce two-hour refund window" | Re-trigger Greptile
|
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. |
|
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. |
Summary
Closes #365
Verification
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.