[Due for payment 2026-11-16] [$175] Web - Scan Receipt - Approve button appears after scan failure
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:
- Create a scan receipt that will be failed, so it will create a scan failure transactions
- Note there's approve button appears on expense preview
- Open Spend -> Reports > Outstanding and notice the row of the expense report
- Note that approve button appear in that row
- Click on this report row
Test 2: Preconditions: set up the submissions frequency to manually on workflow setting Steps:
- Create a scan receipt that missing the amount and not missing the merchant (can use the file I attached below)
- 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
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022113280670266341126
- Upwork Job ID: 2113280670266341126
- Last Price Increase: 2026-10-22
Issue Owner
Current Issue Owner: @mallenexpensify
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:
- Report preview:
canApprove, which checks onlyisScanningandisPending(ReportPreviewActionUtils.ts:100-108). - Search row:
getActionspushes Approve usingcanApproveIOU(SearchUIUtils.ts:2261-2269).canApproveIOUstops only when every expense is scanning or pending (ReportUtils.ts:3332). The App computes this action, not the backend. - Header primary button:
isApproveAction(ReportPrimaryActionUtils.ts:200-205). - Header secondary menu:
isApproveAction, which usesisReceiptBeingScanned(ReportSecondaryActionUtils.ts:331).
isReceiptBeingScanned is true only for SCAN_READY and SCANNING (TransactionUtils/index.ts:1202-1204).
Submit already uses the scan-failed check:
hasSmartScanFailedWithMissingFields(TransactionUtils/index.ts:1745) andisExpenseValueUnsettled(TransactionUtils/index.ts:1701) exist.- They block Submit in ReportPreviewActionUtils.ts:62 and ReportSecondaryActionUtils.ts:242.
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?
- Hide Approve when every expense on the report is still scanning, is a pending card charge, or failed SmartScan with missing fields.
- Add one helper in
TransactionUtils, for examplehasOnlyUnsettledExpenses(transactions, report). It returns true when the report has expenses and every one isisPendingorisExpenseValueUnsettled. - Use the helper in all four Approve checks:
canApproveIOU(Search row and header buttons)ReportPrimaryActionUtils.isApproveActionReportPreviewActionUtils.canApproveReportSecondaryActionUtils.isApproveAction
- Remove the duplicate check in
SearchUIUtils.getActions. With Approve gone, the Search row falls back to View. - 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
canApproveIOUdirectly: 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.
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?
- Add one shared helper in
TransactionUtils(or reuse the existinghasMissingSmartscanFields/isScanFailedhelpers) 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.
- Use the helper in
ReportPrimaryActionUtils.isApproveAction, right after the existingisScanningcheck:
if (reportTransactions.some(isScanFailedOrMissingRequiredFields)) {
return false;
}
-
Do the same in the report preview approve check in
ReportPreviewActionUtils(canApprove). This hides Approve on the expense preview and makesgetReportPreviewActionfall through to the next action, which is the View/Review behaviour. -
Do the same in
SearchUIUtils.getActionswhere the approve action is computed for the Search row. The row then shows View instead of Approve. -
Optionally guard
IOU.canApproveIOUand the secondaryApproveaction with the same helper, so approval can't be triggered through another path. -
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
missingAmountorreceiptRequired. 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
- 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.
- 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.
- 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.
- Unit tests.
- Add cases to
ReportPrimaryActionUtilsTest,ReportPreviewActionUtilsTestandSearchUIUtilsTest. Each should cover a report whose transaction hasreceipt.state = SCANFAILEDor a missing amount, and assert that the approve action isn't returned. - Add a positive control for a complete transaction.
- Add cases to
- Manual check. Run on Chrome and Safari (web) to confirm the fix on the platforms in the report.
Triggered auto assignment to Contributor-plus team member for initial proposal review - @truph01 (External)
Job added to Upwork: https://www.upwork.com/jobs/~022113280670266341126
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:
- The expense report preview in the chat thread (
ReportPreviewActionUtils.ts) - The Search > Reports > Outstanding table row (
SearchUIUtils.tsviaReportUtils.canApproveIOU) - 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:
-
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 checksisScanningand pending card transactions. It completely omits thehasSmartScanFailedWithMissingFieldscheck. -
Report Header Primary Action (
src/libs/ReportPrimaryActionUtils.ts:173–206):isApproveActiononly checksisScanningand 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.
-
Report Header Secondary Action Menu (
src/libs/ReportSecondaryActionUtils.ts:313–350):isApproveActionin the secondary actions utility checksisReceiptBeingScannedat line 331, but also lacks thehasSmartScanFailedWithMissingFieldsguard. -
Search Table Rows & General IOU Approval (
src/libs/ReportUtils.ts:canApproveIOU):SearchUIUtils.ts:2268callscanApproveIOU(report, policy, reportMetadata, currentUserAccountID, allReportTransactions). InReportUtils.ts,canApproveIOUcheckshasOnlyPendingCardOrScanningTransactions, 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:
-
In
src/libs/ReportPreviewActionUtils.ts(canApprove): (hasSmartScanFailedWithMissingFieldsis 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; } -
In
src/libs/ReportPrimaryActionUtils.ts(isApproveAction): ImporthasSmartScanFailedWithMissingFieldsfrom./TransactionUtilsand 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)); } -
In
src/libs/ReportSecondaryActionUtils.ts(isApproveAction): ImporthasSmartScanFailedWithMissingFieldsfrom./TransactionUtilsand 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); -
In
src/libs/ReportUtils.ts(canApproveIOU): ImporthasSmartScanFailedWithMissingFieldsfrom./TransactionUtilsand add the check incanApproveIOU:--- 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
hasSmartScanFailedWithMissingFieldshelper already used bycanSubmit(ReportPreviewActionUtils.ts:62) andisExpenseValueUnsettled(TransactionUtils.ts). - No Side Effects on Manual or Distance Expenses:
hasSmartScanFailedWithMissingFieldsspecifically targets SmartScan transactions (receipt.state === SCANFAILEDwith missing required fields) and does not interfere with valid manual or distance transactions.
What alternative solutions did you explore? (Optional)
- Fixing only
ReportPreviewActionUtils:- Rejected because the report header primary action and Search table row would still render the Approve button.
- Checking transaction violations (e.g.
missingAmount):- Rejected because transaction violations are calculated asynchronously or may depend on policy settings, whereas
hasSmartScanFailedWithMissingFieldschecks the core receipt state and required fields immediately on live Onyx data.
- Rejected because transaction violations are calculated asynchronously or may depend on policy settings, whereas
What specific scenarios should we cover in automated tests to prevent reintroduction of this issue in the future?
ReportPreviewActionUtilsTest.ts:- Call
canApprovewith an expense report containing a transaction withreceipt: {state: CONST.IOU.RECEIPT_STATE.SCAN_FAILED}andamount: 0. - Assert that
canApprovereturnsfalse. - Assert that
canApprovereturnstrueonce the amount is filled and scan failure is resolved.
- Call
ReportPrimaryActionUtilsTest.ts:- Call
isPrimaryApproveActionwith a transaction wherehasSmartScanFailedWithMissingFieldsistrue. - Assert that
isPrimaryApproveActionreturnsfalse.
- Call
ReportUtilsTest.ts:- Call
canApproveIOUfor a report whose transaction has failed SmartScan with missing fields. - Assert that
canApproveIOUreturnsfalse.
- Call
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
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:
- The Report preview in chat (
canApprove). - The Report Primary Action button in RHP header (
isApproveAction). - The Report Secondary Action menu in RHP header (
isApproveAction). - 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:
- Reuses Existing Tested Domain Logic: Employs
hasSmartScanFailedWithMissingFieldsdirectly fromTransactionUtils, preventing fragmented or duplicated field-check logic. - Unified Consistency: Fixes all 4 approval entry points (chat preview, primary action, secondary menu, and search table) simultaneously.
- 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
hasSmartScanFailedWithMissingFieldssynchronously 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_FAILEDandamount: 0. - Assert
canApproveandcanApproveIOUreturnfalse. - Populate a valid
amounton the transaction and assertcanApprovereturnstrue.
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~015055563b6090af39
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
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:
- The chat Report Preview (
ReportPreviewActionUtils.ts), - The Search > Reports row action (
SearchUIUtils.ts/ReportUtils.canApproveIOU), and - 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): filtersiouSettled,isScanning, andisPending, allowing a transaction withreceipt.state === CONST.IOU.RECEIPT_STATE.SCAN_FAILEDand missing amount/merchant to pass as approvable.src/libs/ReportPreviewActionUtils.ts:100-108(canApprove): checkscanApproveIOUand only inspectsisScanning(t)/isPending(t).src/libs/ReportPrimaryActionUtils.ts:200(isApproveAction) &src/libs/ReportSecondaryActionUtils.ts:330(isApproveAction): similarly rely oncanApproveIOUandisScanning/isPendingwithout checkinghasSmartScanFailedWithMissingFields.
What changes do you think we should make in order to solve the problem?
- Block approval in
canApproveIOU(src/libs/ReportUtils.ts) when all approvable transactions have failed SmartScan with missing required fields (or whenhasSmartScanFailedWithMissingFields(transactions, iouReport)is true): Insrc/libs/ReportUtils.ts(canApproveIOU), after resolvingtransactions:if (hasSmartScanFailedWithMissingFields(transactions, iouReport)) { return false; } - Ensure
ReportPreviewActionUtils.ts,ReportPrimaryActionUtils.ts, andReportSecondaryActionUtils.tspassreportTransactionstocanApproveIOU(or check!hasSmartScanFailedWithMissingFields(reportTransactions, report)):- In
src/libs/ReportPreviewActionUtils.ts(canApprove), passtransactionsintocanApproveIOU(report, policy, reportMetadata, currentUserAccountID, transactions)(and guard!hasSmartScanFailedWithMissingFields(transactions, report)). - In
src/libs/ReportPrimaryActionUtils.tsandsrc/libs/ReportSecondaryActionUtils.ts(isApproveAction), passreportTransactionsso 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 passesmoneyReportTransactionstocanApproveIOU, so updatingcanApproveIOUautomatically disables/hides Approve there as well.
- In
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
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):
canSubmitinsrc/libs/ReportPreviewActionUtils.ts#L61-L63returnsfalsewhenhasSmartScanFailedWithMissingFields(transactions ?? [], report)istrue.isSubmitActioninsrc/libs/ReportPrimaryActionUtils.ts#L150callsisTransactionSubmittable(src/libs/TransactionUtils/violations.ts#L510-L520), which callsisExpenseValueUnsettled(src/libs/TransactionUtils/index.ts#L1697-L1706) and checkshasSmartScanFailedWithMissingFields([transaction], report).
However, the Approve eligibility functions only check whether a receipt is currently scanning (isScanning / isReceiptBeingScanned) and never check hasSmartScanFailedWithMissingFields:
canApproveinsrc/libs/ReportPreviewActionUtils.ts#L103-L109(controls the chat report preview button):
Becauseconst isAnyReceiptBeingScanned = transactions?.some((transaction) => isScanning(transaction)); if (isAnyReceiptBeingScanned) { return false; }canSubmitreturnsfalsewhen SmartScan fails,getReportPreviewAction(src/libs/ReportPreviewActionUtils.ts#L189-L195) falls through fromcanSubmittocanApprove, which returnstrue(because for an admin/approver viewing an open report,isOpenExpenseReport(report) && isReportAdmin && reportTransactions.length === 1is satisfied at#L118-L120).isApproveActioninsrc/libs/ReportPrimaryActionUtils.ts#L196-L201(controls the report header primary button).isApproveActioninsrc/libs/ReportSecondaryActionUtils.ts#L331-L369(controls the report header "More" dropdown menu).canApproveIOUinsrc/libs/ReportUtils.ts#L3338-L3343(controls Search > Reports list action button viaSearchUIUtils.ts#L2274,MoneyReportHeaderSecondaryActions.tsx#L295, and LHN badges viagetBadgeFromIOUReportatReportUtils.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):
-
In
src/libs/ReportPreviewActionUtils.ts#L103-L109(canApprove):const isAnyReceiptBeingScanned = transactions?.some((transaction) => isScanning(transaction)); if (isAnyReceiptBeingScanned || hasSmartScanFailedWithMissingFields(transactions ?? [], report)) { return false; } -
In
src/libs/ReportPrimaryActionUtils.ts#L196-L201(isApproveAction): ImporthasSmartScanFailedWithMissingFieldsfrom@libs/TransactionUtilsand check it alongsideisAnyReceiptBeingScanned:const isAnyReceiptBeingScanned = reportTransactions?.some((transaction) => isScanning(transaction)); if (isAnyReceiptBeingScanned || hasSmartScanFailedWithMissingFields(reportTransactions, report)) { return false; } -
In
src/libs/ReportSecondaryActionUtils.ts#L331-L335(isApproveAction): ImporthasSmartScanFailedWithMissingFieldsfrom@libs/TransactionUtilsand check it alongsideisAnyReceiptBeingScanned:const isAnyReceiptBeingScanned = reportTransactions?.some((transaction) => isReceiptBeingScanned(transaction)); if (isAnyReceiptBeingScanned || hasSmartScanFailedWithMissingFields(reportTransactions, report)) { return false; } -
In
src/libs/ReportUtils.ts#L3338-L3343(canApproveIOU):if (hasSmartScanFailedWithMissingFields(reportTransactions, iouReport)) { return false; } -
Unit tests: Add test cases in
tests/unit/ReportPreviewActionUtilsTest.ts,tests/unit/ReportPrimaryActionUtilsTest.ts, andtests/unit/ReportSecondaryActionUtilsTest.tsverifying that when a transaction hasiouRequestType: CONST.IOU.REQUEST_TYPE.SCAN,receipt.state: CONST.IOU.RECEIPT_STATE.SCAN_FAILED, and missing amount/merchant (amount: 0),canApprove/isApproveActionreturnsfalseand the preview/header falls back toVIEW(Reviewwhen there are violations).
What alternative solutions did you explore? (Optional)
- Checking only
hasSubmissionBlockingViolations(CONST.VIOLATIONS.SMARTSCAN_FAILED): As noted in the JSDoc ofhasSmartScanFailedWithMissingFields(src/libs/TransactionUtils/index.ts#L1744),hasSmartScanFailedWithMissingFieldsalso covers the window before the violation is written and immediately clears once the user fills in the missing fields (hasMissingSmartscanFields), matchingcanSubmitandisTransactionSubmittable.
📣 @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:
- Make sure you've read and understood the contributing guidelines.
- 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.
- 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.
- Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>
@truph01 Huh... This is 4 days overdue. Who can take care of this?
@truph01 Still overdue 6 days?! Let's take care of this!
@truph01 10 days overdue. I'm getting more depressed than Marvin.
@truph01 10 days overdue. I'm getting more depressed than Marvin.
@truph01 10 days overdue. I'm getting more depressed than Marvin.