feat(costs): let a trip keep its costs as totals only (#1714)

Travellers who track what a trip costs but never split it saw an
Unfinished warning on every expense and a settle-up they had no use for.
A trip now has a costs mode (appended migration, trips.costs_mode, split
by default); totals leaves payers, shares and settling up out of Costs on
desktop and phone through the same gate as a trip of one, and saves new
expenses without a payer. PUT /api/trips/:id and update_trip take it on
budget_edit. The split chips move into their own component.
This commit is contained in:
Maurice
2026-11-13 09:58:17 +01:00
parent c9c419b4ad
commit a70eea5bf2
62 changed files with 778 additions and 104 deletions
+8 -5
View File
@@ -1,4 +1,4 @@
import type { BudgetParticipantFinal, BudgetUnconverted, CostCategory } from '@trek/shared';
import type { BudgetParticipantFinal, BudgetUnconverted, CostCategory, TripCostsMode } from '@trek/shared';
import { readDateFormat } from '../../hooks/useDateFormat';
import { convertBooked, convertedLine, inDisplayCurrency, tripAmountOf } from '../../hooks/useExchangeRates';
import type { BudgetItem } from '../../types';
@@ -174,17 +174,20 @@ export interface CostsSettlementResponse {
/**
* Whether Costs shows the splitting side: who paid, the shares, the balances
* and settling up. A trip of one has nothing to split, since every share is the
* whole amount and nobody can owe anybody (#2689), so it is left out there,
* unless the ledger still names someone else: a traveller who left the trip
* with money open, or members that have not loaded yet.
* and settling up. A trip that keeps its costs as totals only leaves it out
* (#1714), whatever is stored. A trip of one has nothing to split, since every
* share is the whole amount and nobody can owe anybody (#2689), so it is left
* out there too, unless the ledger still names someone else: a traveller who
* left the trip with money open, or members that have not loaded yet.
*/
export function showsSplitting(
costsMode: TripCostsMode | undefined,
memberCount: number,
items: BudgetItem[],
settlement: Pick<CostsSettlementResponse, 'flows' | 'balances'> | null,
me: number
): boolean {
if (costsMode === 'totals') return false;
if (memberCount > 1) return true;
const namesOthers = items.some((e) => [...(e.payers || []), ...(e.members || [])].some((p) => p.user_id !== me));
const moneyOpen = (settlement?.balances || []).some((b) => Math.abs(b.balance) >= 0.005);