Skip to content

[Due for payment 2026-04-14] Reports - Deleted expense with negative amount is not shown negative #86783

Closed

Description

@mitarachim

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 9.3.51-0
Reproducible in staging?: Yes
Reproducible in production?: N/A - new feature, doesn't exist in prod
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #85818
Email or phone of affected tester (no customers): soidnjsojdiosjiosdjo@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Mac 26.2 / Chrome
App Component: Money Requests

Action Performed:

  1. Go to staging.new.expensify.com
  2. Go to workspace chat.
  3. Create an expense with negative amount.
  4. Delete the expense.
  5. Go to Reports > Expenses.
  6. Click Status, select Deleted and click Apply.

Expected Result:

The expense will show negative amount.

Actual Result:

Deleted expense with negative amount is not shown negative on Reports.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari

Screenshots/Videos

Bug7118360_1774987428451.9.mp4

View all open jobs on GitHub

Activity

  1. added
    DeployBlockerCashThis issue or pull request should block deployment
    BugSomething is broken. Auto assigns a BugZero manager.
    DeployBlockerIndicates it should block deploying the API
    on Mar 31, 2026
  2. melvin-bot commented on Mar 31, 2026

    @melvin-bot

    You have been assigned to this deploy blocker because you recently merged this PR: #85818

  3. melvin-bot commented on Mar 31, 2026

    @melvin-bot

    💬 A slack conversation has been started in #expensify-open-source

  4. github-actions commented on Mar 31, 2026

    @github-actions
    Contributor

    👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

    1. Identify the pull request that introduced this issue and revert it.
    2. Find someone who can quickly fix the issue.
    3. Fix the issue yourself.
  5. OSBotify commented on Mar 31, 2026

    @OSBotify
    Contributor

    🔍 Investigation Summary

    Classification: Frontend bug
    Causing PR: #85818 - "Deleted transactions on search" by @jnowakow (High confidence)
    Related Issues: None

    Recommendation: ROLL FORWARD

    PR #85818 added a significant new feature (deleted transactions support) and is likely a dependency for multiple subsequent PRs. The fix is straightforward: when calculating the amount for deleted transactions, the code needs to recognize them as expense-report-like transactions to preserve the negative sign.

    The fix should add a check in src/libs/ReportUtils.ts in the getTransactionDetails function to treat deleted transactions (reportID === CONST.REPORT.TRASH_REPORT_ID) similarly to how unreported transactions or expense report transactions are handled, ensuring the allowNegative or isFromTrackedExpense parameter is set correctly when calling getTransactionAmount.

    Labels: Keeping DeployBlockerCash (App PR caused the issue), removing DeployBlocker (not a backend issue)

    📋 Detailed Analysis

    Evidence

    PR #85818 introduced support for deleted transactions in the search/reports view. The PR adds:

    • A new TRASH_REPORT_ID constant (-1) to identify deleted transactions
    • A new DELETED status filter for expenses
    • The isDeletedTransaction() helper function
    • UI changes to display deleted transactions with special styling

    However, the PR did not account for how negative amounts should be displayed for deleted transactions.

    Verification

    I verified that PR #85818 modified the following key files:

    • src/libs/ReportUtils.ts - Added deleted status handling
    • src/libs/TransactionUtils/index.ts - Added isDeletedTransaction() function
    • src/libs/SearchUIUtils.ts - Added deleted expense status filtering
    • src/components/TransactionItemRow/index.tsx - Renders the amount via TotalCell
    • src/components/TransactionItemRow/DataCells/TotalCell.tsx - Uses getTransactionDetails() to get amount

    Root Cause

    The bug occurs in src/libs/ReportUtils.ts in the getTransactionDetails function (line 4650-4656):

    const report = getReportOrDraftReport(transaction?.reportID, undefined, ...);
    const isFromExpenseReport = (!isEmptyObject(report) && isExpenseReport(report)) || ...;
    
    return {
        amount: getTransactionAmount(transaction, isFromExpenseReport, 
            transaction?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID, allowNegativeAmount, ...),
        ...
    };

    When a transaction is deleted:

    1. Its reportID is set to CONST.REPORT.TRASH_REPORT_ID (-1)
    2. getReportOrDraftReport() returns an empty/undefined report (because -1 is not a real report)
    3. isFromExpenseReport becomes false
    4. The third parameter isFromTrackedExpense is also false (because reportID is -1, not 0)
    5. With both flags false, getTransactionAmount() takes the Math.abs() path (line 963-965 in TransactionUtils)
    6. This strips the negative sign from the amount

    For normal expense reports, isFromExpenseReport would be true, causing the amount to be negated (line 977-983), preserving negative amounts as negative.

    Deleted transactions should be treated similarly to preserve their original sign.

  6. MelvinBot commented on Mar 31, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    When a transaction is deleted, its reportID is changed to CONST.REPORT.TRASH_REPORT_ID ('-1') — see TransactionUtils/index.ts:140-142:

    function isDeletedTransaction(transaction: {reportID?: string}): boolean {
        return transaction.reportID === CONST.REPORT.TRASH_REPORT_ID;
    }

    This causes the original report context to be lost. In the search display flow, the report is looked up from search data at SearchUIUtils.ts:1730:

    const report = data[`${ONYXKEYS.COLLECTION.REPORT}${transactionItem.reportID}`];

    For deleted transactions, this resolves to data["report_-1"] which is undefined. Then in getTransactionItemCommonFormattedProperties at line 1133:

    const isExpenseReport = report?.type === CONST.REPORT.TYPE.EXPENSE;

    Since report is undefined, isExpenseReport is false. This value is passed to getAmount() in TransactionUtils at line 958-966:

    function getAmount(transaction, isFromExpenseReport = false, ...) {
        if (!isFromExpenseReport && !isFromTrackedExpense && !allowNegative) {
            return Math.abs(transaction?.amount ?? 0); // <-- strips the negative sign
        }
        // Expense report path: negates stored amount
        return -amount;
    }

    The evidence chain: For workspace expenses, amounts are stored with the opposite sign (a -$5 expense is stored as +500). When displayed with isFromExpenseReport=true, the amount is correctly negated back to -500 (displaying as -$5). But after deletion, the report lookup fails → isFromExpenseReport=false → Math.abs(500) = 500 → displays as $5.00 instead of -$5.00.

    The same issue affects the DataCells/TotalCell component at TransactionItemRow/DataCells/TotalCell.tsx:15, which calls getTransactionDetails(transactionItem) — this also loses the report context for deleted transactions since the report field on the transaction section is undefined.

    What changes do you think we should make in order to solve the problem?

    In SearchUIUtils.ts, when building transaction sections in getTransactionsSections, the policy is currently resolved from report?.policyID (line 1754). For deleted transactions, since report is undefined, policy is also undefined. The fix should resolve the policy independently of the report for deleted transactions.

    One approach: when a transaction is detected as deleted (isDeletedTransaction(transactionItem)), try to resolve isExpenseReport using the policy from the transaction's own policyID if available, or fall through to the expense report negation logic. Since deleted transactions have already lost their report context, the getTransactionItemCommonFormattedProperties function should accept a flag (e.g., isDeletedTransaction) and when true, skip the Math.abs() and use the expense report sign convention (-amount), preserving the original amount sign. Alternatively, pass allowNegative = true to getAmount for deleted transactions to avoid the Math.abs() call.

    The most targeted fix would be in getTransactionItemCommonFormattedProperties (around line 1133-1146 of SearchUIUtils.ts): detect if the transaction is deleted, and if so, call getTransactionAmount(transactionItem, isExpenseReport, false, true) (passing allowNegative = true as the 4th argument). This ensures Math.abs() is not applied, and the expense report sign convention is used instead, which correctly restores the negative sign for workspace expenses.

    What alternative solutions did you explore? (Optional)

    • Preserving the original reportID on deleted transactions (backend change) — would be a more robust fix but requires backend coordination.
    • Using disableOppositeConversion = true — returns the raw stored amount, which doesn't work because expense report amounts are stored with opposite sign.
    • Embedding the report in the search data for deleted transactions — backend change that would allow the existing logic to work without modification.

    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.

  7. 3 remaining items

  8. added
    Awaiting PaymentAuto-added when associated PR is deployed to production
    and removed on Apr 7, 2026
  9. changed the title [-]Reports - Deleted expense with negative amount is not shown negative[/-] [+][Due for payment 2026-04-14] Reports - Deleted expense with negative amount is not shown negative[/+] on Apr 7, 2026
  10. melvin-bot commented on Apr 7, 2026

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  11. melvin-bot commented on Apr 7, 2026

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.3.52-9 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2026-04-14. 🎊

  12. melvin-bot commented on Apr 7, 2026

    @melvin-bot

    @luacmartins The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

  13. melvin-bot commented on Apr 7, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.EngineeringReviewingHas a PR in reviewWeeklyKSv2

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions