Repository navigation
Closed
Labels
Description
Refs: #388
Context
FloCafe supports country-specific locale display preferences (currency_display, number_digits, calendar). These are declared per country in main/countries.ts via Country.localeOptions. Currently, Iran (IR) is the primary profile declaring these options (currencyDisplay: ['rial', 'toman', 'toman_short'], digits: ['locale', 'latin'], calendar: ['locale', 'persian', 'gregorian']).
Verified Current Behavior
- Static Profiles (
main/countries.tslines 14-18, 50-97): OnlyIRdeclareslocaleOptions. Countries likeUS,CA,GB,IN, etc. havelocaleOptions: undefined. - Backend Validation (
main/routes/settings.tslines 92-102, 183-187):LOCALE_PREFERENCE_VALUESvalidates incoming preference values against a global union set of all possible options across all countries. Consequently, savingcountry: 'US'withcalendar: 'persian'orcurrency_display: 'toman'passes validation! - Default Returns (
main/routes/settings.tslines 143-145):businessShape()falls back to global defaults (currency_display: s.currency_display || 'rial'), causing non-Iran stores to carry phantom display settings. - Frontend Panel (
frontend/src/components/settings/LocalePreferencesPanel.tsx): Renders only when the selected country's profile haslocaleOptions, but the backend does not enforce country-scoped containment on write.
Problem
A client can persist invalid regional preferences for countries that do not support them (e.g. US store persisting Persian calendar or Toman currency display). Furthermore, country transitions (e.g. switching from IR to US, or US to IR) risk leaving stale regional display flags active on the tenant record.
Architectural Decision
- A stored regional preference must be valid according to the active country's
Country.localeOptions. - If a country does not declare
localeOptions(or does not support a specific option group), the active preference must remain neutral/default. - Backward Compatibility Contract:
- Explicit client submission of an unsupported non-default preference (e.g.
PUT /settings/businesswithcountry: 'US'andcalendar: 'persian') -> Return HTTP 400 with a stable error message (Invalid {field} for country {countryCode}). - Stale legacy preferences on existing databases not being explicitly changed -> Safely normalize/default during save without rejecting the request, preventing disruption for older installs.
- Explicit client submission of an unsupported non-default preference (e.g.
- Canonical Storage Invariant:
- Monetary values in the database remain strictly in canonical currency units (e.g. IRR for Iran). Preferences only affect presentation and UI input adapters.
Exact Implementation Scope
- Backend Validation & Normalization (
main/routes/settings.ts):- Scope validation of
currency_display,number_digits, andcalendarinPUT /api/settings/businessagainstgetCountryByCode(effectiveCountry)?.localeOptions. - Reject explicitly provided unsupported options with HTTP 400.
- When switching countries (e.g.
IR->US), normalize/clear unsupported regional preference settings to their neutral defaults (currency_displayreset,number_digits: 'locale',calendar: 'locale'). - For non-Iran countries, ensure
businessShape()does not expose misleading Iran-specific defaults.
- Scope validation of
- Frontend Settings State (
frontend/src/app/(dashboard)/settings/page.tsx):- When the user selects a different country in Settings, reset/re-evaluate the locale preference state to match the newly selected country's
localeOptions.
- When the user selects a different country in Settings, reset/re-evaluate the locale preference state to match the newly selected country's
- Tests:
- Add integration tests covering country transition matrices (
IR->US,US->IR, freshUS, freshIR, legacy non-IR databases).
- Add integration tests covering country transition matrices (
Required Behavior
- Attempting to set
calendar: 'persian'orcurrency_display: 'toman'for aUSorCAstore returns HTTP 400. - Valid
IRstore preferences continue to save and format correctly. - Transitioning a store from
IRtoUSorCAautomatically neutralizes Toman and Persian calendar display preferences. - Existing legacy non-IR databases can update general business settings without validation errors.
- Canonical stored amounts and historical orders/bills remain untouched.
Backward Compatibility / Upgrade Behavior
- Old databases containing legacy default strings continue to function normally.
- Normalization occurs seamlessly during updates without requiring database migration scripts.
Offline-First Requirements
- Purely in-memory and local SQLite execution; 100% offline.
Non-Goals / What NOT to Do
- Do NOT create a complicated generic preference plugin system.
- Do NOT alter canonical database currency storage (no Toman in database).
- Do NOT break existing non-Iran installations when updating business details.
Acceptance Criteria
- Submitting unsupported locale preferences for a country returns HTTP 400.
- Valid locale preferences for
IRcontinue to save and format as expected. - Changing country from
IRto another country cleanses unsupported regional display state. - Existing non-IR tenants can update business settings without validation crashes.
- Canonical monetary storage remains unchanged.
Verification
npm run lint
npm run test:currency
npm run test:rtl-setup-auth-settings
npm testDependencies
- Can be implemented independently or in parallel with Issue fix(settings): allow tenant timezone override independently of country default #389.
Relationship to Epic
- Part of Phase 1 — Regional Correctness in Epic refactor(regionalization): harden country, regional formatting, and international data boundaries #388.
Activity
khaira777 commentedon Aug 20, 2026
Status update — 2026-08-20
282948b1contains the implementation, but the no-mistakes pipeline failed during the review step before a PR was opened. Next stage: address or rerun validation, then allow the gate to create the PR.khaira777 commentedon Aug 20, 2026
Status update — 2026-08-20
🔄 Implementation complete; validation active but currently parked. Commit
282948b1remains intact. The restarted no-mistakes run01M0GRWKXPW6DQW22YGCG29CH8rebased the branch to pipeline head53e7c6b9and is waiting at review.The gate surfaced one real ask-user finding: a timezone-preservation regression in the country-change path, unrelated to the intended locale-preference invariant change. There is still no PR; the next step is to resolve that finding, then continue through tests, lint, push, and PR creation.
khaira777 commentedon Aug 21, 2026
Completed — PR #436 merged
Issue #390 is complete. PR #436 merged into
mainat079edbab.