Feb 5
feat(settings): Expand currency state management to allow for per-client and per-invoice configuration
## Current Behavior
When users create a new invoice, the currency is set by `settings.general`
## Desired Behavior
When users create a new invoice, the currency is set by reading the currency from invoice (if set), then by client (if set) and default to `settings.general` if non of them are set.
So that: users with clients in multiple currencies can create invoices for these clients without having to navigate into the Settings > General tab to update the currency.
This avoids:
- extra work for clients and user for wrong invoices sent out
- bad reputation of user towards client for sending out incorrect invoice
- frustration
## Proposed Changes
I propose to update the currency state management to implement the following precedences: invoice > client > settings.general
In the code, this could look something like this:
BEFORE
```
const settings = await db.settings.query();//... in invoice creation handler:
const currency = settings.general.currency;
```
AFTER
```
const settings = await db.settings.query();
//...
// the currency settings is known to exist, so we default assign it
let currency = settings.general.currency;
// currency for client take precedence because a single user may have multiple clients with different currencies
if (client.settings.currency) {
currency = invoices.settings.currency
}
// currency for invoices take precedence because a client may have multiple bank accounts with different currencies
if (invoice.settings.currency) {
currency = invoices.settings.currency
}
```
Pending