Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[$250] Expense - Expense duplicated when deleting all expenses of a report and submitting new one. #57304

Open
4 of 8 tasks
IuliiaHerets opened this issue Feb 23, 2025 · 20 comments
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor Overdue

Comments

@IuliiaHerets
Copy link

IuliiaHerets commented Feb 23, 2025

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: 9.1.4-0
Reproducible in staging?: Yes
Reproducible in production?: Yes
Email or phone of affected tester (no customers): [email protected]
Issue reported by: Applause Internal Team
Device used: Motorola MotoG60 - Android 12 - Chrome / Windows 10 - Chrome
App Component: Money Requests

Action Performed:

Prerequisite: Delay submission and approvals disabled.

  1. Open the staging.new.expensify.com website.
  2. Open any workspace chat without expenses in it.
  3. Click on "+" button and select "Create Expense"
  4. Add an amount and click on "Next"
  5. Add a merchant and submit the expense.
  6. Click on "+" button again and select "Create Expense"
  7. Complete the creation flow with the same merchant as the first expense.
  8. Once redirected to conversation, open the report with the two expenses and delete them.
  9. Return to conversation.
  10. Click on "+" button and select "Create Expense"
  11. Complete the expense creation flow.
  12. Check the expense preview behaviour once redirected to chat again.

Expected Result:

Expense submitted to workspace should only be displayed once, after deleting the previously submitted expenses.

Actual Result:

Report is displayed duplicated on workspace chat, when expense is submitted after deleting a report with two expenses.

Workaround:

Unknown

Platforms:

  • Android: Standalone
  • Android: HybridApp
  • Android: mWeb Chrome
  • iOS: Standalone
  • iOS: HybridApp
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Bug6750952_1740241191211.Dup.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021894066689236146219
  • Upwork Job ID: 1894066689236146219
  • Last Price Increase: 2025-03-03
  • Automatic offers:
    • OmarKoueifi | Contributor | 106380248
@IuliiaHerets IuliiaHerets added Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 labels Feb 23, 2025
Copy link

melvin-bot bot commented Feb 23, 2025

Triggered auto assignment to @isabelastisser (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.

@isabelastisser isabelastisser added External Added to denote the issue can be worked on by a contributor Help Wanted Apply this label when an issue is open to proposals by contributors labels Feb 24, 2025
@melvin-bot melvin-bot bot changed the title Expense - Expense duplicated when deleting all expenses of a report and submitting new one. [$250] Expense - Expense duplicated when deleting all expenses of a report and submitting new one. Feb 24, 2025
Copy link

melvin-bot bot commented Feb 24, 2025

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

Copy link

melvin-bot bot commented Feb 24, 2025

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

@gurus00
Copy link

gurus00 commented Feb 24, 2025

Proposal

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

Expense duplicated when deleting all expenses of a report and submitting new one.

What is the root cause of that problem?

Store is not updated after deleting expenses

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

We should check and fix the store update after deleting/creating/updating expenses

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

N/A

What alternative solutions did you explore? (Optional)

@dylanexpensify dylanexpensify moved this to Bugs and Follow Up Issues in [#whatsnext] #expense Feb 25, 2025
@isabelastisser
Copy link
Contributor

@Ollyws can you pls review the proposal? thanks!

@OmarKoueifi
Copy link
Contributor

Proposal

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

After submitting an expense to a workspace after deleting a report containing two expenses, the report appears duplicated in the workspace chat.

What is the root cause of that problem?

  • In IOU.ts, the function getMoneyRequestInformation determines whether a new Report Preview should be created or an existing one should be updated.
  • If a deleted report preview is mistakenly referenced, the system creates a duplicate report preview, causing two reports to appear instead of one.

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

Modify the function getReportPreviewAction in IOU.ts to return only reportActions that have not been deleted.

  • getReportPreviewAction is called in:
    let reportPreviewAction = shouldCreateNewMoneyRequestReport ? null : getReportPreviewAction(chatReport.reportID, iouReport.reportID);
    • Based on this, we check whether to update the existing reportPreviewAction with updateReportPreview or create a new one with buildOptimisticReportPreview:

      App/src/libs/actions/IOU.ts

      Lines 2752 to 2763 in 932f977

      let reportPreviewAction = shouldCreateNewMoneyRequestReport ? null : getReportPreviewAction(chatReport.reportID, iouReport.reportID);
      if (reportPreviewAction) {
      reportPreviewAction = updateReportPreview(iouReport, reportPreviewAction, false, comment, optimisticTransaction);
      } else {
      reportPreviewAction = buildOptimisticReportPreview(chatReport, iouReport, comment, optimisticTransaction);
      chatReport.lastVisibleActionCreated = reportPreviewAction.created;
      // Generated ReportPreview action is a parent report action of the iou report.
      // We are setting the iou report's parentReportActionID to display subtitle correctly in IOU page when offline.
      iouReport.parentReportActionID = reportPreviewAction.reportActionID;
      }
    • If reportPreviewAction was deleted, the logic will go to the else block and create a new reportPreviewAction using buildOptimisticReportPreview, avoiding referencing a deleted report.
  • getReportPreviewAction is used in multiple places in IOU.ts, so this change will fix similar issues elsewhere as well.
  • To ensure this change does not cause unintended regressions, I will verify whether it impacts existing flows.
  • If necessary, I will introduce a new optional boolean parameter, e.g., checkForDeleted, which:
    • If true → The function will exclude deleted reportActions.
    • If false → The function will follow the existing logic to avoid disrupting other use cases.

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

  1. Submit an expense after deleting a report with two expenses
  • Given: A workspace where a report containing two expenses was deleted.
  • When: The user submits a new expense via "Create Expense".
  • Then:
    • Only one report preview should appear in the workspace chat.
    • The report should not be duplicated.
  1. Ensure correct behavior after multiple deletions and submissions
  • Given: A workspace where expenses are repeatedly deleted and resubmitted.
  • When: The user deletes all reports and submits a new expense.
  • Then:
    • The newly submitted expense should correctly appear in one report preview.
    • No duplicate report previews should be generated.

What alternative solutions did you explore? (Optional)

NA

@Ollyws
Copy link
Contributor

Ollyws commented Feb 27, 2025

I can't reproduce this, when I delete the final expense the expense report is removed too. Also, it seemed in the bug report the real problem is the fact that we are left with an empty expense report reading $0.00.
Is it still reproducible for you @OmarKoueifi ?

@OmarKoueifi
Copy link
Contributor

OmarKoueifi commented Feb 28, 2025

@Ollyws Yes I just pulled latest from main and reproduced:

Screen.Recording.2025-02-27.at.10.49.45.PM.mov

@Ollyws
Copy link
Contributor

Ollyws commented Feb 28, 2025

@OmarKoueifi I'm a little confused about your proposal, you propose to modify getReportPreviewAction to return only report actions that have not been deleted, but isn't the problem here that getReportPreviewAction isn't returning anything, despite having a visible report-action? Which is why it's creating a new preview action with buildOptimisticReportPreview.

@OmarKoueifi
Copy link
Contributor

@Ollyws Sorry for the confusion! I'll try to explain better.
getReportPreviewAction is returning a deleted report action and using that to update it and send to backend

After deleting all expenses, when creating a new expense, getReportPreviewAction is called and returns a deleted report with a reportActionID that belongs to a deleted reportAction.

It looks like the backend is creating a new report, but in the UI, we end up displaying two reports:

  1. One for the deleted report (which is empty when checking redux).
  2. Another for the newly created report (which contains the correct values).

I confirmed this using Redux DevTools, where I can see the deleted report still present with no values, while the new one contains the actual data.

By adding a check for deleted reports in getReportPreviewAction, it will prevent returning the deleted report, ensuring that only the valid, newly created report is used, keeping the UI in sync.

Let me know if anything is still unclear, I'm happy to clarify further!

Screen.Recording.2025-02-28.at.12.14.44.PM.mov

Copy link

melvin-bot bot commented Mar 3, 2025

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@melvin-bot melvin-bot bot added the Overdue label Mar 3, 2025
@isabelastisser
Copy link
Contributor

@Ollyws, can you please follow up? Thanks!

Copy link

melvin-bot bot commented Mar 4, 2025

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

@Ollyws
Copy link
Contributor

Ollyws commented Mar 4, 2025

Will have a deeper look into this one today.

@melvin-bot melvin-bot bot removed the Overdue label Mar 4, 2025
@Ollyws
Copy link
Contributor

Ollyws commented Mar 4, 2025

Ah thanks for the explanation, @OmarKoueifi's proposal LGTM.
🎀👀🎀 C+ reviewed

Copy link

melvin-bot bot commented Mar 4, 2025

Triggered auto assignment to @grgia, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Mar 4, 2025
Copy link

melvin-bot bot commented Mar 4, 2025

📣 @OmarKoueifi 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job
Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

@grgia
Copy link
Contributor

grgia commented Mar 4, 2025

assigned!

@OmarKoueifi
Copy link
Contributor

Thank you! I should have a PR by Monday morning

@melvin-bot melvin-bot bot added the Overdue label Mar 7, 2025
@isabelastisser
Copy link
Contributor

Not overdue, waiting for PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor Overdue
Projects
Status: Bugs and Follow Up Issues
Development

No branches or pull requests

6 participants