Skip to content

Save chosen currencies in settings and let wallet currencies be edited - #24

Closed
roncodes wants to merge 2 commits into
mainfrom
fix/settings-currency-select
Closed

roncodes wants to merge 2 commits into
mainfrom
fix/settings-currency-select

Conversation

@roncodes

Copy link
Copy Markdown
Member

Fixes fleetbase/fleetbase#678.

Base and invoice currency never saved

In Ledger → Settings → Accounting (base currency) and Settings → Invoice (default currency), a chosen currency looked saved but was back to the default after a reload.

CurrencySelect calls @onCurrencyChange(code, currency), with the ISO code first. Both settings controllers read currency?.code from that first argument. A string has no .code, so the field became null, Save stored null, and on reload the page fell back to the organisation default (or USD). Both handlers now take the code.

Wallet currency couldn't be changed

Editing a wallet, for example to change its currency, failed with a 400: Column 'balance' cannot be null. The console sends the whole record back, balance included, and the generic update wrote it into the wallet.

  • The ledger-wallet serializer no longer sends balance or formatted_balance.
  • WalletController::updateRecord drops those fields too. An edit can then never overwrite a balance that should only move through transactions (credit, top-up, payout, transfer). Before this, any wallet update request could set the balance directly.

Verification

  • Reproduced on the dev stack: the settings API itself persists base_currency correctly, so the loss happened in the UI handler. Editing a wallet from the UI returned the 400 above.
  • Settings, with the fix in the running console: picking CAD in Accounting settings saves base_currency: "CAD", and CAD is still selected after a reload.
  • Wallet, with the serializer fix: changing a wallet from USD to CAD in the edit panel saves, and the balance is unchanged.
  • Server test: WalletControllerTest passes (11 tests). The new test checks that balance/formatted_balance are stripped with and without the wallet payload key. php-cs-fixer is clean.
  • Not live-tested: the server-side guard, because the dev API runs a vendored ledger.

Ledger > Settings > Accounting (base currency) and Invoice (default
currency) never saved a chosen currency: CurrencySelect calls
@onCurrencyChange with the ISO code first (then the currency object), but
both handlers read `.code` off that argument. The string has no `.code`,
so the field was set to null and saved as null, and after a reload the page
fell back to the organisation default.

Both handlers now take the code.

Fixes fleetbase/fleetbase#678
Editing a wallet (for example to change its currency) failed with a 400:
"Column 'balance' cannot be null". The console sends the whole record back,
including the balance, and the update wrote it straight into the wallet.

- The wallet serializer no longer sends balance or formatted_balance.
- The wallet update endpoint drops them too, so an edit can never overwrite
  a balance that should only move through transactions (credit, top-up,
  payout, transfer).

Part of fleetbase/fleetbase#678
@codecov

codecov Bot commented Sep 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.97%. Comparing base (d2e5de6) to head (2bc461d).

Files with missing lines Patch % Lines
.../Http/Controllers/Internal/v1/WalletController.php 77.77% 2 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##                main      #24      +/-   ##
=============================================
- Coverage     100.00%   99.97%   -0.03%     
- Complexity      1249     1253       +4     
=============================================
  Files             74       74              
  Lines           6981     6990       +9     
=============================================
+ Hits            6981     6988       +7     
- Misses             0        2       +2     
Flag Coverage Δ
backend 99.97% <77.77%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

Unable to change currency in Ledger Account Settings

1 participant