App icon indicating copy to clipboard operation
App copied to clipboard

[$175] Report- Pay button is displayed to $0.0 report

Open applause-bot[bot] opened this issue 2 weeks ago • 20 comments

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: v9.5.39-2 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://test-management.browserstack.com/projects/2219752/test-runs/83789013/folder/57605193/62969908/1974347278 Email or phone of affected tester (no customers): N/A Issue reported by: Applause Internal Team Bug source: Regression TC Execution Device used: Windows 10/Chrome App Component: Chat Report View

Action Performed:

Preconditions:

  • Create a new account, create a workspace
  1. Open https://staging.new.expensify.com/
  2. Navigate to workspace chat
  3. Create a $50 expense
  4. Create a -$50 expense
  5. Click Submit button
  6. Click Approve button
  7. Open the Expense report

Expected Result:

Pay button is hidden for a 0.00 report

Actual Result:

Pay button is displayed for a 0.00 report

Workaround:

Unknown

Platforms:

  • [x] Android: App
  • [x] Android: mWeb Chrome
  • [x] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [x] Windows: Chrome
  • [ ] MacOS: Chrome Safari

Screenshots/Videos

https://github.com/user-attachments/assets/03d334b0-71d2-4e6a-9a27-4e909786ad2e

View all open jobs on GitHub

Applause Internal Information Exported by: Rizky Gunawan Bug ID: 7313627

Upwork Automation - Do Not Edit

applause-bot[bot] avatar Nov 16 '26 01:11 applause-bot[bot]

While Applause doesn't embed attachments for this bug, here are the links for quick view: https://platform.applause.com/services/links/v1/external/7777eb5ce8b7f6de4be302143502cbb705a7a0612c87c9ab4182d29c7be1ea5d

applause-bot[bot] avatar Nov 16 '26 01:11 applause-bot[bot]

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

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

Proposal

What is the root cause of that problem?

The report deliberately allows Mark as paid for settled expenses that cancel out to $0. The header exposes that capability using the generic Pay button.

This is a mismatch with the issue’s expected presentation—not a missing check allowing an actual $0 payment.

Code evidence and validation

Six targeted existing tests passed, including cancellation, empty-report, non-reimbursable, and failed-scan cases. No browser reproduction was performed. Confidence: medium for the reported UI diagnosis; the underlying behavior is explicitly supported by code and tests.

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

To meet the stated expectation, hide the primary Pay action for settled zero-total reports, while retaining Mark as paid in the secondary menu so users can still complete them. Keep report-preview behavior consistent.

Do not simply reject every zero-total report in payment eligibility: that would remove the existing completion capability and could misclassify reports whose receipts are still scanning.

Implementation scope and regression coverage

The primary and preview selectors need coordinated changes. Preserve shared settlement eligibility, and add the secondary completion action explicitly: ReportSecondaryActionUtils.ts:1082–1099 currently offers secondary Pay only for held-expense or export-failure cases.

Update the existing zero-balance primary-action expectations. Verify that positive reports retain Pay, settled cancellation reports retain secondary completion, and empty/scanning reports do not become eligible prematurely. Preserve negative-credit behavior and non-reimbursable policy restrictions.

What alternative solutions did you explore? (Optional)

Rename the zero-report button Mark as paid instead. This preserves current behavior with a smaller change, but does not satisfy the stated expectation that Pay be hidden.

Related issue: Ready to pay shows non-reimbursable-only reports until their transactions load concerns the same payment-optional classification, but a different surface and loading condition; it is not a confirmed duplicate.


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


view run

MelvinBot avatar Nov 16 '26 01:11 MelvinBot

Proposal

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

An approved expense report whose total is $0.00 (for example a $50 expense and a -$50 expense) still shows a green Pay $0.00 button in the report header and in the report preview. Nothing is owed on that report, so a Pay button should not be offered there.

What is the root cause of that problem?

This is not a missing check. The behavior was added on purpose in #102347 (for #102215), so that an approved report with nothing left to reimburse can still be closed out with Mark as paid, the same way Classic does it. That PR added hasSettledZeroReimbursableSpend and put it into the three Pay checks:

https://github.com/Expensify/App/blob/e0941699c3021c47f7b8fae79900294bc1780d05/src/libs/ReportUtils.ts#L5610-L5620

  • report header / More menu, isPrimaryPayAction: https://github.com/Expensify/App/blob/e0941699c3021c47f7b8fae79900294bc1780d05/src/libs/ReportPrimaryActionUtils.ts#L257-L267
  • report preview, canPay: https://github.com/Expensify/App/blob/e0941699c3021c47f7b8fae79900294bc1780d05/src/libs/ReportPreviewActionUtils.ts#L182-L192
  • canIOUBePaid, only on the pay-elsewhere path, so the button can only mark as paid and never send money: https://github.com/Expensify/App/blob/e0941699c3021c47f7b8fae79900294bc1780d05/src/libs/ReportUtils.ts#L3546-L3550

The same PR also decided these reports should not be pushed at the payer as something to pay. It added isPayOptional and used it to drop Pay from the LHN badge, the Reports row action (falls back to View) and the Ready to pay to-do:

https://github.com/Expensify/App/blob/e0941699c3021c47f7b8fae79900294bc1780d05/src/libs/ReportUtils.ts#L5622-L5628 https://github.com/Expensify/App/blob/e0941699c3021c47f7b8fae79900294bc1780d05/src/libs/SearchUIUtils.ts#L3131-L3135 https://github.com/Expensify/App/blob/e0941699c3021c47f7b8fae79900294bc1780d05/src/libs/TodosUtils.ts#L168

But the report header and the report preview never got that exclusion. getReportPrimaryAction returns PAY whenever isPrimaryPayAction is true and the expenses aren't all held:

https://github.com/Expensify/App/blob/e0941699c3021c47f7b8fae79900294bc1780d05/src/libs/ReportPrimaryActionUtils.ts#L582-L599

and getReportPreviewAction returns PAY whenever canPay is true:

https://github.com/Expensify/App/blob/e0941699c3021c47f7b8fae79900294bc1780d05/src/libs/ReportPreviewActionUtils.ts#L335-L337

Both then render SettlementButton, whose label is always Pay <amount> (iou.settlePayment), even when the only option in the dropdown is Mark as paid:

https://github.com/Expensify/App/blob/e0941699c3021c47f7b8fae79900294bc1780d05/src/components/SettlementButton/index.tsx#L557-L562

So on the same $0 report the Reports list shows View and the LHN shows no badge, while the header and the preview show a primary "Pay $0.00". That inconsistency is the bug QA is seeing.

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

Keep the Mark as paid capability from #102347, but stop presenting it as the primary Pay action when the report total is $0.

  1. Add a small helper in ReportUtils.ts, next to hasSettledZeroReimbursableSpend. When the total is 0, getMoneyRequestSpendBreakdown returns all three values as 0 (https://github.com/Expensify/App/blob/e0941699c3021c47f7b8fae79900294bc1780d05/src/libs/ReportUtils.ts#L5598-L5602), so this covers +$50/-$50, a single $0 expense, and mixed reimbursable/non-reimbursable that nets to 0:
/** The report total is $0 and every expense has a final value, so nothing is owed and it can only be marked as paid. */
function hasSettledZeroTotal(report: OnyxInputOrEntry<Report>, transactions?: Transaction[]): boolean {
    const spendBreakdown = getMoneyRequestSpendBreakdown(report);
    return spendBreakdown.totalDisplaySpend === 0 && hasSettledZeroReimbursableSpend(spendBreakdown, report, transactions);
}

I would not reuse isPayOptional here. It is also true for non-reimbursable-only reports with a non-zero total, where the header shows "Pay $X" with Mark as paid today. That is a separate behavior and out of scope for this issue.

  1. Report header: skip PAY in getReportPrimaryAction for these reports, so it falls through to Export / Remove hold / nothing, the same as the Reports row:
    if (
        isPrimaryPayAction({...}) &&
        !allExpensesHeld &&
        !hasSettledZeroTotal(report, reportTransactions)
    ) {
        return CONST.REPORT.PRIMARY_ACTIONS.PAY;
    }

I'd put the check here and not inside isPrimaryPayAction, because isPrimaryPayAction is also used by the More menu and by TodosUtils, and the More menu still needs it to be true (step 3).

  1. More menu: keep the close-out. getSecondaryReportActions only adds SECONDARY_ACTIONS.PAY for held expenses or a failed export (https://github.com/Expensify/App/blob/e0941699c3021c47f7b8fae79900294bc1780d05/src/libs/ReportSecondaryActionUtils.ts#L1082-L1099). Add the zero-total case:
        (hasOnlyHeldExpenses(reportTransactions) || didExportFail || hasSettledZeroTotal(report, reportTransactions))

In MoneyReportHeaderSecondaryActions.tsx the PAY entry is labelled Pay $0.00 with a submenu (https://github.com/Expensify/App/blob/e0941699c3021c47f7b8fae79900294bc1780d05/src/components/MoneyReportHeaderActions/MoneyReportHeaderSecondaryActions.tsx#L458-L466). For a zero-total report I'd render it as a single "Mark as paid" item (translate('iou.payElsewhere') with no amount) that calls the existing confirmPayment({paymentType: CONST.IOU.PAYMENT_TYPE.ELSEWHERE}). That way the word "Pay" doesn't come back through the menu, and the hold and delegate checks inside confirmPayment still apply.

  1. Report preview: same exclusion in getReportPreviewAction, so the preview shows View:
    if (
        canPay(report, isReportArchived, currentUserAccountID, currentUserLogin, bankAccountList, transactions, policy, invoiceReceiverPolicy) &&
        !hasSettledZeroTotal(report, transactions)
    ) {
        return CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY;
    }

canIOUBePaid stays as it is, so the More menu item can still mark the report as paid. The LHN badge, Reports row and to-do already exclude these reports, so they don't change.

Note for the C+/internal reviewer: #102347 deliberately added "Pay $0.00 > Mark as paid" to the header and preview, so it's worth confirming the regression test expectation before we change it. If the team would rather keep a visible primary button, the alternative below is the smaller change.

What specific scenarios should we cover in automated tests to prevent reoccurrence?

tests/unit/ReportPrimaryActionUtilsTest.ts

  • Update should return PAY for expense report whose reimbursable expenses cancel out to 0 (https://github.com/Expensify/App/blob/e0941699c3021c47f7b8fae79900294bc1780d05/tests/unit/ReportPrimaryActionUtilsTest.ts#L1454-L1488) so that the +$50/-$50 approved report does not return PAY.
  • A single $0.00 expense, and a +$50 reimbursable / -$50 non-reimbursable report, also do not return PAY.
  • Reimbursable expenses that cancel out plus a $100 non-reimbursable expense (total $100) still return PAY.
  • A positive report still returns PAY.

tests/unit/ReportSecondaryActionUtilsTest.ts

  • The approved +$50/-$50 report includes SECONDARY_ACTIONS.PAY.
  • A $0 report with a scanning or failed-scan expense, or with no expenses, does not include it.

tests/actions/ReportPreviewActionUtilsTest.ts

  • Update canPay should return PAY for an expense report with a zero total that is ready to be paid (https://github.com/Expensify/App/blob/e0941699c3021c47f7b8fae79900294bc1780d05/tests/actions/ReportPreviewActionUtilsTest.ts#L1343) to expect VIEW from getReportPreviewAction.

tests/actions/IOUTest/ReportWorkflowTest.ts

  • Keep should only allow marking as paid for report whose reimbursable expenses cancel out to 0 (https://github.com/Expensify/App/blob/e0941699c3021c47f7b8fae79900294bc1780d05/tests/actions/IOUTest/ReportWorkflowTest.ts#L4460) passing unchanged, so we know the close-out still works.

What alternative solutions did you explore? (Optional)

  • Keep the primary button but label it "Mark as paid" when the total is $0. Pass a flag into SettlementButton and use iou.payElsewhere as customText. This is the smallest diff and keeps the one-click close-out, but it doesn't match the expected result that the Pay button is hidden, and the header would still push an action that the LHN and Reports list treat as optional.
  • Return false from isPrimaryPayAction / canPay for $0 totals. I rejected this because it would also remove the More menu entry and leave approved $0 reports with no way to close them, which is what #102215 fixed.
  • Use isPayOptional everywhere. I rejected this because it would also hide Pay on non-reimbursable-only reports with a real total, which is outside this issue.

PawanOzha avatar Nov 16 '26 03:11 PawanOzha

Proposal

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

On an approved expense report whose total is $0.00 (for example, where expenses cancel out: a $50 expense and a -$50 expense), the report header and chat report preview display a primary green "Pay $0.00" button. Because nothing is owed on the report, a primary Pay button should not be displayed.

What is the root cause of that problem?

In PR #102347 (addressing #102215), hasSettledZeroReimbursableSpend was introduced so that users could close out approved $0.00 reports using Mark as paid (which was previously impossible).

However, hasSettledZeroReimbursableSpend was included in the primary payment eligibility checks:

  1. ReportPrimaryActionUtils.ts:257-267: isPrimaryPayAction evaluates to true because (nonReimbursableSpend !== 0 || hasSettledZeroReimbursableSpend(...)) passes even when reimbursableSpend === 0 and nonReimbursableSpend === 0. Because isSecondaryAction is not passed by getReportPrimaryAction, it returns !didExportFail (true), causing getReportPrimaryAction to return CONST.REPORT.PRIMARY_ACTIONS.PAY.
  2. ReportPreviewActionUtils.ts:182-192: canPay similarly evaluates to true for hasSettledZeroReimbursableSpend, causing getReportPreviewAction to return CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY.

Consequently:

  • While SearchUIUtils.ts:2493 (isPayOptional) and TodosUtils.ts:168 intentionally hide the Pay action for zero-spend reports, the report header and preview card still expose a primary button labeled "Pay $0.00" (via SettlementButton), opening a dropdown where the only option is "Mark as paid".
  • This contradicts the regression test requirement where the primary Pay button must be hidden for a $0.00 report.

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

We should hide the primary Pay action on the report header and report preview when the settled report balance is $0.00, while preserving the ability to close out the report via "Mark as paid" in the secondary actions ("..." More menu):

  1. src/libs/ReportPrimaryActionUtils.ts: In isPrimaryPayAction, qualify hasSettledZeroReimbursableSpend so that a settled zero-spend report (hasSettledZeroReimbursableSpend(spendBreakdown, report, reportTransactions) && nonReimbursableSpend === 0) is only eligible when called for secondary actions (isSecondaryAction === true):

    const isSettledZeroReport = hasSettledZeroReimbursableSpend(spendBreakdown, report, reportTransactions) && nonReimbursableSpend === 0;
    
    if (
        canPayReport &&
        isExpenseReport &&
        arePaymentsEnabled &&
        isReportFinished &&
        (reimbursableSpend !== 0 ||
            ((nonReimbursableSpend !== 0 || (isSettledZeroReport && isSecondaryAction)) &&
                !(policy?.preventPayoutNonReimbursableReports && hasOnlyNonReimbursableTransactions(report?.reportID, reportTransactions))))
    ) {
        return isSecondaryAction ?? !didExportFail;
    }
    

    This ensures getReportPrimaryAction will not return CONST.REPORT.PRIMARY_ACTIONS.PAY when the total is $0.00 (falling through cleanly to EXPORT_TO_ACCOUNTING if an integration is connected, or empty string).

  2. src/libs/ReportPreviewActionUtils.ts: In canPay, exclude reports where hasSettledZeroReimbursableSpend is true and nonReimbursableSpend === 0:

    const isSettledZeroReport = hasSettledZeroReimbursableSpend(spendBreakdown, report, transactions) && nonReimbursableSpend === 0;
    
    if (
        isExpense &&
        canPayReport &&
        isPaymentsEnabled &&
        isReportFinished &&
        !isSettledZeroReport &&
        (reimbursableSpend !== 0 ||
            (nonReimbursableSpend !== 0 && !(policy?.preventPayoutNonReimbursableReports && hasOnlyNonReimbursableTransactions(report?.reportID, transactions))))
    ) {
        return !didExportFail;
    }
    

    This ensures getReportPreviewAction falls through to EXPORT_TO_ACCOUNTING or VIEW.

  3. src/libs/ReportSecondaryActionUtils.ts: In getSecondaryReportActions, permit CONST.REPORT.SECONDARY_ACTIONS.PAY when the report is a settled zero-spend report so the approver can close it out:

    const spendBreakdown = getMoneyRequestSpendBreakdown(report);
    const isSettledZeroReport = hasSettledZeroReimbursableSpend(spendBreakdown, report, reportTransactions) && spendBreakdown.nonReimbursableSpend === 0;
    
    if (
        isPrimaryPayAction({
            report,
            reportTransactions,
            currentUserAccountID,
            currentUserLogin,
            bankAccountList,
            policy,
            reportNameValuePairs,
            isChatReportArchived,
            reportActions,
            isSecondaryAction: true,
            canNonPayerAdminPay: true,
        }) &&
        (hasOnlyHeldExpenses(reportTransactions) || didExportFail || isSettledZeroReport)
    ) {
        options.push(CONST.REPORT.SECONDARY_ACTIONS.PAY);
    }
    
  4. src/components/MoneyReportHeaderActions/MoneyReportHeaderSecondaryActions.tsx: When rendering CONST.REPORT.SECONDARY_ACTIONS.PAY for a settled zero report (where onlyShowPayElsewhere is true and total is $0), rather than displaying a nested submenu labeled "Pay $0.00" with a single child item, render it directly as a single menu action:

    • Label: translate('iou.payElsewhere') ("Mark as paid")
    • Icon: expensifyIcons.Cash (or expensifyIcons.Checkmark)
    • onSelected: calls confirmPayment({paymentType: CONST.IOU.PAYMENT_TYPE.ELSEWHERE}) directly, maintaining all delegate and hold verifications.

What alternative solutions did you explore? (Optional)

  1. Change the primary button label to "Mark as paid" instead of hiding it: In SettlementButton, if onlyShowPayElsewhere is true and amount is 0, display translate('iou.payElsewhere') ("Mark as paid") as customText. While this provides a one-click primary close-out button, it does not satisfy the regression test's explicit expected result that the Pay button is hidden for a $0.00 report.
  2. Add a separate helper hasSettledZeroTotal in ReportUtils.ts: Unnecessary, because spendBreakdown is already computed in each caller, and hasSettledZeroReimbursableSpend(...) && nonReimbursableSpend === 0 precisely defines a settled $0 report without adding new global helper functions.

What specific scenarios should we cover in automated tests to prevent reoccurrence?

  1. tests/unit/ReportPrimaryActionUtilsTest.ts:
    • Update should return PAY for expense report whose reimbursable expenses cancel out to 0 to verify that getReportPrimaryAction returns '' (or EXPORT_TO_ACCOUNTING if an integration exists), confirming PAY is hidden.
    • Verify that positive reports (e.g. +$50 reimbursable) continue to return CONST.REPORT.PRIMARY_ACTIONS.PAY.
    • Verify that reports with reimbursable cancelling to $0 plus non-reimbursable spend (e.g. +$50 / -$50 reimbursable, +$100 non-reimbursable) still return CONST.REPORT.PRIMARY_ACTIONS.PAY.
  2. tests/unit/ReportSecondaryActionUtilsTest.ts:
    • Test that an approved expense report whose expenses cancel out to $0 includes CONST.REPORT.SECONDARY_ACTIONS.PAY in getSecondaryReportActions.
    • Test that a $0 report with scanning, pending, or failed-scan transactions does NOT include CONST.REPORT.SECONDARY_ACTIONS.PAY.
  3. tests/actions/ReportPreviewActionUtilsTest.ts:
    • Update canPay should return PAY for an expense report with a zero total that is ready to be paid to verify that getReportPreviewAction returns CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW.
  4. tests/actions/IOUTest/ReportWorkflowTest.ts:
    • Verify that canIOUBePaid(fakeReport, ..., cancellingTransactions, true, false) remains true, confirming the report can successfully be marked as paid.

Contributor details

  • Email: [email protected]
  • Upwork Profile: https://www.upwork.com/freelancers/~0131dae36abcf59374

kevinjosh10 avatar Nov 16 '26 04:11 kevinjosh10

Proposal

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

An expense report whose expenses net to $0.00 (such as $50 and -$50) shows a primary Pay $0.00 button after submission and approval. The expected behavior hides Pay on $0.00 reports.

What is the root cause of that problem?

Settled $0.00 expense reports are explicitly marked eligible for primary Pay in both the report header and chat preview selectors:

  1. hasSettledZeroReimbursableSpend (src/libs/ReportUtils.ts:5610-5620) returns true when reimbursableSpend === 0, the total is loaded and non-pending, and settled expenses exist.
  2. Both isPrimaryPayAction (src/libs/ReportPrimaryActionUtils.ts:257-267) and canPay (src/libs/ReportPreviewActionUtils.ts:182-192) call hasSettledZeroReimbursableSpend(...). Therefore getReportPrimaryAction (L582-L599) and getReportPreviewAction (L335-L337) return PAY.
  3. In PayPrimaryAction.tsx:87-113 and useReportPreviewActionDecision.ts:58-84, canIOUBePaid(..., false) returns false. However, canIOUBePaid(..., true) returns true via canShowMarkedAsPaidForZeroReimbursableSpend (src/libs/ReportUtils.ts:3547-3550). This sets onlyShowPayElsewhere = true.
  4. SettlementButton (src/components/SettlementButton/index.tsx:285-287) limits the dropdown to Mark as paid (ELSEWHERE). Meanwhile, lines 557-562 render Pay $0.00 using getTotalAmountForIOUReportPreviewButton (src/libs/MoneyRequestReportUtils.ts:244).

Note for maintainers: PR #102347 added hasSettledZeroReimbursableSpend for #102215 so approved $0 reports can close via Mark as paid.

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

Hide the primary Pay button on $0.00 reports while preserving direct Mark as paid close-out in the More and selection-mode menus:

  1. Add a zero-total helper:
    • Add hasSettledZeroTotal(report, transactions) in src/libs/ReportUtils.ts:5610-5620. Require spendBreakdown.totalDisplaySpend === 0 (L5598-L5602) alongside hasSettledZeroReimbursableSpend(...). That avoids matching reports with non-zero non-reimbursable spend.
  2. Hide primary and preview Pay for $0.00 reports:
  3. Expose direct Mark as paid in More without a submenu:
    • Keep canShowMarkedAsPaidForZeroReimbursableSpend in canIOUBePaid (src/libs/ReportUtils.ts:3547-3550) unchanged so onlyShowPayElsewhere remains true.
    • In getSecondaryReportActions (src/libs/ReportSecondaryActionUtils.ts:1082-1099), include SECONDARY_ACTIONS.PAY when isPrimaryPayAction(..., isSecondaryAction: true) passes and hasSettledZeroTotal(report, reportTransactions) is true. Requiring totalDisplaySpend === 0 prevents adding SECONDARY_ACTIONS.PAY to non-zero non-reimbursable reports.
    • In MoneyReportHeaderSecondaryActions.tsx:290-304, pass nonPendingDeleteTransactions instead of undefined (lines 297 and 304) to canIOUBePaidAction so onlyShowPayElsewhere stays accurate.
    • In MoneyReportHeaderSecondaryActions.tsx:458-466, check onlyShowPayElsewhere && hasSettledZeroTotal(moneyRequestReport, nonPendingDeleteTransactions). Render translate('iou.payElsewhere', '') (Mark as paid), omit rightIcon, backButtonText, and subMenuItems, and set onSelected to call onPaymentSelect(undefined, CONST.IOU.PAYMENT_TYPE.ELSEWHERE, () => {}) (L476-L511). Routing through onPaymentSelect instead of calling confirmPayment directly preserves selectPaymentType and its shouldRestrictUserBillableActions guard (PaymentUtils.ts:251-254) while avoiding a redundant submenu showing Mark $0.00 as paid (src/hooks/usePaymentOptions.ts:130).
  4. Fix selection-mode Pay $0.00 and submenu leaks:
    • When secondaryActions includes SECONDARY_ACTIONS.PAY, hasPayAction becomes true in useSelectionModeReportActions.ts:207 and MoneyReportHeaderSelectionDropdown.tsx:180.
    • In MoneyReportHeaderSelectionDropdown.tsx:183-197, pass nonPendingDeleteTransactions instead of undefined (lines 190 and 197) to canIOUBePaidAction so onlyShowPayElsewhere stays accurate.
    • Both useSelectionModeReportActions.ts:282-293 (line 284) and MoneyReportHeaderSelectionDropdown.tsx:293-305 (line 296) still render Pay $0.00 with rightIcon and paymentSubMenuItems.
    • When onlyShowPayElsewhere && hasSettledZeroTotal(...) is true, render translate('iou.payElsewhere', '') (Mark as paid) in both menus and omit rightIcon, backButtonText, and subMenuItems:
      • In MoneyReportHeaderSelectionDropdown.tsx, set onSelected to call onSelectionModePaymentSelect(undefined, CONST.IOU.PAYMENT_TYPE.ELSEWHERE, () => {}) (L204, useSelectionModePayment.ts:351-353), preserving runPaymentAction (isAccountLocked at useSelectionModePayment.ts:157-160) and selectPaymentType.
      • In useSelectionModeReportActions.ts, set onSelected to call runPaymentAction(CONST.IOU.PAYMENT_TYPE.ELSEWHERE, false, () => invokePaymentSelect(undefined, CONST.IOU.PAYMENT_TYPE.ELSEWHERE, () => {})) (L219-L220). Passing deferBlockingPresentation = false directly avoids onSelectionModePaymentSelect's TransitionTracker.runAfterTransitions wrapper (L246-L253) so BulkActionBarButton does not wait on a popover transition while still running isAccountLocked and selectPaymentType.
  5. Update and add tests:

What alternative solutions did you explore? (Optional)

  • Rename the primary button to Mark as paid: If #102215 still governs product behavior, SettlementButton (src/components/SettlementButton/index.tsx:557-562) could render Mark as paid on $0 reports. However, that keeps the primary button visible, contradicting this issue's expected result.
  • Remove hasSettledZeroReimbursableSpend from canIOUBePaid: Rejected because it blocks Mark as paid completion on settled $0.00 reports, regressing #102215.

Contributor: Upwork · [email protected]

— submitted with Antigravity on the contributor's behalf

HindsightWise avatar Nov 16 '26 05:11 HindsightWise

Contributor details:

  • Expensify account email: [email protected]
  • Upwork profile: https://www.upwork.com/freelancers/~013b564a690d9bcdab

Proposal

Problem

An approved expense report whose total is $0.00 (for example $50 + -$50) still shows a green primary Pay $0.00 button in the report header and in the chat report preview. The expected behaviour is no Pay button: nothing is owed, and the report should only be closed with Mark as paid.

Root cause

PR #102347 (for #102215) deliberately made $0 reports closable with Mark as paid, by adding hasSettledZeroReimbursableSpend (src/libs/ReportUtils.ts) to the three Pay checks: isPrimaryPayAction, canPay, and canIOUBePaid. The same PR added isPayOptional and excluded these reports from the LHN badge, the Reports row action and the Pay to-do. But the header primary action and the report preview were never given that exclusion, so they still render SettlementButton labelled Pay $0.00 (iou.settlePayment) even though the only option in its dropdown is Mark as paid. The issue is therefore a presentation mismatch: the header and preview disagree with the rest of the app about a $0 report.

Changes

  1. New helper in src/libs/ReportUtils.ts, next to hasSettledZeroReimbursableSpend:

    function hasSettledZeroTotal(report, transactions) {
        const spendBreakdown = getMoneyRequestSpendBreakdown(report);
        return spendBreakdown.totalDisplaySpend === 0 && hasSettledZeroReimbursableSpend(spendBreakdown, report, transactions);
    }
    

    totalDisplaySpend === 0 is the discriminator (not isPayOptional, which is also true for non-reimbursable-only reports with a non-zero total, where the header legitimately shows "Pay $X" - out of scope). It covers a $0 report made of reimbursable expenses that cancel out, a single $0 expense, and a mix of reimbursable/non-reimbursable expenses netting to $0. Fail-closed is inherited: hasSettledZeroReimbursableSpend returns false while any expense is scanning, failed to scan, or a pending card charge, so a $0 report with an unknown amount keeps its Pay path.

  2. Report header - src/libs/ReportPrimaryActionUtils.ts (getReportPrimaryAction): skip PAY when hasSettledZeroTotal(report, reportTransactions). The check goes at the call site, not inside isPrimaryPayAction, so the shared predicate keeps its meaning for the More menu and the Pay to-do, which both rely on it. An approved $0 report with a connected integration falls through to EXPORT_TO_ACCOUNTING, otherwise to no primary action - matching the Reports row (View).

  3. More menu - the report stays closable, with the correct label and the correct guard:

    • src/libs/ReportSecondaryActionUtils.ts: add the zero-total case to getSecondaryReportActions, so SECONDARY_ACTIONS.PAY is present for $0 reports.
    • src/components/MoneyReportHeaderActions/MoneyReportHeaderSecondaryActions.tsx: when the report is zero-total and only "Mark as paid" applies, render a SINGLE menu item
      • text translate('iou.payElsewhere', '') ("Mark as paid"), icon Cash, no submenu, no back button.
    • Route that item through the existing onPaymentSelect (which calls selectPaymentType and therefore the shouldRestrictUserBillableActions guard), instead of calling confirmPayment directly. A direct call would skip the billing-restriction redirect that the submenu path applies today.
    • Pass the real nonPendingDeleteTransactions (not undefined) to canIOUBePaidAction, so onlyShowPayElsewhere is computed from the same transaction list the rest of the header uses.
    • canIOUBePaid itself is NOT changed - the report can still be marked as paid.
  4. Report preview - src/libs/ReportPreviewActionUtils.ts (getReportPreviewAction): same exclusion; a $0 report falls through to EXPORT_TO_ACCOUNTING if an integration is connected, otherwise to VIEW. The isPaidAnimationRunning / isApprovedAnimationRunning early-return is left untouched.

  5. Selection mode - once the More menu has SECONDARY_ACTIONS.PAY, hasPayAction becomes true in useSelectionModeReportActions.ts and MoneyReportHeaderSelectionDropdown.tsx, so selection mode would still offer Pay $0.00. Apply the same single-item rendering there ("Mark as paid", no submenu), routed through onSelectionModePaymentSelect / runPaymentAction so isAccountLocked and selectPaymentType still apply.

Not changed: canIOUBePaid, isPayOptional, the LHN badge, the Search row action, the Pay to-do, isPrimaryPayAction itself, and non-reimbursable-only reports with a non-zero total (they keep today's behaviour).

Tests

  • tests/unit/ReportPrimaryActionUtilsTest.ts: flip both $0 tests - the non-reimbursable-only $0 report and the cancel-out $0 report no longer return PAY. (These are the #102347 regression tests; flipping them is the intended behaviour change for this issue.) Add: a single $0 expense does not return PAY; +$50 reimbursable / -$50 non-reimbursable does not return PAY; +$50/-$50 reimbursable + $100 non-reimbursable (total $100) still returns PAY; a $0 report with a failed-scan expense still does not return PAY (fail-closed, unchanged).
  • tests/actions/ReportPreviewActionUtilsTest.ts: flip both $0 tests - the preview returns VIEW (or EXPORT_TO_ACCOUNTING where an integration is connected).
  • tests/unit/ReportSecondaryActionUtilsTest.ts: add a case that an approved $0 cancel-out report includes SECONDARY_ACTIONS.PAY, and that a $0 report with a scanning / pending / failed-scan expense does not.
  • tests/actions/IOUTest/ReportWorkflowTest.ts: verify (no change) that canIOUBePaid stays true for the $0 report - it can still be marked as paid.

Alternatives considered

  • Return false from isPrimaryPayAction / canPay / canIOUBePaid for $0 reports. Rejected: it would remove the More-menu close-out path as well, leaving the report unclosable - the capability PR #102347 deliberately added.
  • Reuse isPayOptional everywhere. Rejected: it is also true for non-reimbursable-only reports with a non-zero total, which are out of scope for this issue.
  • Gate hasSettledZeroReimbursableSpend on isSecondaryAction inside isPrimaryPayAction. Rejected: isPrimaryPayAction is a shared predicate used by the header, the More menu and the to-do; mutating its meaning is riskier than a call-site check that changes exactly one surface.
  • Relabel the primary button to "Mark as paid". Rejected: it keeps a prominent action for a report with nothing to pay, and the header would still disagree with the LHN badge, the Reports row and the to-do.

dankezo avatar Nov 16 '26 06:11 dankezo

📣 @dankezo! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details. Screen Shot 2022-11-16 at 4 42 54 PM Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

melvin-bot[bot] avatar Nov 16 '26 06:11 melvin-bot[bot]

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

dankezo avatar Nov 16 '26 06:11 dankezo

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

melvin-bot[bot] avatar Nov 16 '26 06:11 melvin-bot[bot]

I think this is expected behavior from https://github.com/Expensify/App/issues/102215, not a bug

@trjExpensify can you confirm whether we want to keep the current behavior?

daledah avatar Nov 16 '26 09:11 daledah

Proposal updated: please review this version of my proposal above (https://github.com/Expensify/App/issues/106952#issuecomment-6909279551), reformatted into the official template. The solution and scope are unchanged.

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

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

An approved expense report whose total is $0.00 (for example $50 + -$50) still shows a green primary Pay $0.00 button in the report header and in the chat report preview. The expected behaviour is no Pay button: nothing is owed, and the report should only be closed with Mark as paid.

What is the root cause of that problem?

PR #102347 (for #102215) deliberately made $0 reports closable with Mark as paid, by adding hasSettledZeroReimbursableSpend (src/libs/ReportUtils.ts) to the three Pay checks: isPrimaryPayAction, canPay, and canIOUBePaid. The same PR added isPayOptional and excluded these reports from the LHN badge, the Reports row action and the Pay to-do. But the header primary action and the report preview were never given that exclusion, so they still render SettlementButton labelled Pay $0.00 (iou.settlePayment) even though the only option in its dropdown is Mark as paid. The issue is therefore a presentation mismatch: the header and preview disagree with the rest of the app about a $0 report.

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

  1. New helper in src/libs/ReportUtils.ts, next to hasSettledZeroReimbursableSpend:

    function hasSettledZeroTotal(report, transactions) {
        const spendBreakdown = getMoneyRequestSpendBreakdown(report);
        return spendBreakdown.totalDisplaySpend === 0 && hasSettledZeroReimbursableSpend(spendBreakdown, report, transactions);
    }
    

    totalDisplaySpend === 0 is the discriminator (not isPayOptional, which is also true for non-reimbursable-only reports with a non-zero total, where the header legitimately shows "Pay $X" - out of scope). It covers a $0 report made of reimbursable expenses that cancel out, a single $0 expense, and a mix of reimbursable/non-reimbursable expenses netting to $0. Fail-closed is inherited: hasSettledZeroReimbursableSpend returns false while any expense is scanning, failed to scan, or a pending card charge, so a $0 report with an unknown amount keeps its Pay path.

  2. Report header - src/libs/ReportPrimaryActionUtils.ts (getReportPrimaryAction): skip PAY when hasSettledZeroTotal(report, reportTransactions). The check goes at the call site, not inside isPrimaryPayAction, so the shared predicate keeps its meaning for the More menu and the Pay to-do, which both rely on it. An approved $0 report with a connected integration falls through to EXPORT_TO_ACCOUNTING, otherwise to no primary action - matching the Reports row (View).

  3. More menu - the report stays closable, with the correct label and the correct guard:

    • src/libs/ReportSecondaryActionUtils.ts: add the zero-total case to getSecondaryReportActions, so SECONDARY_ACTIONS.PAY is present for $0 reports.
    • src/components/MoneyReportHeaderActions/MoneyReportHeaderSecondaryActions.tsx: when the report is zero-total and only "Mark as paid" applies, render a SINGLE menu item
      • text translate('iou.payElsewhere', '') ("Mark as paid"), icon Cash, no submenu, no back button.
    • Route that item through the existing onPaymentSelect (which calls selectPaymentType and therefore the shouldRestrictUserBillableActions guard), instead of calling confirmPayment directly. A direct call would skip the billing-restriction redirect that the submenu path applies today.
    • Pass the real nonPendingDeleteTransactions (not undefined) to canIOUBePaidAction, so onlyShowPayElsewhere is computed from the same transaction list the rest of the header uses.
    • canIOUBePaid itself is NOT changed - the report can still be marked as paid.
  4. Report preview - src/libs/ReportPreviewActionUtils.ts (getReportPreviewAction): same exclusion; a $0 report falls through to EXPORT_TO_ACCOUNTING if an integration is connected, otherwise to VIEW. The isPaidAnimationRunning / isApprovedAnimationRunning early-return is left untouched.

  5. Selection mode - once the More menu has SECONDARY_ACTIONS.PAY, hasPayAction becomes true in useSelectionModeReportActions.ts and MoneyReportHeaderSelectionDropdown.tsx, so selection mode would still offer Pay $0.00. Apply the same single-item rendering there ("Mark as paid", no submenu), routed through onSelectionModePaymentSelect / runPaymentAction so isAccountLocked and selectPaymentType still apply.

Not changed: canIOUBePaid, isPayOptional, the LHN badge, the Search row action, the Pay to-do, isPrimaryPayAction itself, and non-reimbursable-only reports with a non-zero total (they keep today's behaviour).

Tests:

  • tests/unit/ReportPrimaryActionUtilsTest.ts: flip both $0 tests - the non-reimbursable-only $0 report and the cancel-out $0 report no longer return PAY. (These are the #102347 regression tests; flipping them is the intended behaviour change for this issue.) Add: a single $0 expense does not return PAY; +$50 reimbursable / -$50 non-reimbursable does not return PAY; +$50/-$50 reimbursable + $100 non-reimbursable (total $100) still returns PAY; a $0 report with a failed-scan expense still does not return PAY (fail-closed, unchanged).
  • tests/actions/ReportPreviewActionUtilsTest.ts: flip both $0 tests - the preview returns VIEW (or EXPORT_TO_ACCOUNTING where an integration is connected).
  • tests/unit/ReportSecondaryActionUtilsTest.ts: add a case that an approved $0 cancel-out report includes SECONDARY_ACTIONS.PAY, and that a $0 report with a scanning / pending / failed-scan expense does not.
  • tests/actions/IOUTest/ReportWorkflowTest.ts: verify (no change) that canIOUBePaid stays true for the $0 report - it can still be marked as paid.

What alternative solutions did you explore? (Optional)

  • Return false from isPrimaryPayAction / canPay / canIOUBePaid for $0 reports. Rejected: it would remove the More-menu close-out path as well, leaving the report unclosable - the capability PR #102347 deliberately added.
  • Reuse isPayOptional everywhere. Rejected: it is also true for non-reimbursable-only reports with a non-zero total, which are out of scope for this issue.
  • Gate hasSettledZeroReimbursableSpend on isSecondaryAction inside isPrimaryPayAction. Rejected: isPrimaryPayAction is a shared predicate used by the header, the More menu and the to-do; mutating its meaning is riskier than a call-site check that changes exactly one surface.
  • Relabel the primary button to "Mark as paid". Rejected: it keeps a prominent action for a report with nothing to pay, and the header would still disagree with the LHN badge, the Reports row and the to-do.

dankezo avatar Nov 16 '26 10:11 dankezo

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

melvin-bot[bot] avatar Nov 16 '26 10:11 melvin-bot[bot]

I think this is expected behavior from https://github.com/Expensify/App/issues/102215, not a bug

@trjExpensify can you confirm whether we want to keep the current behavior?

The video in the OP didn't show the options, but if the pay option available is Mark as paid only that's expected. People can manually mark a balanced report as paid. CC: @joekaufmanexpensify

trjExpensify avatar Nov 16 '26 10:11 trjExpensify

@daledah Whoops! This issue is 2 days overdue. Let's get this updated quick!

@daledah Still overdue 6 days?! Let's take care of this!

@joekaufmanexpensify could you please check this comment?

daledah avatar Nov 25 '26 04:11 daledah

Yep, Tom is correct. We intentionally added support for showing mark as paid on a balanced report in this issue.

joekaufmanexpensify avatar Nov 25 '26 13:11 joekaufmanexpensify

Not a bug, so we can close this issue

daledah avatar Nov 26 '26 03:11 daledah