App icon indicating copy to clipboard operation
App copied to clipboard

[Due for payment 2026-11-16] [$175] Web - Scan Receipt - Approve button appears after scan failure

Open vincdargento opened this issue 1 month ago • 31 comments

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Version Number: v9.5.16-1 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from TestRail: https://github.com/Expensify/Expensify/issues/495513 Email or phone of affected tester (no customers): N/A Issue reported by: Applause Internal Team

Action Performed:

Test 1: Preconditions: set up the submissions frequency to instantly on workflow setting, so after uploading the failed scan is directly to approval flow Steps:

  1. Create a scan receipt that will be failed, so it will create a scan failure transactions
  2. Note there's approve button appears on expense preview
  3. Open Spend -> Reports > Outstanding and notice the row of the expense report
  4. Note that approve button appear in that row
  5. Click on this report row

Test 2: Preconditions: set up the submissions frequency to manually on workflow setting Steps:

  1. Create a scan receipt that missing the amount and not missing the merchant (can use the file I attached below)
  2. After the scan is complete, submit the expense

Expected Result:

In test 1:

  • Step 2: should have no approve button appears
  • Step 4: View button appear in large screen
  • no approve button in the header of the report in RHP in after step 5

Test 2: after submitting, the approve button doesn't appear

Actual Result:

Test 1:

  • Step 2: there's approve button appears on expense preview
  • Step 4: approve button appear in that row
  • There's approve button in the header of the report in RHP in after step 5

Test 2: after submitting, the approve button appears

Workaround:

N/A

Platforms:

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

Screenshots/Videos

https://github.com/user-attachments/assets/abdb7dd0-6db7-4151-9d1a-f306a8eb6cfd

https://github.com/user-attachments/assets/917773ec-52f1-416b-a40a-f2b06ce511fa

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

vincdargento avatar Oct 22 '26 14:10 vincdargento

Proposal

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

The Approve button shows on the report preview, on the Search > Reports row, and in the report header when the report's only expense failed SmartScan and is missing required fields such as the amount.

What is the root cause of that problem?

The Approve checks only block expenses that are still scanning (SCAN_READY or SCANNING) or card charges that are still pending. They never check for a failed scan with missing fields. A SCANFAILED receipt passes every Approve check.

Submit already has this check through hasSmartScanFailedWithMissingFields, but Approve never had it. This is a missing check, not a regression. No commit since May 2026 added or removed a scan-failed check from Approve.

Code references

Each surface decides Approve here:

isReceiptBeingScanned is true only for SCAN_READY and SCANNING (TransactionUtils/index.ts:1202-1204).

Submit already uses the scan-failed check:

Test 1 (Instant submit): the backend submits the report automatically, so the client's Submit check never runs. Approve shows because SCANFAILED doesn't count as scanning.

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

  1. Hide Approve when every expense on the report is still scanning, is a pending card charge, or failed SmartScan with missing fields.
  2. Add one helper in TransactionUtils, for example hasOnlyUnsettledExpenses(transactions, report). It returns true when the report has expenses and every one is isPending or isExpenseValueUnsettled.
  3. Use the helper in all four Approve checks:
    • canApproveIOU (Search row and header buttons)
    • ReportPrimaryActionUtils.isApproveAction
    • ReportPreviewActionUtils.canApprove
    • ReportSecondaryActionUtils.isApproveAction
  4. Remove the duplicate check in SearchUIUtils.getActions. With Approve gone, the Search row falls back to View.
  5. Add unit tests for a report with one scan-failed expense (no Approve) and for a mixed report (Approve still shows).

Use "every," not "some." Approving a mixed report with a scan-failed expense is intended. The backend moves the scan-failed expense to a new report, per Fix/96257 relaid optimistic scan failed move.

What alternative solutions did you explore? (Optional)

  • Use "some" like Submit: this would block approval of a whole report because of one failed expense. It conflicts with the intended behavior in Fix/96257 relaid optimistic scan failed move.
  • Make the preview and header call canApproveIOU directly: this is cleaner long term, but the change is larger.
Open question (Test 2)

hasSmartScanFailedWithMissingFields requires the receipt state to be SCANFAILED. If the Test 2 receipt finished as SCAN_COMPLETE with amount 0, neither Submit nor this fix catches it. On expense reports, a zero amount isn't treated as missing in that state (TransactionUtils/amountUtils.ts:14-34). Confirm the receipt.state of the Test 2 expense before implementing. If it is SCAN_COMPLETE, the helper also needs an isScanRequest + isAmountMissing clause.


Next Steps for Contributor+ team: To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/104750) 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 22 '26 14:10 MelvinBot

Proposal

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

When a SmartScan receipt fails, the transaction ends up with a missing required field, usually the amount and sometimes the merchant, and the receipt state is SCANFAILED. The expense report that contains it should not be approvable in that state. Today the Approve button still shows in three places:

  • the expense preview (report preview) on the chat
  • the Reports > Outstanding row in Search, where a View button is expected on large screens
  • the report header in the RHP

This happens in both flows:

  • Instant submit: the failed scan goes straight to approval.
  • Manual submit: the user submits after the scan fails, and Approve then appears.

What is the root cause of that problem?

The approve-eligibility logic ignores whether the report's transactions are incomplete or have a failed scan.

The approve checks already skip a transaction that is still being scanned (isScanning), but nothing covers a scan that has finished with SCANFAILED and left required fields empty (hasMissingSmartscanFields / areRequiredFieldsEmpty). Those fields are the amount, and the merchant on expense reports.

Approve eligibility is computed separately in several places:

  • ReportPrimaryActionUtils.isApproveAction (RHP header)
  • ReportPreviewActionUtils (canApprove / getReportPreviewAction, used by the expense preview)
  • SearchUIUtils.getActions (the Search row)
  • IOU.canApproveIOU (used when approving)

None of these rejects "report contains a scan-failed or missing-required-field transaction", so all three UI surfaces show Approve.

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

  1. Add one shared helper in TransactionUtils (or reuse the existing hasMissingSmartscanFields / isScanFailed helpers) so every surface uses the same rule:
// TransactionUtils.ts
function isScanFailedOrMissingRequiredFields(transaction: OnyxEntry<Transaction>): boolean {
    if (!transaction) return false;
    const isScanFailed = transaction.receipt?.state === CONST.IOU.RECEIPT_STATE.SCAN_FAILED;
    return isScanFailed || hasMissingSmartscanFields(transaction);
}

Make sure the check is limited to SmartScan transactions. Manual and distance expenses must not be affected.

  1. Use the helper in ReportPrimaryActionUtils.isApproveAction, right after the existing isScanning check:
if (reportTransactions.some(isScanFailedOrMissingRequiredFields)) {
    return false;
}
  1. Do the same in the report preview approve check in ReportPreviewActionUtils (canApprove). This hides Approve on the expense preview and makes getReportPreviewAction fall through to the next action, which is the View/Review behaviour.

  2. Do the same in SearchUIUtils.getActions where the approve action is computed for the Search row. The row then shows View instead of Approve.

  3. Optionally guard IOU.canApproveIOU and the secondary Approve action with the same helper, so approval can't be triggered through another path.

  4. Make sure the checks re-evaluate when the scan finishes. The transactions passed in must come from live Onyx data, so Approve disappears or appears as soon as the receipt state changes. This also covers test 2, where the user submits manually after the scan fails.

What alternative solutions did you explore? (Optional)

  • Fix only the report preview component. Rejected because it would leave the RHP header and Search row wrong. Approve eligibility has to be fixed in the shared action-utility functions.
  • Rely on violations such as missingAmount or receiptRequired. Rejected because violations may not exist yet, or may not be loaded, when the scan fails. They also depend on policy settings, so the button could still flash.
  • Block submission when the scan failed. Rejected because it changes the submit flow and is not what the issue asks for. The expected result is only that Approve is hidden.

Testing

  1. Instant submit.
    • Set the workspace to instant submit.
    • Upload a receipt that fails to scan.
    • Confirm the expense preview has no Approve button.
    • In Spend > Reports > Outstanding, confirm the row shows View on a large screen.
    • Open the report and confirm the RHP header has no Approve button.
  2. Manual submit.
    • Set the workspace to manual submit.
    • Upload a receipt that is missing the amount but has a merchant.
    • After the scan completes, submit the expense.
    • Confirm Approve doesn't appear on the preview, in Search, or in the RHP.
  3. Regression. Confirm that a successfully scanned expense, a manual expense, and a distance expense still show Approve for an eligible approver. Confirm that an expense still being scanned still hides it.
  4. Unit tests.
    • Add cases to ReportPrimaryActionUtilsTest, ReportPreviewActionUtilsTest and SearchUIUtilsTest. Each should cover a report whose transaction has receipt.state = SCANFAILED or a missing amount, and assert that the approve action isn't returned.
    • Add a positive control for a complete transaction.
  5. Manual check. Run on Chrome and Safari (web) to confirm the fix on the platforms in the report.

Abdallah-1551 avatar Oct 22 '26 14:10 Abdallah-1551

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

melvin-bot[bot] avatar Oct 22 '26 14:10 melvin-bot[bot]

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

melvin-bot[bot] avatar Oct 22 '26 14:10 melvin-bot[bot]

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

Proposal

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

When a receipt SmartScan fails or is missing required fields (such as amount), the Approve button still incorrectly appears in three locations:

  1. The expense report preview in the chat thread (ReportPreviewActionUtils.ts)
  2. The Search > Reports > Outstanding table row (SearchUIUtils.ts via ReportUtils.canApproveIOU)
  3. The report header / RHP primary action button and secondary actions menu (ReportPrimaryActionUtils.ts & ReportSecondaryActionUtils.ts)

Instead, when an expense has failed SmartScan with missing required fields, the Approve button should not appear (falling through to "View" / "Review").


What is the root cause of that problem?

Across all 4 approval evaluation surfaces, the code only checks whether receipts are actively scanning (isScanning) or transactions are pending card charges (isPending). None of the approval gates check whether SmartScan has failed with missing required fields:

  1. Chat Report Preview (src/libs/ReportPreviewActionUtils.ts:86–123): canSubmit (line 62) already properly blocks submission when scan fails via:

    if (hasSmartScanFailedWithMissingFields(transactions ?? [], report)) {
        return false;
    }
    

    However, canApprove (lines 100–108) only checks isScanning and pending card transactions. It completely omits the hasSmartScanFailedWithMissingFields check.

  2. Report Header Primary Action (src/libs/ReportPrimaryActionUtils.ts:173–206): isApproveAction only checks isScanning and pending transactions at lines 200–205:

    const isAnyReceiptBeingScanned = reportTransactions.some((transaction) => isScanning(transaction));
    if (isAnyReceiptBeingScanned) {
        return false;
    }
    return !reportTransactions.every((transaction) => isPending(transaction));
    

    It never checks if any transactions have failed SmartScan with missing fields.

  3. Report Header Secondary Action Menu (src/libs/ReportSecondaryActionUtils.ts:313–350): isApproveAction in the secondary actions utility checks isReceiptBeingScanned at line 331, but also lacks the hasSmartScanFailedWithMissingFields guard.

  4. Search Table Rows & General IOU Approval (src/libs/ReportUtils.ts:canApproveIOU): SearchUIUtils.ts:2268 calls canApproveIOU(report, policy, reportMetadata, currentUserAccountID, allReportTransactions). In ReportUtils.ts, canApproveIOU checks hasOnlyPendingCardOrScanningTransactions, but does not verify whether transactions in the report have failed SmartScan with missing fields.

Because all four checks omit hasSmartScanFailedWithMissingFields, a report containing a failed scan expense is treated as validly approvable across the entire app.


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

Apply hasSmartScanFailedWithMissingFields symmetrically across all 4 approval gates:

  1. In src/libs/ReportPreviewActionUtils.ts (canApprove): (hasSmartScanFailedWithMissingFields is already imported at line 38 from ./TransactionUtils):

    --- a/src/libs/ReportPreviewActionUtils.ts
    +++ b/src/libs/ReportPreviewActionUtils.ts
    @@ -103,6 +103,10 @@ function canApprove(report: Report, currentUserAccountID: number, reportMetadata
             return false;
         }
    
    +    if (hasSmartScanFailedWithMissingFields(transactions ?? [], report)) {
    +        return false;
    +    }
    +
         if (transactions.length > 0 && transactions.every((transaction) => isPending(transaction))) {
             return false;
         }
    
  2. In src/libs/ReportPrimaryActionUtils.ts (isApproveAction): Import hasSmartScanFailedWithMissingFields from ./TransactionUtils and add the check:

    --- a/src/libs/ReportPrimaryActionUtils.ts
    +++ b/src/libs/ReportPrimaryActionUtils.ts
    @@ -202,6 +202,10 @@ function isApproveAction(report: Report, reportTransactions: Transaction[], curr
             return false;
         }
    
    +    if (hasSmartScanFailedWithMissingFields(reportTransactions ?? [], report)) {
    +        return false;
    +    }
    +
         return !reportTransactions.every((transaction) => isPending(transaction));
     }
    
  3. In src/libs/ReportSecondaryActionUtils.ts (isApproveAction): Import hasSmartScanFailedWithMissingFields from ./TransactionUtils and add the check:

    --- a/src/libs/ReportSecondaryActionUtils.ts
    +++ b/src/libs/ReportSecondaryActionUtils.ts
    @@ -334,6 +334,10 @@ function isApproveAction(
             return false;
         }
    
    +    if (hasSmartScanFailedWithMissingFields(reportTransactions ?? [], report)) {
    +        return false;
    +    }
    +
         const isDEWPolicy = hasDynamicExternalWorkflow(policy);
    
  4. In src/libs/ReportUtils.ts (canApproveIOU): Import hasSmartScanFailedWithMissingFields from ./TransactionUtils and add the check in canApproveIOU:

    --- a/src/libs/ReportUtils.ts
    +++ b/src/libs/ReportUtils.ts
    @@ -3335,6 +3335,10 @@ function canApproveIOU(
         if (hasOnlyPendingCardOrScanningTransactions) {
             return false;
         }
    +    if (hasSmartScanFailedWithMissingFields(reportTransactions ?? [], iouReport)) {
    +        return false;
    +    }
         const isReportPayAtEnd = isPayAtEndExpenseReport(iouReport ?? undefined, reportTransactions);
    

Why this solution is optimal:

  • Comprehensive 4-Surface Coverage: Fixes chat previews, RHP header primary action, three-dots secondary menu, and Search table rows simultaneously.
  • Architectural Parity: Reuses the battle-tested hasSmartScanFailedWithMissingFields helper already used by canSubmit (ReportPreviewActionUtils.ts:62) and isExpenseValueUnsettled (TransactionUtils.ts).
  • No Side Effects on Manual or Distance Expenses: hasSmartScanFailedWithMissingFields specifically targets SmartScan transactions (receipt.state === SCANFAILED with missing required fields) and does not interfere with valid manual or distance transactions.

What alternative solutions did you explore? (Optional)

  1. Fixing only ReportPreviewActionUtils:
    • Rejected because the report header primary action and Search table row would still render the Approve button.
  2. Checking transaction violations (e.g. missingAmount):
    • Rejected because transaction violations are calculated asynchronously or may depend on policy settings, whereas hasSmartScanFailedWithMissingFields checks the core receipt state and required fields immediately on live Onyx data.

What specific scenarios should we cover in automated tests to prevent reintroduction of this issue in the future?

  1. ReportPreviewActionUtilsTest.ts:
    • Call canApprove with an expense report containing a transaction with receipt: {state: CONST.IOU.RECEIPT_STATE.SCAN_FAILED} and amount: 0.
    • Assert that canApprove returns false.
    • Assert that canApprove returns true once the amount is filled and scan failure is resolved.
  2. ReportPrimaryActionUtilsTest.ts:
    • Call isPrimaryApproveAction with a transaction where hasSmartScanFailedWithMissingFields is true.
    • Assert that isPrimaryApproveAction returns false.
  3. ReportUtilsTest.ts:
    • Call canApproveIOU for a report whose transaction has failed SmartScan with missing fields.
    • Assert that canApproveIOU returns false.

HamzaKhanBUIC avatar Oct 22 '26 15:10 HamzaKhanBUIC

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

melvin-bot[bot] avatar Oct 22 '26 15:10 melvin-bot[bot]

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

melvin-bot[bot] avatar Oct 22 '26 15:10 melvin-bot[bot]

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

Proposal

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

When a scanned receipt fails SmartScan (receipt.state: SCAN_FAILED) and is left with missing required fields (such as missing amount or merchant), the "Approve" action button incorrectly displays on:

  1. The Report preview in chat (canApprove).
  2. The Report Primary Action button in RHP header (isApproveAction).
  3. The Report Secondary Action menu in RHP header (isApproveAction).
  4. The Search > Reports list row (canApproveIOU).

What is the root cause of that problem?

Across all 4 approval permission checks:

  • src/libs/ReportPreviewActionUtils.ts:100 (canApprove)
  • src/libs/ReportPrimaryActionUtils.ts:200 (isApproveAction)
  • src/libs/ReportSecondaryActionUtils.ts:330 (isApproveAction)
  • src/libs/ReportUtils.ts:3330 (canApproveIOU)

The logic guards against transactions that are currently scanning (isScanning(transaction)) or pending card authorizations (isPending(transaction)). However, none of these checks inspect whether SmartScan has failed with missing required fields. When SmartScan fails, receipt.state transitions to CONST.IOU.RECEIPT_STATE.SCAN_FAILED. Since it is no longer scanning, isScanning(transaction) evaluates to false. If the report is in an approved/submitted state (such as automatic instant submission on receipt capture), the report passes all approval criteria and displays the "Approve" button, even though approving an expense that has no valid amount or missing required fields is an invalid domain operation.

Notice that Expensify already created a dedicated, canonical helper for this exact validation in src/libs/TransactionUtils/index.ts:

hasSmartScanFailedWithMissingFields(transactions: Transaction[], report: OnyxEntry<Report>): boolean

This helper is already used by canSubmit and shouldSplitScanFailedTransactions. It was simply omitted from the 4 approval evaluation surfaces.


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

Incorporate hasSmartScanFailedWithMissingFields(transactions, report) across all 4 approval resolution functions:

1. In src/libs/ReportPreviewActionUtils.ts:

--- a/src/libs/ReportPreviewActionUtils.ts
+++ b/src/libs/ReportPreviewActionUtils.ts
@@ -20,6 +20,7 @@ import {isPreventSelfApprovalEnabled} from './PolicyUtils';
 import {canMemberAssignRole} from './PolicyUtils';
 import {isSubmitterApproveBlockedOnSubmitWorkspace} from './PolicyUtils';
 import {isScanning} from './TransactionUtils';
+import {hasSmartScanFailedWithMissingFields} from './TransactionUtils';

@@ -103,6 +104,10 @@ function canApprove(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>, transa
     if (isAnyReceiptBeingScanned) {
         return false;
     }

+    if (hasSmartScanFailedWithMissingFields(transactions, report)) {
+        return false;
+    }

     if (transactions.length > 0 && transactions.every((transaction) => isPending(transaction))) {

2. In src/libs/ReportPrimaryActionUtils.ts:

--- a/src/libs/ReportPrimaryActionUtils.ts
+++ b/src/libs/ReportPrimaryActionUtils.ts
@@ -21,6 +21,7 @@ import {hasDynamicExternalWorkflow} from './PolicyUtils';
 import {hasPendingDEWApprove} from './ReportUtils';
 import {isScanning} from './TransactionUtils';
+import {hasSmartScanFailedWithMissingFields} from './TransactionUtils';

@@ -204,6 +205,10 @@ function isApproveAction(report: Report, reportTransactions: Transaction[], curr
     if (isAnyReceiptBeingScanned) {
         return false;
     }

+    if (hasSmartScanFailedWithMissingFields(reportTransactions, report)) {
+        return false;
+    }

     return !reportTransactions.every((transaction) => isPending(transaction));

3. In src/libs/ReportSecondaryActionUtils.ts:

--- a/src/libs/ReportSecondaryActionUtils.ts
+++ b/src/libs/ReportSecondaryActionUtils.ts
@@ -20,6 +20,7 @@ import {isProcessingReport as isProcessingReportUtils} from './ReportUtils';
 import {isReceiptBeingScanned} from './TransactionUtils';
+import {hasSmartScanFailedWithMissingFields} from './TransactionUtils';

@@ -334,6 +335,10 @@ function isApproveAction(
     if (isAnyReceiptBeingScanned) {
         return false;
     }

+    if (hasSmartScanFailedWithMissingFields(reportTransactions, report)) {
+        return false;
+    }

     const isDEWPolicy = hasDynamicExternalWorkflow(policy);

4. In src/libs/ReportUtils.ts:

--- a/src/libs/ReportUtils.ts
+++ b/src/libs/ReportUtils.ts
@@ -75,6 +75,7 @@ import {isReportApproved} from './ReportUtils/isReportApproved';
 import {isProcessingReport} from './ReportUtils/isProcessingReport';
 import {isScanning} from './TransactionUtils';
+import {hasSmartScanFailedWithMissingFields} from './TransactionUtils';

@@ -3335,6 +3336,10 @@ function canApproveIOU(
     if (hasOnlyPendingCardOrScanningTransactions) {
         return false;
     }
+    if (hasSmartScanFailedWithMissingFields(reportTransactions, iouReport)) {
+        return false;
+    }
     const isReportPayAtEnd = isPayAtEndExpenseReport(iouReport ?? undefined, reportTransactions);

Why this solution is optimal:

  1. Reuses Existing Tested Domain Logic: Employs hasSmartScanFailedWithMissingFields directly from TransactionUtils, preventing fragmented or duplicated field-check logic.
  2. Unified Consistency: Fixes all 4 approval entry points (chat preview, primary action, secondary menu, and search table) simultaneously.
  3. Preserves Valid 0-Amount/Non-Reimbursable Expenses: Only suppresses approval when SmartScan has explicitly failed and required fields are empty; valid manual expenses or zero-cost transactions are unaffected.

What alternative solutions did you explore? (Optional)

  • Checking for violations in approval functions: Rejected. Violations are asynchronously evaluated and can take a moment to sync from Onyx, whereas hasSmartScanFailedWithMissingFields synchronously reads transaction receipt state and required fields immediately.

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

In tests/unit/ReportPreviewActionUtilsTest.ts and tests/unit/ReportUtilsTest.ts:

  • Create an expense report with a single transaction where receipt.state: CONST.IOU.RECEIPT_STATE.SCAN_FAILED and amount: 0.
  • Assert canApprove and canApproveIOU return false.
  • Populate a valid amount on the transaction and assert canApprove returns true.

camesenin avatar Oct 22 '26 15:10 camesenin

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

melvin-bot[bot] avatar Oct 22 '26 15:10 melvin-bot[bot]

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

HamzaKhanBUIC avatar Oct 22 '26 18:10 HamzaKhanBUIC

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

melvin-bot[bot] avatar Oct 22 '26 18:10 melvin-bot[bot]

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

Proposal

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

When a receipt fails SmartScan (SCANFAILED) and is missing required fields (such as amount or merchant), the Approve button still appears on:

  1. The chat Report Preview (ReportPreviewActionUtils.ts),
  2. The Search > Reports row action (SearchUIUtils.ts / ReportUtils.canApproveIOU), and
  3. The Report Header / RHP primary and secondary action menus (ReportPrimaryActionUtils.ts & ReportSecondaryActionUtils.ts).

What is the root cause of that problem?

While the Submit action explicitly blocks reports whose transactions failed SmartScan with missing required fields via hasSmartScanFailedWithMissingFields(transactions, report), none of the Approve eligibility helpers check hasSmartScanFailedWithMissingFields:

  • src/libs/ReportUtils.ts:3330 (canApproveIOU): filters iouSettled, isScanning, and isPending, allowing a transaction with receipt.state === CONST.IOU.RECEIPT_STATE.SCAN_FAILED and missing amount/merchant to pass as approvable.
  • src/libs/ReportPreviewActionUtils.ts:100-108 (canApprove): checks canApproveIOU and only inspects isScanning(t) / isPending(t).
  • src/libs/ReportPrimaryActionUtils.ts:200 (isApproveAction) & src/libs/ReportSecondaryActionUtils.ts:330 (isApproveAction): similarly rely on canApproveIOU and isScanning / isPending without checking hasSmartScanFailedWithMissingFields.

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

  1. Block approval in canApproveIOU (src/libs/ReportUtils.ts) when all approvable transactions have failed SmartScan with missing required fields (or when hasSmartScanFailedWithMissingFields(transactions, iouReport) is true): In src/libs/ReportUtils.ts (canApproveIOU), after resolving transactions:
    if (hasSmartScanFailedWithMissingFields(transactions, iouReport)) {
        return false;
    }
    
  2. Ensure ReportPreviewActionUtils.ts, ReportPrimaryActionUtils.ts, and ReportSecondaryActionUtils.ts pass reportTransactions to canApproveIOU (or check !hasSmartScanFailedWithMissingFields(reportTransactions, report)):
    • In src/libs/ReportPreviewActionUtils.ts (canApprove), pass transactions into canApproveIOU(report, policy, reportMetadata, currentUserAccountID, transactions) (and guard !hasSmartScanFailedWithMissingFields(transactions, report)).
    • In src/libs/ReportPrimaryActionUtils.ts and src/libs/ReportSecondaryActionUtils.ts (isApproveAction), pass reportTransactions so that reports with a failed SmartScan and missing required fields fall through to View / Review instead of showing Approve.
    • In src/components/MoneyReportHeaderSecondaryActions.tsx:295, already passes moneyReportTransactions to canApproveIOU, so updating canApproveIOU automatically disables/hides Approve there as well.

bonnhatnguyen avatar Oct 24 '26 11:10 bonnhatnguyen

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

melvin-bot[bot] avatar Oct 24 '26 11:10 melvin-bot[bot]

Proposal

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

When a user uploads an invalid/unreadable receipt in a workspace where Prevent self-approval is disabled (and workflow approvals are enabled), the Approve button is hidden while SmartScan is actively scanning, but appears as soon as SmartScan fails (SCANFAILED) even though the expense still has missing required fields (e.g., $0.00 amount / missing merchant) and cannot be submitted.

What is the root cause of that problem?

While a receipt is actively scanning (CONST.IOU.RECEIPT_STATE.SCAN_READY or CONST.IOU.RECEIPT_STATE.SCANNING), isScanning(transaction) (src/libs/TransactionUtils/index.ts#L1204-L1206) returns true. Once SmartScan fails, transaction.receipt.state transitions to CONST.IOU.RECEIPT_STATE.SCAN_FAILED, so isScanning(transaction) becomes false.

For the Submit action, both the report preview and report header explicitly check hasSmartScanFailedWithMissingFields(transactions, report) (src/libs/TransactionUtils/index.ts#L1747-L1751):

However, the Approve eligibility functions only check whether a receipt is currently scanning (isScanning / isReceiptBeingScanned) and never check hasSmartScanFailedWithMissingFields:

  1. canApprove in src/libs/ReportPreviewActionUtils.ts#L103-L109 (controls the chat report preview button):
    const isAnyReceiptBeingScanned = transactions?.some((transaction) => isScanning(transaction));
    if (isAnyReceiptBeingScanned) {
        return false;
    }
    
    Because canSubmit returns false when SmartScan fails, getReportPreviewAction (src/libs/ReportPreviewActionUtils.ts#L189-L195) falls through from canSubmit to canApprove, which returns true (because for an admin/approver viewing an open report, isOpenExpenseReport(report) && isReportAdmin && reportTransactions.length === 1 is satisfied at #L118-L120).
  2. isApproveAction in src/libs/ReportPrimaryActionUtils.ts#L196-L201 (controls the report header primary button).
  3. isApproveAction in src/libs/ReportSecondaryActionUtils.ts#L331-L369 (controls the report header "More" dropdown menu).
  4. canApproveIOU in src/libs/ReportUtils.ts#L3338-L3343 (controls Search > Reports list action button via SearchUIUtils.ts#L2274, MoneyReportHeaderSecondaryActions.tsx#L295, and LHN badges via getBadgeFromIOUReport at ReportUtils.ts#L3509).

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

Add the hasSmartScanFailedWithMissingFields guard to the approval eligibility helpers so that reports with a failed SmartScan and missing required fields cannot be approved across any surface until the missing fields are resolved (matching Submit):

  1. In src/libs/ReportPreviewActionUtils.ts#L103-L109 (canApprove):

    const isAnyReceiptBeingScanned = transactions?.some((transaction) => isScanning(transaction));
    
    if (isAnyReceiptBeingScanned || hasSmartScanFailedWithMissingFields(transactions ?? [], report)) {
        return false;
    }
    
  2. In src/libs/ReportPrimaryActionUtils.ts#L196-L201 (isApproveAction): Import hasSmartScanFailedWithMissingFields from @libs/TransactionUtils and check it alongside isAnyReceiptBeingScanned:

    const isAnyReceiptBeingScanned = reportTransactions?.some((transaction) => isScanning(transaction));
    
    if (isAnyReceiptBeingScanned || hasSmartScanFailedWithMissingFields(reportTransactions, report)) {
        return false;
    }
    
  3. In src/libs/ReportSecondaryActionUtils.ts#L331-L335 (isApproveAction): Import hasSmartScanFailedWithMissingFields from @libs/TransactionUtils and check it alongside isAnyReceiptBeingScanned:

    const isAnyReceiptBeingScanned = reportTransactions?.some((transaction) => isReceiptBeingScanned(transaction));
    
    if (isAnyReceiptBeingScanned || hasSmartScanFailedWithMissingFields(reportTransactions, report)) {
        return false;
    }
    
  4. In src/libs/ReportUtils.ts#L3338-L3343 (canApproveIOU):

    if (hasSmartScanFailedWithMissingFields(reportTransactions, iouReport)) {
        return false;
    }
    
  5. Unit tests: Add test cases in tests/unit/ReportPreviewActionUtilsTest.ts, tests/unit/ReportPrimaryActionUtilsTest.ts, and tests/unit/ReportSecondaryActionUtilsTest.ts verifying that when a transaction has iouRequestType: CONST.IOU.REQUEST_TYPE.SCAN, receipt.state: CONST.IOU.RECEIPT_STATE.SCAN_FAILED, and missing amount/merchant (amount: 0), canApprove / isApproveAction returns false and the preview/header falls back to VIEW (Review when there are violations).

What alternative solutions did you explore? (Optional)

  • Checking only hasSubmissionBlockingViolations (CONST.VIOLATIONS.SMARTSCAN_FAILED): As noted in the JSDoc of hasSmartScanFailedWithMissingFields (src/libs/TransactionUtils/index.ts#L1744), hasSmartScanFailedWithMissingFields also covers the window before the violation is written and immediately clears once the user fills in the missing fields (hasMissingSmartscanFields), matching canSubmit and isTransactionSubmittable.

xian96xx avatar Oct 25 '26 14:10 xian96xx

📣 @xian96xx! 📣 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 Oct 25 '26 14:10 melvin-bot[bot]

@truph01 Huh... This is 4 days overdue. Who can take care of this?

melvin-bot[bot] avatar Oct 27 '26 21:10 melvin-bot[bot]

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

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

@truph01 10 days overdue. I'm getting more depressed than Marvin.

melvin-bot[bot] avatar Nov 02 '26 23:11 melvin-bot[bot]

@truph01 10 days overdue. I'm getting more depressed than Marvin.

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

@truph01 10 days overdue. I'm getting more depressed than Marvin.

melvin-bot[bot] avatar Nov 03 '26 03:11 melvin-bot[bot]