mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 13:23:04 +00:00
fix(costs): keep convertBooked at five parameters and update the tests to as-typed display rows
The display-currency check is its own helper (inDisplayCurrency), used by the Costs model and the shared trip page. The tests that pinned #2525's reading of a display-currency bill through the trip currency now pin the as-typed reading, which the balances use too; read in the trip currency, such a bill and its repayment may stay a euro cent apart.
This commit is contained in:
@@ -133,19 +133,27 @@ export function convertBooked(
|
||||
frozenRate: number | null | undefined,
|
||||
tripCurrency: string,
|
||||
convertLive: (amount: number, from: string | null | undefined) => number,
|
||||
displayCurrency?: string,
|
||||
): number {
|
||||
const trip = (tripCurrency || 'EUR').toUpperCase()
|
||||
// A row entered in the display currency is shown as typed (#2965): through the
|
||||
// trip currency at its frozen rate and back at today's, it drifted off the
|
||||
// amount entered, and the balances (which net such rows as typed) disagreed.
|
||||
if (displayCurrency && (rowCurrency || trip).toUpperCase() === displayCurrency.toUpperCase()) return amount
|
||||
const inTrip = bookedInTrip(amount, rowCurrency, frozenRate, trip)
|
||||
if (inTrip != null) return convertLive(inTrip, trip)
|
||||
// A NULL currency means the trip's own, and then there was never anything to freeze.
|
||||
return convertLive(amount, (rowCurrency || trip).toUpperCase())
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a row was entered in the display currency (#2965). Such a row counts as typed:
|
||||
* through the trip currency at its frozen rate and back at today's it drifted off the
|
||||
* amount entered, and the balances, which net such rows as typed, would disagree.
|
||||
*/
|
||||
export function inDisplayCurrency(
|
||||
rowCurrency: string | null | undefined,
|
||||
tripCurrency: string,
|
||||
displayCurrency: string,
|
||||
): boolean {
|
||||
return ((rowCurrency || tripCurrency) || '').toUpperCase() === (displayCurrency || '').toUpperCase()
|
||||
}
|
||||
|
||||
/**
|
||||
* The amount a row was booked at in the trip currency, when it was booked through one: a
|
||||
* foreign currency with a frozen rate. Null for a row in the trip currency, and for one
|
||||
|
||||
Reference in New Issue
Block a user