Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/pages/Search/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function SearchPage({route}: SearchPageProps) {

const shouldUseClientTotal = selectedTransactionsKeys.length > 0 || !metadata?.count || (selectedTransactionsKeys.length > 0 && !areAllMatchingItemsSelected);
const selectedTransactionItems = Object.values(selectedTransactions);
const currency = metadata?.currency ?? selectedTransactionItems.at(0)?.groupCurrency;
const currency = metadata?.currency ?? selectedTransactionItems.at(0)?.groupCurrency ?? selectedTransactionItems.at(0)?.currency;
const numberOfExpense = shouldUseClientTotal
? selectedTransactionsKeys.reduce((count, key) => {
const item = selectedTransactions[key];
Expand All @@ -119,7 +119,7 @@ function SearchPage({route}: SearchPageProps) {
return count + 1;
}, 0)
: metadata?.count;
const total = shouldUseClientTotal ? selectedTransactionItems.reduce((acc, transaction) => acc - (transaction.groupAmount ?? 0), 0) : metadata?.total;
const total = shouldUseClientTotal ? selectedTransactionItems.reduce((acc, transaction) => acc - (transaction.groupAmount ?? -Math.abs(transaction.amount)), 0) : metadata?.total;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid summing mixed-currency amounts without conversion

When groupAmount is missing, this fallback adds Math.abs(transaction.amount) values directly, but amount is stored in each transaction’s original currency. In the default Expenses view (shouldCalculateTotals=false), selecting transactions with different currencies will now produce a mathematically invalid total and label it with a single currency (from metadata/first item), which misstates spend. The total should only be computed from a common-currency field (e.g., groupAmount) or guarded to same-currency selections.

Useful? React with 👍 / 👎.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a valid observation, but it's not a new problem introduced by this fix - the existing code already sums groupAmount values and labels the total with a single currency. When groupAmount is available, it's converted to the group/policy currency, so mixed currencies work. When it's missing (the bug case), the previous behavior was showing $0.00, which is strictly worse. This fix at least shows a correct total for the common single-currency case. A multi-currency guard could be a follow-up improvement but is outside the scope of this regression fix.


return {count: numberOfExpense, total, currency};
}, [areAllMatchingItemsSelected, metadata?.count, metadata?.currency, metadata?.total, selectedTransactions, selectedTransactionsKeys, shouldAllowFooterTotals]);
Expand Down
Loading