Skip to content

[Due for payment 2025-06-16][$250] Approve button appears when the receipt is scanning #62743

Closed

Description

@m-natarajan

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


Version Number: 9.1.51-0
Reproducible in staging?: y
Reproducible in production?: y
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: @iwiznia
Slack conversation (hyperlinked to channel name): #Expensify-bugs

Action Performed:

Precondition: Disable delay submissions

  1. Create a workspace
  2. Disable delay submissions
  3. Click create expense, select scan option and upload a receipt
  4. Observe the button

Expected Result:

Approve button should not appear while scanning

Actual Result:

Approve button appears

Workaround:

unknown

Platforms:

Select the officially supported platforms where the issue was reproduced:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari
  • MacOS: Desktop
Platforms Tested: On which of our officially supported platforms was this issue tested:
  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence
Screen.Recording.2025-05-23.at.10.46.49.AM.mov
Recording.1272.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021927434948367177304
  • Upwork Job ID: 1927434948367177304
  • Last Price Increase: 2025-05-27
Issue OwnerCurrent Issue Owner: @
Issue OwnerCurrent Issue Owner: @mallenexpensify

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on May 25, 2025
  2. melvin-bot commented on May 25, 2025

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  3. bernhardoj commented on May 25, 2025

    @bernhardoj
    Contributor

    Proposal

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

    Approve button shows while scanning.

    What is the root cause of that problem?

    In canApprove logic, we don't have any logic to check if the request is still scanning.

    if (isPreventSelfApprovalEnabled && isReportSubmitter) {
    return false;
    }
    return isExpense && isApprover && isProcessing && isApprovalEnabled && !hasAnyViolations && reportTransactions.length > 0 && isCurrentUserManager;
    }

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

    We can follow the logic from IOU.canApproveIOU by checking every transactions with isPendingCardOrScanningTransaction and return early if true.

    App/src/libs/actions/IOU.ts

    Lines 8984 to 8987 in 526a0e4

    const hasOnlyPendingCardOrScanningTransactions = reportTransactions.length > 0 && reportTransactions.every(isPendingCardOrScanningTransaction);
    if (hasOnlyPendingCardOrScanningTransactions) {
    return false;
    }

    const hasOnlyPendingCardOrScanningTransactions = reportTransactions.length > 0 && reportTransactions.every(isPendingCardOrScanningTransaction);
    
    if (hasOnlyPendingCardOrScanningTransactions) {
        return false;
    }
    

    or we can only check if it's scanning, just like the canSubmit logic.

    const isAnyReceiptBeingScanned = transactions?.some((transaction) => isReceiptBeingScanned(transaction));

    (hasOnlyPendingCardOrScanningTransactions also checks if it's partial, but BE allow approving partial transaction)

    We need to apply it to ReportPrimaryActionUtils and ReportSecondaryActionUtils too.

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

    We can test canApprove and assert it returns false if it's scanning.

  4. mavrickdeveloper commented on May 25, 2025

    @mavrickdeveloper
    Contributor

    Proposal

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

    Approve button appears when the receipt is scanning

    What is the root cause of that problem?

    This is an intentional behavior the TL;DR :

    Submitters must wait until all receipts finish scanning before they can submit an expense report

    Approvers can approve expense reports even while receipts are still scanning, trusting that the scanning will complete and populate the necessary fields

    This design allows for a more flexible approval workflow where approvers don't have to wait for all scanning to complete, while still ensuring that submitters have complete information before submission

    The scanning status is still shown in the chat preview as Receipt /Scanning, but the approval workflow can proceed independently of the scanning process.

    Submit Button Logic
    The submit functionality explicitly prevents submission while receipts are scanning:

    function canSubmit(report: Report, violations: OnyxCollection<TransactionViolation[]>, policy?: Policy, transactions?: Transaction[]) {
    const isExpense = isExpenseReport(report);
    const isSubmitter = isCurrentUserSubmitter(report.reportID);
    const isOpen = isOpenReport(report);
    const isManager = report.managerID === getCurrentUserAccountID();
    const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN;
    const isManualSubmitEnabled = getCorrectedAutoReportingFrequency(policy) === CONST.POLICY.AUTO_REPORTING_FREQUENCIES.MANUAL;
    const hasAnyViolations =
    hasMissingSmartscanFields(report.reportID, transactions) ||
    hasViolations(report.reportID, violations) ||
    hasNoticeTypeViolations(report.reportID, violations, true) ||
    hasWarningTypeViolations(report.reportID, violations, true);
    const isAnyReceiptBeingScanned = transactions?.some((transaction) => isReceiptBeingScanned(transaction));
    const submitToAccountID = getSubmitToAccountID(policy, report);
    if (submitToAccountID === report.ownerAccountID && policy?.preventSelfApproval) {
    return false;
    }
    return isExpense && (isSubmitter || isManager || isAdmin) && isOpen && isManualSubmitEnabled && !hasAnyViolations && !isAnyReceiptBeingScanned;
    }

    Notice the !isAnyReceiptBeingScanned check that prevents submission when any receipt is scanning.

    On the other hand Approve Button Logic
    the approve functionality does NOT have this same restriction:

    function canApprove(report: Report, violations: OnyxCollection<TransactionViolation[]>, policy?: Policy, transactions?: Transaction[]) {
    const currentUserID = getCurrentUserAccountID();
    const isExpense = isExpenseReport(report);
    const isApprover = isApproverMember(policy, currentUserID);
    const isProcessing = isProcessingReport(report);
    const isApprovalEnabled = policy ? policy.approvalMode && policy.approvalMode !== CONST.POLICY.APPROVAL_MODE.OPTIONAL : false;
    const managerID = report?.managerID ?? CONST.DEFAULT_NUMBER_ID;
    const isCurrentUserManager = managerID === currentUserID;
    const hasAnyViolations =
    hasMissingSmartscanFields(report.reportID, transactions) ||
    hasViolations(report.reportID, violations) ||
    hasNoticeTypeViolations(report.reportID, violations, true) ||
    hasWarningTypeViolations(report.reportID, violations, true);
    const reportTransactions = transactions ?? getReportTransactions(report?.reportID);
    const isPreventSelfApprovalEnabled = policy?.preventSelfApproval;
    const isReportSubmitter = isCurrentUserSubmitter(report.reportID);
    if (isPreventSelfApprovalEnabled && isReportSubmitter) {
    return false;
    }
    return isExpense && isApprover && isProcessing && isApprovalEnabled && !hasAnyViolations && reportTransactions.length > 0 && isCurrentUserManager;

    here's no explicit check for scanning receipts in the approve logic , meaning hasMissingSmartscanFields Excludes Scanning Receipts

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

    i applied the exact same proven logic pattern (isAnyReceiptBeingScanned = reportTransactions?.some(transaction => isReceiptBeingScanned(transaction))) that already exists in canSubmit and isSubmitAction to all three approve functions (canApprove, isApproveAction in ReportPrimaryActionUtils, and isApproveAction in ReportSecondaryActionUtils) , This leverages the existing the tested isReceiptBeingScanned function that properly detects both SCAN_READY and SCANNING states, ensuring that approve buttons are hidden during scanning just like submit buttons already are. this works cause it follows established architectural patterns & has comprehensive test coverage for both scanning states, and creates consistent behavior across all expense report actions without introducing any breaking changes or new complex logic

    const isAnyReceiptBeingScanned = reportTransactions?.some((transaction) => isReceiptBeingScanned(transaction));
    ...
    return isExpense && isApprover && isProcessing && isApprovalEnabled && !hasAnyViolations && reportTransactions.length > 0 && isCurrentUserManager && !isAnyReceiptBeingScanned;

    We should also fix it in ReportPrimaryActionUtils.ts & ReportSecondaryActionUtils.ts

    *ReportPrimaryActionUtils.ts :

      const isAnyReceiptBeingScanned = reportTransactions?.some((transaction) => isReceiptBeingScanned(transaction));
    
        if (isAnyReceiptBeingScanned) {
            return false;
        }
    import {allHavePendingRTERViolation, isDuplicate, isOnHold as isOnHoldTransactionUtils, isReceiptBeingScanned, shouldShowBrokenConnectionViolationForMultipleTransactions} from './TransactionUtils';
    ...
      const isAnyReceiptBeingScanned = reportTransactions?.some((transaction) => isReceiptBeingScanned(transaction));
    
        if (isAnyReceiptBeingScanned) {
            return false;
        }
    

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

    this change requires a new test case imo in ReportPreviewActionUtilsTest.ts , im including it, here it is :

        it('canApprove should return false when receipts are being scanned', async () => {
            const report = {
                ...createRandomReport(REPORT_ID),
                type: CONST.REPORT.TYPE.EXPENSE,
                ownerAccountID: CURRENT_USER_ACCOUNT_ID,
                stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
                statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED,
                managerID: CURRENT_USER_ACCOUNT_ID,
                isWaitingOnBankAccount: false,
            };
    
            const policy = createRandomPolicy(0);
            policy.type = CONST.POLICY.TYPE.CORPORATE;
            policy.approver = CURRENT_USER_EMAIL;
            policy.approvalMode = CONST.POLICY.APPROVAL_MODE.BASIC;
            policy.preventSelfApproval = false;
    
            await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
            const transaction = {
                reportID: `${REPORT_ID}`,
                receipt: {
                    state: CONST.IOU.RECEIPT_STATE.SCANNING,
                    source: 'test-receipt.jpg',
                },
            } as unknown as Transaction;
    
            const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID));
            expect(getReportPreviewAction(VIOLATIONS, report, policy, [transaction], isReportArchived.current)).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW);
        });
    
        it('canApprove should return false when receipts are in scan ready state', async () => {
            const report = {
                ...createRandomReport(REPORT_ID),
                type: CONST.REPORT.TYPE.EXPENSE,
                ownerAccountID: CURRENT_USER_ACCOUNT_ID,
                stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
                statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED,
                managerID: CURRENT_USER_ACCOUNT_ID,
                isWaitingOnBankAccount: false,
            };
    
            const policy = createRandomPolicy(0);
            policy.type = CONST.POLICY.TYPE.CORPORATE;
            policy.approver = CURRENT_USER_EMAIL;
            policy.approvalMode = CONST.POLICY.APPROVAL_MODE.BASIC;
            policy.preventSelfApproval = false;
    
            await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
            const transaction = {
                reportID: `${REPORT_ID}`,
                receipt: {
                    state: CONST.IOU.RECEIPT_STATE.SCAN_READY,
                    source: 'test-receipt.jpg',
                },
            } as unknown as Transaction;
    
            const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID));
            expect(getReportPreviewAction(VIOLATIONS, report, policy, [transaction], isReportArchived.current)).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW);
        });
    // Action determination flow
    getReportPreviewAction() 
    ├── canSubmit() ✅ (already had scanning check)
    ├── canApprove() ✅ (now has scanning check)
    ├── canPay() (doesn't need it , pay happens after approval)
    └── ...
    
    getReportPrimaryAction()
    ├── isSubmitAction() ✅ (already had scanning check)  
    ├── isApproveAction() ✅ (now has scanning check)
    └── ...
    
    getSecondaryReportActions()
    ├── isSubmitAction() ✅ (already had scanning check)
    ├── isApproveAction() ✅ (now has scanning check)
    └── ...
  5. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on May 27, 2025
  6. changed the title [-]`Approve` button appears when the receipt is scanning[/-] [+][$250] `Approve` button appears when the receipt is scanning[/+] on May 27, 2025
  7. melvin-bot commented on May 27, 2025

    @melvin-bot
  8. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on May 27, 2025
  9. melvin-bot commented on May 27, 2025

    @melvin-bot

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

  10. 31 remaining items

  11. melvin-bot commented on Jun 16, 2025

    @melvin-bot

    @mallenexpensify Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  12. ishpaul777 commented on Jun 16, 2025

    @ishpaul777
    Contributor

    will fill checklist today

  13. changed the title [-][Due for payment 2025-06-16] [Due for payment 2025-06-13] [$250] `Approve` button appears when the receipt is scanning[/-] [+][Due for payment 2025-06-16][$250] `Approve` button appears when the receipt is scanning[/+] on Jun 17, 2025
  14. mallenexpensify commented on Jun 17, 2025

    @mallenexpensify
    Contributor

    Contributor: @bernhardoj due $250 via NewDot
    Contributor+: @ishpaul777 due $250 via NewDot

    @ishpaul777 please post checklist, thx

  15. bernhardoj commented on Jun 17, 2025

    @bernhardoj
    Contributor

    Requested in ND.

  16. ishpaul777 commented on Jun 17, 2025

    @ishpaul777
    Contributor

    BugZero Checklist:

    • [Contributor] Classify the bug:
    Bug classification

    Source of bug:

    • 1a. Result of the original design (eg. a case wasn't considered)
    • 1b. Mistake during implementation
    • 1c. Backend bug
    • 1z. Other:

    Where bug was reported:

    • 2a. Reported on production (eg. bug slipped through the normal regression and PR testing process on staging)
    • 2b. Reported on staging (eg. found during regression or PR testing)
    • 2d. Reported on a PR
    • 2z. Other:

    Who reported the bug:

    • 3a. Expensify user
    • 3b. Expensify employee
    • 3c. Contributor
    • 3d. QA
    • 3z. Other:
    • [Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.

      Link to comment: https://github.com/Expensify/App/pull/58084/files#r2153357071

    • [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.

      Link to discussion: no need this was a edge case from a large feature PR might now be considered in the implementation phase

    • [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again. recomended

    • [BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.

      Link to issue:

    Regression Test Proposal

    Precondition:

    • Disable delay submissions in WS settings

    Test:

    1. Create a workspace
    2. Disable delay submissions
    3. Click create expense, select scan option and upload a receipt
    4. Observe the button
    5. Expected Result: Approve button should not appear while scanning

    Do we agree 👍 or 👎

  17. melvin-bot commented on Jun 20, 2025

    @melvin-bot

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

  18. mallenexpensify commented on Jun 21, 2025

    @mallenexpensify
    Contributor
  19. JmillsExpensify commented on Jul 2, 2025

    @JmillsExpensify
    Contributor

    $250 approved for @bernhardoj

  20. garrettmknight commented on Jul 3, 2025

    @garrettmknight
    Contributor

    $250 approved for @ishpaul777

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

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions