fix(trips): pin place prices when the trip currency changes

A place price with no currency of its own means "the trip's own currency" —
that is how the PDF export and the place chips read it since #1519. But
rebaseTripCurrency() only pinned budget_items and budget_settlements, so
switching a trip's currency silently redenominated every implicit place
price: a €15 museum on a trip moved to JPY started reading as ¥15. Same
class of mismatch as #1543, on the places surface.

Pin priced, currency-less places to the outgoing currency inside the same
transaction. No amount is rewritten — the figure the user typed keeps its
real-world value, it just stops being ambiguous about which unit it is in.
Bump updated_at as well: it doubles as the optimistic-concurrency token
(#1135), so a client holding the pre-switch row can no longer write the
pin away.

Document place prices in the wiki's currency model, and drop the now-stale
"in EUR" from the PDF export's estimated-cost stat.
This commit is contained in:
jubnl
2026-07-14 20:56:36 +02:00
parent 8267650b2d
commit ecef9e06a5
4 changed files with 49 additions and 3 deletions
+17 -2
View File
@@ -142,7 +142,7 @@ export async function freezeForeignRate(
}
/**
* Re-anchor a trip's budget when its base currency changes (#1543).
* Re-anchor a trip's money when its base currency changes (#1543).
*
* Every frozen `exchange_rate` is "units of the row's currency per 1 *trip*
* currency", and `currency = NULL` means "the trip's own currency" — both are
@@ -156,6 +156,11 @@ export async function freezeForeignRate(
* No stored amount is rewritten — each expense keeps the figure the user typed,
* in the currency they typed it in, and its real-world value is preserved.
*
* Place prices follow the same NULL = "the trip's own currency" convention (that
* is how the PDF export and the place chips read them), so they are pinned too —
* otherwise a €15 museum on a trip switched to JPY starts reading as ¥15. They
* carry no frozen rate, so pinning the currency is all they need.
*
* Must run *before* the (synchronous) trip update, while the old currency is
* still in `trips`, and is a no-op when the currency isn't actually changing.
*/
@@ -193,7 +198,17 @@ export async function rebaseTripCurrency(
}
};
db.transaction(() => { rebase('budget_items'); rebase('budget_settlements'); })();
// Only priced places have anything to denominate; a currency on a free place would
// just be noise. `updated_at` doubles as the optimistic-concurrency token (#1135),
// so bumping it stops a client holding the pre-switch row from writing the pin away.
const pinPlaces = () => {
db.prepare(`
UPDATE places SET currency = ?, updated_at = CURRENT_TIMESTAMP
WHERE trip_id = ? AND price IS NOT NULL AND (currency IS NULL OR currency = '')
`).run(prev, tripId);
};
db.transaction(() => { rebase('budget_items'); rebase('budget_settlements'); pinPlaces(); })();
}
export function createBudgetItem(