Skip to content

[Due for payment 2025-07-30] [$250] Expense - Nothing happens when submitter deletes own expense and clicks Change workspace #65323

Closed

Description

@mitarachim

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.74-2
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://expensify.testrail.io/index.php?/tests/view/6414864
Email or phone of affected tester (no customers): siojsduhsbsuid@gmail.com
Issue reported by: Applause Internal Team
Device used: Mac 15.5 / Chrome
App Component: Money Requests

Action Performed:

Precondition:

  • User A has a workspace.
  1. Go to staging.expensify.com
  2. [User A] Submit an expense to User B.
  3. [User B} Submit an expense (any amount) to User A.
  4. [User A] Open the expense report.
  5. [User A] Delete the submitted expense from Step 2.
  6. [User A] Click More > Change workspace.
  7. [User A] Select any workspace.

Expected Result:

IOU will be moved to the workspace.

Actual Result:

Change workspace button is not responsive when submitter deletes own expense and tries to change workspace.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Bug6875753_1751447445636.20250702_170453.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021940551797202659919
  • Upwork Job ID: 1940551797202659919
  • Last Price Increase: 2025-07-09
  • Automatic offers:
    • etCoderDysto | Contributor | 107989106
Issue OwnerCurrent Issue Owner: @sakluger

Activity

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

    @melvin-bot

    Triggered auto assignment to @sakluger (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. etCoderDysto commented on Jul 2, 2025

    @etCoderDysto
    Contributor

    Proposal

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

    Expense - Nothing happens when submitter deletes own expense and clicks Change workspace

    What is the root cause of that problem?

    We return early in moveIOUReportToPolicyAndInviteSubmitter, if the manager of an iou has also submitted an IOU in the same money request report

    App/src/libs/actions/Report.ts

    Lines 5164 to 5166 in cec17ac

    if (!isReimbursed && ReportActionsUtils.hasRequestFromCurrentAccount(reportID, iouReport.managerID ?? CONST.DEFAULT_NUMBER_ID)) {
    return;
    }

    When checking if the manager of iouReport has submitted an expense to the same report, we are not considering if the report action is deleted here. Therefore the deleted report action will be counted an existing report action, and we return early.
    function hasRequestFromCurrentAccount(reportID: string | undefined, currentAccountID: number): boolean {
    if (!reportID) {
    return false;
    }
    const reportActions = Object.values(getAllReportActions(reportID));
    if (reportActions.length === 0) {
    return false;
    }
    return reportActions.some((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && action.actorAccountID === currentAccountID);

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

    We should check if the report action is deleted

    
        return reportActions.some((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && action.actorAccountID === currentAccountID && !isDeletedAction(action));
    

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

    We can add test for hasRequestFromCurrentAccount to assert that it returns false when the report action is deleted and it return true when the report action is not deleted

    What alternative solutions did you explore? (Optional)

    We can create a custom function to check if iou report manager has submitted to the same report if think changing the existing function breaks any existing functionality

    function hasNonDeletedRequestFromCurrentAccount(reportID: string | undefined, currentAccountID: number): boolean {
        if (!reportID) {
            return false;
        }
    
        const reportActions = Object.values(getAllReportActions(reportID));
        if (reportActions.length === 0) {
            return false;
        }
    
        return reportActions.some(
            (action) =>
                action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU &&
                action.actorAccountID === currentAccountID &&
                !isDeletedAction(action),
        );
    
    

    }

  4. nkdengineer commented on Jul 2, 2025

    @nkdengineer
    Contributor

    Proposal

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

    Change workspace button is not responsive when submitter deletes own expense and tries to change workspace.

    What is the root cause of that problem?

    We return early if the iou report has the request from the current user.

    App/src/libs/actions/Report.ts

    Lines 5164 to 5166 in cec17ac

    if (!isReimbursed && ReportActionsUtils.hasRequestFromCurrentAccount(reportID, iouReport.managerID ?? CONST.DEFAULT_NUMBER_ID)) {
    return;
    }

    App/src/libs/actions/Report.ts

    Lines 4982 to 4985 in cec17ac

    if (!isReimbursed && ReportActionsUtils.hasRequestFromCurrentAccount(reportID, iouReport.managerID ?? CONST.DEFAULT_NUMBER_ID)) {
    return;
    }

    But the check hasRequestFromCurrentAccount doesn't work as expected. After user A deletes your transaction, the iou action still exists, it's only marked as deleted then this function returns true.

    function hasRequestFromCurrentAccount(reportID: string | undefined, currentAccountID: number): boolean {
    if (!reportID) {
    return false;
    }
    const reportActions = Object.values(getAllReportActions(reportID));
    if (reportActions.length === 0) {
    return false;
    }
    return reportActions.some((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && action.actorAccountID === currentAccountID);
    }
    /**
    * Constructs a message for an actionable mention whisper report action.

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

    We should filter out the deleted action

    return reportActions.some((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && action.actorAccountID === currentAccountID && !isDeletedAction(action));
    

    function hasRequestFromCurrentAccount(reportID: string | undefined, currentAccountID: number): boolean {
    if (!reportID) {
    return false;
    }
    const reportActions = Object.values(getAllReportActions(reportID));
    if (reportActions.length === 0) {
    return false;
    }
    return reportActions.some((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && action.actorAccountID === currentAccountID);
    }
    /**
    * Constructs a message for an actionable mention whisper report action.

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

    We should add a unit test for hasRequestFromCurrentAccount function to verify it works correctly if the list action contains the deleted iou action and prevent the same bug from happening in the feature.

    What alternative solutions did you explore? (Optional)

    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  5. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Jul 2, 2025
  6. changed the title [-]Expense - Nothing happens when submitter deletes own expense and clicks Change workspace[/-] [+][$250] Expense - Nothing happens when submitter deletes own expense and clicks Change workspace[/+] on Jul 2, 2025
  7. melvin-bot commented on Jul 2, 2025

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

    @melvin-bot

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

  10. moved this to Bugs and Follow Up Issues in #expensify-bugson Jul 2, 2025
  11. FitseTLT commented on Jul 4, 2025

    @FitseTLT
    Contributor

    Proposal

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

    Expense - Nothing happens when submitter deletes own expense and clicks Change workspace

    What is the root cause of that problem?

    We can't move iou report to a workspace if the iou report has expenses from mutltiple users

    App/src/libs/actions/Report.ts

    Lines 5163 to 5166 in cec17ac

    // We only allow moving IOU report to a policy if it doesn't have requests from multiple users, as we do not want to create negative amount expenses
    if (!isReimbursed && ReportActionsUtils.hasRequestFromCurrentAccount(reportID, iouReport.managerID ?? CONST.DEFAULT_NUMBER_ID)) {
    return;
    }

    but the way we are checking is via hasRequestFromCurrentAccount for the manager (if the manager of the iou has request) and even if the request from the manager is deleted in the OP, it doesn't properly account for deleted iou actions
    function hasRequestFromCurrentAccount(reportID: string | undefined, currentAccountID: number): boolean {
    if (!reportID) {
    return false;
    }
    const reportActions = Object.values(getAllReportActions(reportID));
    if (reportActions.length === 0) {
    return false;
    }
    return reportActions.some((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && action.actorAccountID === currentAccountID);
    }
    /**
    * Constructs a message for an actionable mention whisper report action.

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

    By the way, what we want to prevent is moving iou report's to policy which have expense from multiple users because we don't want to create negative amount expenses

    App/src/libs/actions/Report.ts

    Lines 4976 to 4977 in 74e1436

    // We do not want to create negative amount expenses
    if (!isReimbursed && ReportActionsUtils.hasRequestFromCurrentAccount(reportID, iouReport.managerID ?? CONST.DEFAULT_NUMBER_ID)) {

    Checking for IOU actions is not a reliable way to determine this as there are otherIOU which are not linked to a request, for instance, payed action that is created when you create an iou report is also IOU type report action. So the correct way to determine is to check if there are transactions with negative amount like here
    function isChangeWorkspaceAction(report: Report, policies: OnyxCollection<Policy>): boolean {
    const availablePolicies = Object.values(policies ?? {}).filter((newPolicy) => isWorkspaceEligibleForReportChange(newPolicy, report, policies));

    App/src/libs/ReportUtils.ts

    Lines 10841 to 10844 in 74e1436

    // We can't move the iou report to the workspace if both users from the iou report create the expense
    if (doesReportContainRequestsFromMultipleUsers(report)) {
    return false;
    }

    App/src/libs/ReportUtils.ts

    Lines 10829 to 10832 in 74e1436

    function doesReportContainRequestsFromMultipleUsers(iouReport: OnyxEntry<Report>): boolean {
    const transactions = getReportTransactions(iouReport?.reportID);
    // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
    return isIOUReport(iouReport) && transactions.some((transaction) => (transaction?.modifiedAmount || transaction?.amount) < 0);

    which is the condition we used to determine if we can display change workspace option in the more options.

    So we should update both to the condition consistent with the above

    App/src/libs/actions/Report.ts

    Lines 4976 to 4980 in 74e1436

    // We do not want to create negative amount expenses
    if (!isReimbursed && ReportActionsUtils.hasRequestFromCurrentAccount(reportID, iouReport.managerID ?? CONST.DEFAULT_NUMBER_ID)) {
    return;
    }

    App/src/libs/actions/Report.ts

    Lines 5158 to 5162 in 74e1436

    // We only allow moving IOU report to a policy if it doesn't have requests from multiple users, as we do not want to create negative amount expenses
    if (!isReimbursed && ReportActionsUtils.hasRequestFromCurrentAccount(reportID, iouReport.managerID ?? CONST.DEFAULT_NUMBER_ID)) {
    return;
    }

    
        if (!isReimbursed && doesReportContainRequestsFromMultipleUsers(iouReport)) {
            return;
        }
    

    Additionally, we can still update hasRequestFromCurrentAccount to take account of deleted iou actions because we still use it in another place.

    return reportActions.some((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && action.actorAccountID === currentAccountID && !isDeletedAction(action));
    

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

    If needed can test moveIOUReportToPolicyAndInviteSubmitter properly moves iou report when there is a deleted iou action from the manager of the iou report.

    What alternative solutions did you explore? (Optional)

  12. 21 remaining items

  13. changed the title [-][$250] Expense - Nothing happens when submitter deletes own expense and clicks Change workspace[/-] [+][Due for payment 2025-07-30] [$250] Expense - Nothing happens when submitter deletes own expense and clicks Change workspace[/+] on Jul 23, 2025
  14. melvin-bot commented on Jul 23, 2025

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  15. melvin-bot commented on Jul 23, 2025

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.1.84-4 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2025-07-30. 🎊

    For reference, here are some details about the assignees on this issue:

  16. melvin-bot commented on Jul 23, 2025

    @melvin-bot

    @Pujan92 @sakluger The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

  17. Pujan92 commented on Jul 31, 2025

    @Pujan92
    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
    • 2b. Reported on staging (deploy blocker)
    • 2c. Reported on both staging and production
    • 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/58078/files#r2245296227

    • [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: N/A

    • [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.

    • [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:

    • User A has a workspace.
    1. [User A] Submit an expense to User B.
    2. [User B] Submit an expense to User A.
    3. [User A] Open the expense report.
    4. [User A] Delete the submitted expense from Step 2.
    5. [User A] Click More > Change workspace.
    6. [User A] Select any workspace.
    7. [User A] Verify that the expense is moved to the workspace

    Do we agree 👍 or 👎

  18. sakluger commented on Jul 31, 2025

    @sakluger
    Contributor

    Payment Summary

    Contributor: @etCoderDysto paid $250 via Upwork
    Contributor+: @Pujan92 request $250 via Newdot

  19. moved this from Bugs and Follow Up Issues to Done in #expensify-bugson Jul 31, 2025
  20. garrettmknight commented on Aug 1, 2025

    @garrettmknight
    Contributor

    $250 approved for @Pujan92

  21. isabelastisser commented on Aug 5, 2025

    @isabelastisser
    Contributor

    @Pujan92 has submitted payment for this report on ND here.

    SO: https://stackoverflowteams.com/c/expensify/questions/7582

    Vendor found in VML: True. Status: Active

    Amount requested: $250.00 (Matches the payment summary here.

    I am not already the BZ assignee. I have approved this payment.

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