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

[HOLD for payment 2024-11-11] [$250] Held expense-Negative amount in transaction thread for held expense after paying unheld expense #49754

Closed
6 tasks done
IuliiaHerets opened this issue Sep 25, 2024 · 37 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2

Comments

@IuliiaHerets
Copy link

IuliiaHerets commented Sep 25, 2024

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.0.40-1
Reproducible in staging?: Y
Reproducible in production?: Y
Issue was found when executing this PR: #49463
Email or phone of affected tester (no customers): [email protected]
Issue reported by: Applause Internal Team

Action Performed:

  1. Go to staging.new.expensify.com
  2. [User A] Submit two expenses to User B.
  3. [User A] Hold one of the expenses.
  4. [User B] Go offline.
  5. [User B] Pay the unheld expense.
  6. [User B] Click on the expense preview of the held expense in the main chat.

Expected Result:

The amount in the transaction thread will not be negative.

Actual Result:

The amount in the transaction thread is negative.

Workaround:

Unknown

Platforms:

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Bug6615322_1727299431457.20240926_051632.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021841126678085530276
  • Upwork Job ID: 1841126678085530276
  • Last Price Increase: 2024-10-15
  • Automatic offers:
    • Nodebrute | Contributor | 104483850
Issue OwnerCurrent Issue Owner: @OfstadC
@IuliiaHerets IuliiaHerets added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Sep 25, 2024
Copy link

melvin-bot bot commented Sep 25, 2024

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

@IuliiaHerets
Copy link
Author

We think that this bug might be related to #wave-collect - Release 1

@IuliiaHerets
Copy link
Author

@OfstadC FYI I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors

@Nodebrute
Copy link
Contributor

Nodebrute commented Sep 26, 2024

Edited by proposal-police: This proposal was edited at 2024-10-09 18:11:01 UTC.

Proposal

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

Negative amount in transaction thread for held expense after paying unheld expense

What is the root cause of that problem?

For expense report case we add - before amount because the amounts are stored using an opposite sign

// Expense report case:
// The amounts are stored using an opposite sign and negative values can be set,
// we need to return an opposite sign than is saved in the transaction object
let amount = transaction?.modifiedAmount ?? 0;
if (amount) {
return -amount;
}

However, when we handle the pay money request and use getReportFromHoldRequestsOnyxData, we are actually creating an ExpenseReport. For 1:1 direct messages, it should instead be an IOUReport.

App/src/libs/actions/IOU.ts

Lines 6451 to 6459 in b655040

const optimisticExpenseReport = ReportUtils.buildOptimisticExpenseReport(
chatReport.reportID,
chatReport.policyID ?? iouReport?.policyID ?? '',
recipient.accountID ?? 1,
holdTransactions.reduce((acc, transaction) => acc + transaction.amount, 0) * (ReportUtils.isIOUReport(iouReport) ? 1 : -1),
getCurrency(firstHoldTransaction),
false,
newParentReportActionID,
);

This is also not consistent with the BE response in case of 1:1 DMs the backend will return an IOUReport

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

We should add a check here isPolicyExpenseChat. The idea is that if it's a policy expense chat, we should build an optimistic expense report using buildOptimisticExpenseReport. If it's not a policy expense chat, then we should build an optimistic IOU report using buildOptimisticIOUReport. This is the same logic we are using here Pseudocode

 const optimisticExpenseReport = isPolicyExpenseChat
        ? ReportUtils.buildOptimisticExpenseReport(
              chatReport.reportID,
              chatReport.policyID ?? iouReport?.policyID ?? '',
              recipient.accountID ?? 1,
              totalAmount,
              getCurrency(firstHoldTransaction),
              false,
              newParentReportActionID,
          )
        : ReportUtils.buildOptimisticIOUReport(recipient.accountID ?? 1, iouReport?.managerID ?? 1, totalAmount, chatReport.reportID, getCurrency(firstHoldTransaction), false);

After this change, this line will evaluate to false, and we'll move to this block, where we'll apply -amount, which will fix the bug

if (!isFromExpenseReport || isFromTrackedExpense) {

Note: This is pseudocode only. We need to test the implementation with multiple test cases, which can be done in the pull request (PR).

What alternative solutions did you explore? (Optional)

We can use buildOptimisticIOUReport here instead of buildOptimisticExpenseReport

@OfstadC
Copy link
Contributor

OfstadC commented Sep 27, 2024

Missed this yesterday - reviewing now

Copy link

melvin-bot bot commented Sep 30, 2024

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

@OfstadC
Copy link
Contributor

OfstadC commented Oct 1, 2024

I had issues reproducing this on Friday - forgot to add a comment here.

@melvin-bot melvin-bot bot removed the Overdue label Oct 1, 2024
@m-natarajan
Copy link

Able to reproduce

20241001_220541.mp4

@OfstadC OfstadC added the External Added to denote the issue can be worked on by a contributor label Oct 1, 2024
@melvin-bot melvin-bot bot changed the title Held expense-Negative amount in transaction thread for held expense after paying unheld expense [$250] Held expense-Negative amount in transaction thread for held expense after paying unheld expense Oct 1, 2024
Copy link

melvin-bot bot commented Oct 1, 2024

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

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Oct 1, 2024
Copy link

melvin-bot bot commented Oct 1, 2024

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

@hungvu193
Copy link
Contributor

On my list this weekend.

@hungvu193
Copy link
Contributor

Reviewing shortly

@hungvu193
Copy link
Contributor

hey @Nodebrute, I think your proposal makes sense, can you please provide a little more detailed about your main solution? TIA.

@Nodebrute
Copy link
Contributor

Thank You @hungvu193, I'll update in few hours.

Copy link

melvin-bot bot commented Oct 8, 2024

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

@hungvu193
Copy link
Contributor

Waiting for contributor information, no action required

Copy link

melvin-bot bot commented Oct 9, 2024

@OfstadC @hungvu193 this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!

@Nodebrute
Copy link
Contributor

@hungvu193 I've updated my main proposal. I tried my best to explain it as clearly as possible, but I'm unsure how to add more detail. Please let me know if you have any questions, and I'll do my best to answer them.

@hungvu193
Copy link
Contributor

Thanks I'll review it today

@hungvu193
Copy link
Contributor

I see/ i'll check it in a while

@melvin-bot melvin-bot bot removed the Overdue label Oct 17, 2024
@hungvu193
Copy link
Contributor

Thanks for your details. @Nodebrute 's proposal here looks good to me!

@hungvu193
Copy link
Contributor

🎀 👀 🎀

Copy link

melvin-bot bot commented Oct 18, 2024

Triggered auto assignment to @blimpich, 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 Oct 18, 2024
Copy link

melvin-bot bot commented Oct 18, 2024

📣 @Nodebrute 🎉 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 📖

@Nodebrute Nodebrute mentioned this issue Oct 19, 2024
50 tasks
Copy link

melvin-bot bot commented Oct 21, 2024

@OfstadC, @hungvu193, @blimpich, @Nodebrute Whoops! This issue is 2 days overdue. Let's get this updated quick!

@melvin-bot melvin-bot bot added the Overdue label Oct 21, 2024
@hungvu193
Copy link
Contributor

Not overdue. PR is inprogress

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Overdue Daily KSv2 labels Oct 22, 2024
@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Nov 4, 2024
@melvin-bot melvin-bot bot changed the title [$250] Held expense-Negative amount in transaction thread for held expense after paying unheld expense [HOLD for payment 2024-11-11] [$250] Held expense-Negative amount in transaction thread for held expense after paying unheld expense Nov 4, 2024
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Nov 4, 2024
Copy link

melvin-bot bot commented Nov 4, 2024

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

Copy link

melvin-bot bot commented Nov 4, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.56-9 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 2024-11-11. 🎊

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

Copy link

melvin-bot bot commented Nov 4, 2024

@hungvu193 @OfstadC 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]

@OfstadC
Copy link
Contributor

OfstadC commented Nov 5, 2024

Commenting to please Melly Melvin. @hungvu193 Please ensure BZ checklist is completed by payment date. Thank you!

@hungvu193
Copy link
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/42573/files#r1836147530

  • 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

  • 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: We already created some tests to prevent this case, I don't think we need regression test for this one.

@OfstadC
Copy link
Contributor

OfstadC commented Nov 11, 2024

Payment Summary

@OfstadC OfstadC closed this as completed Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2
Projects
None yet
Development

No branches or pull requests

6 participants