Skip to content

fix(expenses): recover retries and enforce currency - #1016

Merged
khaira777 merged 4 commits into
mainfrom
fix/expense-currency-policy-and-recovery
Oct 9, 2026
Merged

khaira777 merged 4 commits into
mainfrom
fix/expense-currency-policy-and-recovery

Conversation

@khaira777

@khaira777 khaira777 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Expense retries with omitted currency could conflict after the store currency changed, and historical expenses still accepted new non-cash settlements. Resolve omitted currency against the committed expense snapshot, preserve existing receipt hashes and explicit/omitted equivalence, and require every new payment or reversal to match the store currency.

Committed requests replay before mutable currency, session, balance, date and category checks. The no-mistakes review correction also makes the store-currency guard return 409 currency_mismatch before caller-currency validation for new mismatched settlements.

Validation:

  • Local no-mistakes review, live API probes, documentation and lint gates passed.
  • Full npm test, npm run lint, npm run build, npm run docs:check, and diff checks passed on the recovered result.
  • Expense records: 296/296; expense API: 138/138; expense payments: 151/151.
  • Regression coverage includes database reopen recovery, normalized currency equivalence, changed-payload conflicts, all payment methods and cash/non-cash reversals.

Refs #645.

Summary by CodeRabbit

  • Bug Fixes

    • Payments and reversals now require the expense currency to match the store’s active currency, regardless of payment method.
    • Retrying expense creation or replacement without specifying a currency now replays the original result even if the store’s currency settings have changed. Supplying a different explicit currency still conflicts.
  • Documentation

    • Clarified the currency-match requirements for payments and reversals, and how omitted currencies are handled when replaying requests.

@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: FreeOpenSourcePOS/FloCafe/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2be1d341-ea25-4659-99c4-0ded32bd492b

📥 Commits

Reviewing files that changed from the base of the PR and between 68e2d65 and 7ef0668.


📒 Files selected for processing (4)
  • docs/reference/api.md
  • main/services/expenses.ts
  • tests/expense-payments.test.ts
  • tests/expense-records.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.



Walkthrough

Expense mutation idempotency now uses the committed expense currency when a request omits currency. Payment and reversal settlements now require the expense currency to match the current store currency. API documentation and tests cover these changes.

Changes

Expense mutations

Layer / File(s) Summary
Mutation currency and replay
main/services/expenses.ts, tests/expense-records.test.ts, docs/reference/api.md
Omitted currency remains unset during request normalization. Mutation hashes use the returned expense currency, and replay checks use the stored response. Tests cover retries across store currency changes and database reopen; summary tests extend their date range to the later of the store business date and today.
Settlement currency checks
main/services/expenses.ts, tests/expense-payments.test.ts, docs/reference/api.md
Payments and reversals reject settlements when the expense currency differs from the current store currency. Tests cover cash and non-cash methods, including reversal replay after a store currency change. The API documentation describes the 409 currency_mismatch response.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant runExpenseMutation
  participant ExpenseMutation
  participant IdempotencyReceipts
  Client->>runExpenseMutation: Submit mutation request
  runExpenseMutation->>ExpenseMutation: Execute mutation
  ExpenseMutation-->>runExpenseMutation: Return expense with resolved currency
  runExpenseMutation->>IdempotencyReceipts: Store hash using returned currency
  Client->>runExpenseMutation: Retry mutation request
  runExpenseMutation->>IdempotencyReceipts: Read stored response and request hash
  runExpenseMutation->>runExpenseMutation: Recalculate hash from stored response
Loading

Merge Risk: ⚪ Minimal · up to 7ef06

The supplied evidence identifies no issue that needs resolution before merge; normal checks still apply.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check Warning The description explains the main behavior changes, references issue #645, and lists verification results. It does not follow the required template because it omits the Related work, Scope, Compatibil… Complete the required template sections. State the related issue explicitly, define the scope, document database and user-visible impacts, mark applicable cross-cutting surfaces, record the documentation choice, and complete the contributor…
Docstring Coverage Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 3 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check Passed The title clearly describes the main changes: recovering expense retries and enforcing currency validation.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

Full details: Description check

Explanation

The description explains the main behavior changes, references issue #645, and lists verification results. It does not follow the required template because it omits the Related work, Scope, Compatibility & data safety, Screenshots, Cross-cutting surfaces, Developer documentation, and Contributor checklist sections.

Resolution

Complete the required template sections. State the related issue explicitly, define the scope, document database and user-visible impacts, mark applicable cross-cutting surfaces, record the documentation choice, and complete the contributor checklist.


Full details: Docstring Coverage

Explanation

Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 3 files. (1 skipped: 1 unsupported.)



  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR


  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@khaira777
khaira777 merged commit 8b79ff1 into main Oct 9, 2026
16 checks passed
@khaira777
khaira777 deleted the fix/expense-currency-policy-and-recovery branch October 9, 2026 17:14
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.

1 participant