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
11 changes: 8 additions & 3 deletions src/pages/AddExistingExpense.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,13 @@ function AddExistingExpense({route}: AddExistingExpensePageType) {
if (!transactions) {
return [];
}
const isIOU = isIOUReport(report);
return Object.values(transactions || {}).filter((item) => {
const isUnreported = isUnreportedTransaction(item);
if (isIOU && !isUnreported) {
return false;
}

const isOnOpenExpenseReport = !!(item?.reportID && (allOpenReports?.[item.reportID] ?? openReportDrafts?.[item.reportID]));
if (!isUnreported && !isOnOpenExpenseReport) {
return false;
Expand All @@ -121,13 +126,13 @@ function AddExistingExpense({route}: AddExistingExpensePageType) {

const transactionAmount = getTransactionDetails(item)?.amount ?? 0;

// Negative values are not allowed for unreported expenses
if (transactionAmount < 0) {
// Only block negative amounts for unreported expenses.
if (transactionAmount < 0 && isUnreported) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Flagging a regression from this PR, caught in #98425 and fixed by #98627.

The eligibility guard added here applied to every target report type:

// Only block negative amounts for unreported expenses.
if (transactionAmount < 0 && isUnreported) {
    return false;
}

The original scope, from #72138 → #72552, was to block negative expenses only on IOU reports. This PR preserved #72552's broader implementation and its test, which overlooked the later clarification on that PR. The result was that negative unreported expenses stopped appearing under Add expenses > Existing expenses for expense reports too — a valid business case (chargebacks, refunds).

The lesson for reviewers: when a guard is carried forward from an earlier PR, re-check the scope it was originally agreed on rather than the implementation that shipped. The test came along with the over-broad behavior, so it confirmed the bug rather than catching it.

return false;
}

// Zero amount expenses are not allowed in IOU reports
if (isIOUReport(report) && transactionAmount === 0) {
if (isIOU && transactionAmount === 0) {
return false;
}

Expand Down
Loading