App icon indicating copy to clipboard operation
App copied to clipboard

[Due for payment 2026-11-25] [$175] Ready to pay shows non-reimbursable-only reports until their transactions load

Open MelvinBot opened this issue 1 month ago • 35 comments

Problem

The Pay to-do ("Ready to pay") includes approved reports that contain only non-reimbursable expenses, if the transactions for those reports are not loaded yet. When the admin opens one of these reports, its transactions load and the report drops out of the Pay to-do. The count goes down by one.

These reports should never appear in the Pay to-do. Show Mark as paid on approved reports with nothing to reimburse made them pay-optional on purpose.

Steps to reproduce

  1. As a workspace admin, have several approved expense reports that contain only non-reimbursable expenses (for example, company card expenses). Do not open them in this session.
  2. Open the Spend page and look at the Ready to pay section and its count.
  3. Open one of the non-reimbursable-only reports, then go back.

Expected: Non-reimbursable-only reports never appear in Ready to pay.

Actual: They appear in Ready to pay until each report's transactions load. After you open a report, the count drops by one and that report disappears from the list.

Root cause

isPayOptional() decides only from loaded transactions:

  • ReportUtils.ts:2997-3001: hasOnlyNonReimbursableTransactions() returns false for an empty transaction list.
  • ReportUtils.ts:5500-5501: hasSettledZeroReimbursableSpend() passes the report-total check but then requires at least one loaded expense.
  • TodosUtils.ts:164: the Pay bucket filters with !isPayOptional(report, reportTransactions), so an unloaded report counts as payable.

The affected reports already have reimbursableTotal: 0 and nonReimbursableTotal equal to total on the report object.

Suggested fix

When a report's transactions are not loaded, use the report-level totals to decide whether pay is optional. Treat reimbursableTotal === 0 with a non-zero nonReimbursableTotal as pay-optional.

Keep the transaction-based check when transactions are loaded. hasSettledZeroReimbursableSpend() fails closed on purpose: a receipt that is still scanning can show $0 reimbursable even when it isn't. TodoBucketContext already has an areTransactionsLoaded flag (TodosUtils.ts:104) that you can use to tell "not loaded" apart from "no expenses".

This is a frontend-only fix.

Reported in Slack.

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @mallenexpensify

MelvinBot avatar Oct 29 '26 19:10 MelvinBot

Triggered auto assignment to Contributor-plus team member for initial proposal review - @jayeshmangwani (External)

melvin-bot[bot] avatar Oct 29 '26 19:10 melvin-bot[bot]

Job added to Upwork: https://www.upwork.com/jobs/~022115882276320875460

melvin-bot[bot] avatar Oct 29 '26 19:10 melvin-bot[bot]

@MelvinBot could you please draft a proposal for this issue using Expensify's standard guidelines?

joekaufmanexpensify avatar Oct 29 '26 19:10 joekaufmanexpensify

Proposal

What is the root cause of that problem?

The Pay bucket hides pay-optional reports with !isPayOptional(report, reportTransactions). isPayOptional() only looks at loaded transactions. When a report's transactions are not in Onyx yet, reportTransactions is empty, so both checks return false:

  • hasOnlyNonReimbursableTransactions() returns false for an empty list.
  • hasSettledZeroReimbursableSpend() passes the report-total checks, then requires expenses.length > 0.

The report then counts as payable, even though its report-level totals already say nothing is reimbursable.

Code references

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

In ReportUtils.ts, add a report-total fallback to isPayOptional() that applies only when the report has no loaded transactions:

  1. Add a helper, for example hasOnlyNonReimbursableTotal(report). It returns true when:
    • the report is an expense report,
    • its total is loaded (total or reimbursableTotal is defined) and not pending (isReportTotalPending),
    • getMoneyRequestSpendBreakdown(report) gives reimbursableSpend === 0 and nonReimbursableSpend !== 0.
  2. In isPayOptional(), resolve the report's transactions. If the list (excluding pending deletes) is empty, return the result of this helper. Otherwise, keep the current transaction-based checks unchanged.

This keeps the fail-closed behavior of hasSettledZeroReimbursableSpend() whenever transactions are loaded, for example a receipt that is still scanning. Because the fix is in isPayOptional(), the Pay to-do and the LHN Pay badge stay consistent.

Add unit tests:

  • ReportUtilsTest.ts: isPayOptional() returns true for an approved report with reimbursableTotal: 0, a non-zero nonReimbursableTotal, and no transactions. It returns false when reimbursableTotal is non-zero or the total is pending.
  • TodosUtilsTest.ts: such a report is not in reportsToPay before its transactions load.

What alternative solutions did you explore? (Optional)

Gate the fallback on areTransactionsLoaded from TodoBucketContext, as the issue suggests. That flag only means the whole transaction collection has hydrated (TodosUtils.ts:103-104). It does not tell you whether one specific report's transactions were fetched. This bug is about reports whose transactions were never fetched, so the flag would often be true here and the bug would remain. An empty per-report list is the reliable signal, and an approved report with a non-zero nonReimbursableTotal cannot have zero expenses.


Next Steps for Contributor+ team: To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/105413) to create a draft PR. To refine: @MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.


view run

MelvinBot avatar Oct 29 '26 19:10 MelvinBot

Proposal:

Please re-state the problem that we are trying to solve in this issue.

Approved expense reports that contain only non-reimbursable expenses (such as company card expenses) appear in the "Ready to pay" section and count towards the Pay to-do until the report is opened and its transactions load into Onyx. Once opened, the report drops out of "Ready to pay" and the count decreases. They should never appear in "Ready to pay" because paying them is optional (Mark as paid).

What is the root cause of that problem?

  1. In src/libs/TodosUtils.ts:164, the CONST.SEARCH.SEARCH_KEYS.PAY bucket filters out pay-optional reports with !isPayOptional(report, reportTransactions).
  2. In src/libs/ReportUtils.ts:5474-5476, isPayOptional decides purely based on loaded transactions:
    function isPayOptional(report: OnyxInputOrEntry<Report>, transactionsParam?: Transaction[]): boolean {
        return hasOnlyNonReimbursableTransactions(report?.reportID, transactionsParam) || hasSettledZeroReimbursableSpend(getMoneyRequestSpendBreakdown(report), report, transactionsParam);
    }
    
  3. When an approved report has not been opened yet in the session, reportTransactions is empty ([]). Both helper functions fail:
    • hasOnlyNonReimbursableTransactions returns false when transactions.length === 0 (ReportUtils.ts:2994-2996).
    • hasSettledZeroReimbursableSpend requires expenses.length > 0 (ReportUtils.ts:5467).
  4. As a result, isPayOptional returns false, causing !isPayOptional(report, reportTransactions) to evaluate to true. The report is counted as payable in reportsToPay and in the LHN action badge (ReportUtils.ts:3558), even though the report object itself already has reimbursableTotal === 0 and a non-zero nonReimbursableTotal.

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

In src/libs/ReportUtils.ts:

  1. Add a helper hasOnlyNonReimbursableTotal(report) that checks whether the report's settled totals show only non-reimbursable spend:

    /**
     * Whether an expense report's loaded totals show only non-reimbursable spend and no reimbursable spend.
     * Used as a fallback when the report's transactions have not loaded yet.
     */
    function hasOnlyNonReimbursableTotal(report: OnyxInputOrEntry<Report>): boolean {
        if (!isExpenseReport(report)) {
            return false;
        }
        const isTotalLoaded = report?.total !== undefined || report?.reimbursableTotal !== undefined;
        if (!isTotalLoaded || isReportTotalPending(report)) {
            return false;
        }
        const {reimbursableSpend, nonReimbursableSpend} = getMoneyRequestSpendBreakdown(report);
        return reimbursableSpend === 0 && nonReimbursableSpend !== 0;
    }
    
  2. Update isPayOptional to fall back to hasOnlyNonReimbursableTotal(report) when the resolved transactions list (excluding pending deletes) is empty:

    function isPayOptional(report: OnyxInputOrEntry<Report>, transactionsParam?: Transaction[]): boolean {
        const transactions = resolveReportTransactions(report?.reportID, transactionsParam).filter((transaction) => !isTransactionPendingDelete(transaction));
        if (transactions.length > 0) {
            return hasOnlyNonReimbursableTransactions(report?.reportID, transactions) || hasSettledZeroReimbursableSpend(getMoneyRequestSpendBreakdown(report), report, transactions);
        }
        return hasOnlyNonReimbursableTotal(report);
    }
    
  3. Export hasOnlyNonReimbursableTotal from ReportUtils.ts for unit testing.

Why this solution is safe:

  • When transactions are loaded, the exact existing transaction-based checks run unchanged.
  • For $0 cancel-out reports (reimbursableSpend === 0 && nonReimbursableSpend === 0), hasSettledZeroReimbursableSpend continues to fail closed until transactions load (protecting against receipts that are still smart-scanning).
  • Because isPayOptional is also used by getBadgeFromIOUReport (ReportUtils.ts:3558), this fix simultaneously ensures consistency between the "Ready to pay" to-do bucket and the LHN Pay badge.

What alternative solutions did you explore? (Optional)

Using areTransactionsLoaded from TodoBucketContext in TodosUtils.ts: Rejected because areTransactionsLoaded only tracks whether the global Onyx transaction collection has hydrated from disk (TodosUtils.ts:103-104). It does not indicate whether transactions for a specific individual report were fetched from the server. Furthermore, handling it in isPayOptional in ReportUtils.ts ensures that both TodosUtils and ReportUtils (LHN Pay badge) stay 100% in sync without duplicating fallback logic.

What automated tests can you add to prevent this from re-occurring?

In tests/unit/ReportUtilsTest.ts under describe('isPayOptional'):

it('returns true when a non-reimbursable-only report has no loaded transactions', () => {
    // Given an approved report whose totals show only non-reimbursable spend, but no transactions are loaded yet
    const report: Report = {...expenseReport, total: -5000, nonReimbursableTotal: -5000, reimbursableTotal: 0};

    // When checking whether paying it is optional with an empty transaction list
    // Then it is optional, so it does not surface in Ready to pay before transactions load
    expect(isPayOptional(report, [])).toBe(true);
});

it('returns false when transactions are not loaded and the report total is pending', () => {
    // Given a report with non-reimbursable total whose total is still pending
    const report: Report = {...expenseReport, total: -5000, nonReimbursableTotal: -5000, reimbursableTotal: 0, pendingFields: {total: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}};

    // When checking whether paying it is optional
    // Then it fails closed and returns false
    expect(isPayOptional(report, [])).toBe(false);
});

In tests/unit/TodosUtilsTest.ts: Add a test verifying that createTodosReportsAndTransactions excludes an approved report with reimbursableTotal: 0 and non-zero nonReimbursableTotal from reportsToPay when passed an empty transactions map.

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~014bb7d4c250a1fe03

Abdibaye avatar Oct 29 '26 19:10 Abdibaye

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Oct 29 '26 19:10 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

Approved expense reports that contain solely non-reimbursable expenses (such as company card charges) erroneously appear in the Ready to pay ("Pay") to-do bucket on the Spend page if their transactions have not been loaded into Onyx yet in the current session. Once an admin opens one of these reports, its transactions load into cache, and the report immediately disappears from "Ready to pay" while the badge count decrements by one.

What is the root cause of that problem?

In src/libs/TodosUtils.ts, the Pay to-do bucket filters out pay-optional reports using !isPayOptional(report, reportTransactions):

  • isPayOptional() in src/libs/ReportUtils.ts:5471 evaluates:
    return hasOnlyNonReimbursableTransactions(report?.reportID, transactionsParam) || hasSettledZeroReimbursableSpend(getMoneyRequestSpendBreakdown(report), report, transactionsParam);
    
  • When a report's transactions have not yet hydrated in Onyx, resolveReportTransactions(iouReportID, transactionsParam) resolves to an empty array ([]).
  • Consequently:
    1. hasOnlyNonReimbursableTransactions() at ReportUtils.ts:2991 early-returns false when transactions.length === 0.
    2. hasSettledZeroReimbursableSpend() at ReportUtils.ts:5463-5464 requires expenses.length > 0, thus evaluating to false.
  • Both checks fail, causing isPayOptional() to evaluate to false. Therefore, !isPayOptional(...) evaluates to true, mistakenly including the report in the Pay bucket despite its report-level summary fields already confirming zero reimbursable spend (reimbursableTotal === 0 and nonReimbursableTotal !== 0).

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

In src/libs/ReportUtils.ts, enhance isPayOptional() to evaluate report-level spend totals as a fallback when no transactions are currently loaded for that report:

diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts
index dd9296ea..4b210871 100644
--- a/src/libs/ReportUtils.ts
+++ b/src/libs/ReportUtils.ts
@@ -5468,6 +5468,18 @@ function hasSettledZeroReimbursableSpend(spendBreakdown: SpendBreakdown, report:
  * Whether paying the report is optional because nothing is owed on it: every expense is non-reimbursable, or its reimbursable spend is settled at $0.
  * These reports can still be marked as paid from the report, but aren't surfaced as something to pay (LHN badge, Search row action, Pay to-do).
  */
+function hasOnlyNonReimbursableTotals(report: OnyxInputOrEntry<Report>): boolean {
+    if (!isExpenseReport(report)) {
+        return false;
+    }
+    const isTotalLoaded = report?.total !== undefined || report?.reimbursableTotal !== undefined;
+    if (!isTotalLoaded || isReportTotalPending(report)) {
+        return false;
+    }
+    const spendBreakdown = getMoneyRequestSpendBreakdown(report);
+    return spendBreakdown.reimbursableSpend === 0 && Math.abs(spendBreakdown.nonReimbursableSpend) > 0;
+}
+
 function isPayOptional(report: OnyxInputOrEntry<Report>, transactionsParam?: Transaction[]): boolean {
+    const transactions = resolveReportTransactions(report?.reportID, transactionsParam).filter((transaction) => !isTransactionPendingDelete(transaction));
+    if (transactions.length === 0) {
+        return hasOnlyNonReimbursableTotals(report);
+    }
     return hasOnlyNonReimbursableTransactions(report?.reportID, transactionsParam) || hasSettledZeroReimbursableSpend(getMoneyRequestSpendBreakdown(report), report, transactionsParam);
 }

This preserves the fail-closed behavior of hasSettledZeroReimbursableSpend whenever transactions are actually loaded (e.g., in-flight scanning receipts), while accurately classifying unloaded approved reports whose server-calculated totals indicate only non-reimbursable expenses exist. Furthermore, this simultaneously protects SearchUIUtils.ts and the LHN Pay badge (ReportUtils.ts:3555).

What alternative solutions did you explore? (Optional)

Gating solely on areTransactionsLoaded from TodoBucketContext: While TodoBucketContext includes areTransactionsLoaded, that flag indicates global hydration of the transaction collection, not whether transactions for this specific report have been fetched from the server. An unloaded report will have zero per-report transactions even when the global collection has hydrated. Therefore, checking transactions.length === 0 in combination with report-level totals provides the robust, per-report source of truth across all consumers (TodosUtils, SearchUIUtils, and LHN badges).

What automated tests can you add to prevent this from re-occurring?

  1. In tests/unit/ReportUtilsTest.ts:
    • Add a unit test asserting isPayOptional() returns true for an approved expense report with reimbursableTotal: 0, nonReimbursableTotal: -5000, and total: -5000 when no transactions are provided/loaded.
    • Add a unit test asserting isPayOptional() returns false when reimbursableTotal > 0 or when pendingFields.total is set.
    • Add a unit test verifying isPayOptional() continues to evaluate loaded transactions and properly fail-closed for unsettled/scanning expenses.
  2. In tests/unit/TodosUtilsTest.ts:
    • Verify that an approved report containing only non-reimbursable totals is excluded from reportsToPay even when its transaction objects are not yet loaded in Onyx.

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~01f7d7991785f2ee01

apoorv-xs avatar Oct 29 '26 19:10 apoorv-xs

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Oct 29 '26 19:10 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

Approved reports containing strictly non-reimbursable expenses incorrectly appear in the "Ready to pay" to-do list when their transactions have not yet been loaded into Onyx. Once a user opens the report and its transactions load, isPayOptional() evaluates to true, causing the report to disappear from "Ready to pay" and decrementing the count by one.

What is the root cause of that problem?

In src/libs/ReportUtils.ts, isPayOptional() relies on two helper functions: hasOnlyNonReimbursableTransactions(reportTransactions) and hasSettledZeroReimbursableSpend(report, reportTransactions).

When a report's transactions have not been fetched from the server into Onyx, reportTransactions is empty ([] or undefined):

  1. hasOnlyNonReimbursableTransactions() returns false when transactions is empty (src/libs/ReportUtils.ts:2997-3001).
  2. hasSettledZeroReimbursableSpend() passes report-level checks but explicitly requires expenses.length > 0 (src/libs/ReportUtils.ts:5500-5501).

Consequently, isPayOptional() returns false, and TodosUtils.ts:164 includes the unloaded report in the reportsToPay bucket despite its report object already having reimbursableTotal: 0 and nonReimbursableTotal equal to total.

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

In src/libs/ReportUtils.ts, update isPayOptional() so that when reportTransactions is empty or undefined, it uses the report's top-level summary totals (reimbursableTotal and nonReimbursableTotal / total) to determine if the report consists solely of non-reimbursable expenses.

/// src/libs/ReportUtils.ts
function isPayOptional(report: OnyxEntry<Report>, reportTransactions?: Transaction[]): boolean {
    if (!report) {
        return false;
    }

    const hasLoadedTransactions = !!reportTransactions && reportTransactions.length > 0;
    if (!hasLoadedTransactions) {
        const hasZeroReimbursable = report.reimbursableTotal === 0;
        const hasNonReimbursableSpend = (report.nonReimbursableTotal ?? 0) > 0 || (report.total ?? 0) > 0;
        if (hasZeroReimbursable && hasNonReimbursableSpend && !isReportTotalPending(report)) {
            return true;
        }
    }

    return hasOnlyNonReimbursableTransactions(reportTransactions) || hasSettledZeroReimbursableSpend(report, reportTransactions);
}

What alternative solutions did you explore? (Optional)

  1. Gating on areTransactionsLoaded from TodoBucketContext (Issue description suggestion): areTransactionsLoaded only indicates that the initial Onyx transactions collection hydration has completed. Since individual report transactions are fetched on-demand when reports are opened, areTransactionsLoaded will be true even when transactions for a specific un-opened report are not in Onyx. This leaves the bug active for unloaded reports.

  2. MelvinBot Proposal Flaws: MelvinBot proposed introducing a separate hasOnlyNonReimbursableTotal helper calling getMoneyRequestSpendBreakdown(report). getMoneyRequestSpendBreakdown introduces redundant recalculations and object creations when report.reimbursableTotal and report.nonReimbursableTotal / report.total are already normalized properties on the report object itself. Direct field checks inside isPayOptional maintain surgical minimalism (KISS principle) without extra function overhead.

What automated tests can you add to prevent this from re-occurring?

Add unit tests in tests/unit/ReportUtilsTest.ts:

describe('isPayOptional', () => {
    it('returns true for an approved report with reimbursableTotal 0 and positive total when reportTransactions is empty', () => {
        const report = {
            reportID: '1',
            statusNum: CONST.REPORT.STATUS_NUM.APPROVED,
            stateNum: CONST.REPORT.STATE_NUM.APPROVED,
            reimbursableTotal: 0,
            nonReimbursableTotal: 1000,
            total: 1000,
        } as Report;

        expect(ReportUtils.isPayOptional(report, [])).toBe(true);
        expect(ReportUtils.isPayOptional(report, undefined)).toBe(true);
    });

    it('returns false for an approved report when reimbursableTotal is greater than 0 and reportTransactions is empty', () => {
        const report = {
            reportID: '2',
            statusNum: CONST.REPORT.STATUS_NUM.APPROVED,
            stateNum: CONST.REPORT.STATE_NUM.APPROVED,
            reimbursableTotal: 500,
            total: 500,
        } as Report;

        expect(ReportUtils.isPayOptional(report, [])).toBe(false);
    });
});

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~01b60d704ba377be83

camesenin avatar Oct 29 '26 19:10 camesenin

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Oct 29 '26 19:10 melvin-bot[bot]

@jayeshmangwani is @MelvinBot's proposal good here?

joekaufmanexpensify avatar Oct 30 '26 17:10 joekaufmanexpensify

@jayeshmangwani @joekaufmanexpensify Friendly bump on this! My proposal above (submitted earlier at #6506284978) accurately identifies the root cause and provides the clean fix. Ready to begin implementation as soon as assigned on Upwork!

apoorv-xs avatar Oct 30 '26 21:10 apoorv-xs

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~016c1aa34b51059d42

Proposal

Please re-state the problem that we are trying to solve in this issue.

Approved expense reports that contain solely non-reimbursable expenses (e.g. corporate/company card transactions) incorrectly appear in the Ready to pay ("Pay") to-do bucket and LHN action list when their individual transactions have not yet been loaded into Onyx in the active session. When the workspace admin opens one of these reports, its transactions load, causing the report to disappear from "Ready to pay" and decrementing the bucket count by one.

What is the root cause of that problem?

In src/libs/TodosUtils.ts (line 164), the CONST.SEARCH.SEARCH_KEYS.PAY bucket condition filters out pay-optional reports via:

!isPayOptional(report, reportTransactions)

However, isPayOptional() in src/libs/ReportUtils.ts strictly relies on loaded transactions:

  1. hasOnlyNonReimbursableTransactions() (ReportUtils.ts:2997–3001):
    if (!transactions || transactions.length === 0) {
        return false;
    }
    return transactions.every((transaction) => !getReimbursable(transaction));
    
    When transactions are not loaded, transactions is empty, so it returns false.
  2. hasSettledZeroReimbursableSpend() (ReportUtils.ts:5463–5464):
    const expenses = resolveReportTransactions(report?.reportID, transactionsParam).filter((transaction) => !isTransactionPendingDelete(transaction));
    return expenses.length > 0 && !expenses.some((transaction) => isExpenseValueUnsettled(transaction, report ?? undefined, isScanningTransaction));
    
    Even though the report-level totals (reimbursableTotal === 0 and total !== 0) are settled, this check explicitly requires expenses.length > 0, which evaluates to false when transactions are not loaded.

As a result, an approved non-reimbursable-only report whose transactions are not loaded is treated as payable (isPayOptional === false), placing it into the "Ready to pay" to-do bucket until the report is clicked.

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

We should update isPayOptional() in src/libs/ReportUtils.ts to inspect the report-level summary totals when individual transactions have not been loaded or when reportTransactions is empty:

  1. In src/libs/ReportUtils.ts (isPayOptional): Add an optional areTransactionsLoaded?: boolean parameter (or evaluate report totals when transactions is empty):

    function isPayOptional(report: OnyxInputOrEntry<Report>, transactionsParam?: Transaction[], areTransactionsLoaded?: boolean): boolean {
        const spendBreakdown = getMoneyRequestSpendBreakdown(report);
        const isTotalLoaded = report?.total !== undefined || report?.reimbursableTotal !== undefined;
    
        // If transactions are not loaded yet, use reliable report-level totals:
        // When reimbursable spend is settled at 0 and there is settled non-reimbursable spend, paying is optional.
        if (!areTransactionsLoaded && isTotalLoaded && !isReportTotalPending(report)) {
            if (spendBreakdown.reimbursableSpend === 0 && spendBreakdown.nonReimbursableSpend !== 0) {
                return true;
            }
        }
    
        return hasOnlyNonReimbursableTransactions(report?.reportID, transactionsParam) || hasSettledZeroReimbursableSpend(spendBreakdown, report, transactionsParam);
    }
    
  2. In src/libs/TodosUtils.ts (line 164): Pass areTransactionsLoaded from the already-available TodoBucketContext (TodosUtils.ts:104):

    case CONST.SEARCH.SEARCH_KEYS.PAY:
        return (
            isPrimaryPayAction({ ... }) &&
            !isPayOptional(report, reportTransactions, areTransactionsLoaded) &&
            (!allExpensesHeld || currentUserPlacedHold)
        );
    

This preserves the fail-closed protection for pending scanning receipts while allowing TodosUtils to correctly exclude approved non-reimbursable reports before their transaction sub-collections hydrate.

What alternative solutions did you explore? (Optional)

We could modify hasSettledZeroReimbursableSpend directly to bypass expenses.length > 0 when report?.transactionCount > 0, but passing areTransactionsLoaded from TodosUtils cleanly distinguishes "transactions not loaded into memory" from "report has zero expenses".

Tests

  1. Log in as a workspace admin with approved expense reports containing only non-reimbursable (company card) expenses.
  2. Refresh the browser / restart the app so transaction caches are cold.
  3. Navigate to the Spend page / check the LHN Ready to pay count.
  4. Verify that non-reimbursable-only reports do not appear under Ready to pay and do not increment the bucket count.
  5. Open one of the non-reimbursable reports, let its transactions load, and navigate back.
  6. Verify that the bucket count remains unchanged and the report remains excluded from Ready to pay.
  7. Verify that normal reimbursable approved reports still display in Ready to pay as expected.
  • [x] Verify that no errors appear in the JS console

Offline tests

  1. Go offline.
  2. View the Ready to pay to-do list.
  3. Verify that non-reimbursable reports remain excluded offline when transactions are unloaded.

QA Steps

  1. As a workspace admin, ensure you have an approved report with only company card (non-reimbursable) expenses.
  2. Reload the page on web.
  3. Check the "Ready to pay" section on the Spend page.
  4. Confirm the approved non-reimbursable report is not listed in Ready to pay.

bhomvratrai-glitch avatar Nov 01 '26 13:11 bhomvratrai-glitch

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 01 '26 13:11 melvin-bot[bot]

17. @jayeshmangwani is @MelvinBot's proposal good here?

Yes, proposal looks good to move forward with.

jayeshmangwani avatar Nov 02 '26 12:11 jayeshmangwani

@MelvinBot implement this

jayeshmangwani avatar Nov 02 '26 12:11 jayeshmangwani

🤖 Draft PR created: https://github.com/Expensify/App/pull/105618 Please mark it as "Ready for review" or ask me to do that for you when it is ready for review.

When a report's transactions aren't loaded yet, isPayOptional() now uses the report's totals. Non-reimbursable-only reports stay out of Ready to pay before you open them. When transactions are loaded, the existing checks run unchanged.

The new unit tests pass, along with the related suites, typecheck, lint, and spell check. I didn't run the full Jest suite or test in the UI. The human co-author still needs to fill in the Tests and QA sections.


view run

MelvinBot avatar Nov 02 '26 13:11 MelvinBot

@jayeshmangwani can we get this to review soon?

joekaufmanexpensify avatar Nov 04 '26 22:11 joekaufmanexpensify

26. @jayeshmangwani can we get this to review soon?

sorry for the delay. I’m working on it now. The only blocker is that I can’t reproduce the issue on staging, so I’m trying to find a way to reproduce it before confirming the fix.

jayeshmangwani avatar Nov 05 '26 10:11 jayeshmangwani

@MelvinBot please check comments on PR

jayeshmangwani avatar Nov 05 '26 16:11 jayeshmangwani