Expensify / App

Welcome to New Expensify: a complete re-imagination of financial collaboration, centered around chat. Help us build the next generation of Expensify by sharing feedback and contributing to the code.
https://new.expensify.com
MIT License
3.57k stars 2.91k forks source link

[$250] Expense - Expense preview shows "x paid amount" when expense payment is cancelled offline #52135

Open lanitochka17 opened 2 weeks ago

lanitochka17 commented 2 weeks ago

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.0.58-1 Reproducible in staging?: Y Reproducible in production?: Y If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: Y If this was caught during regression testing, add the test name, ID and link from TestRail: N/A Email or phone of affected tester (no customers): applausetester+kh2610010@applause.expensifail.com Issue reported by: Applause - Internal Team

Action Performed:

Precondition:

Expected Result:

The expense preview will show "x owes amount" without checkmark because the expense payment is cancelled offline

Actual Result:

The expense preview shows "x paid amount" when expense payment is cancelled offline

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

Screenshots/Videos

Add any screenshot/video evidence

https://github.com/user-attachments/assets/5e219d01-3bef-411c-8271-a6869e272d11

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021854562907265274025
  • Upwork Job ID: 1854562907265274025
  • Last Price Increase: 2024-11-07
  • Automatic offers:
    • mkzie2 | Contributor | 104908738
Issue OwnerCurrent Issue Owner: @sobitneupane
melvin-bot[bot] commented 2 weeks ago

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

mkzie2 commented 2 weeks ago

Edited by proposal-police: This proposal was edited at 2024-11-12 14:23:20 UTC.

Proposal

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

The expense preview shows "x paid amount" when expense payment is cancelled offline

What is the root cause of that problem?

iouSettled condition is true if isSettled function returns true or action.childStatusNum is CONST.REPORT.STATUS_NUM.REIMBURSED

https://github.com/Expensify/App/blob/c755314f826a771ea9b3eb1aa5c1dd92a5aae483/src/components/ReportActionItem/ReportPreview.tsx#L135

After paying the expense, action.childStatusNum is updated correctly. But when we cancel the payment and unapproved the report, this status isn't updated (only the statusNum of the expense report is updated).

It leads iouSettled is still true because this condition action?.childStatusNum === CONST.REPORT.STATUS_NUM.REIMBURSED is still true

https://github.com/Expensify/App/blob/c755314f826a771ea9b3eb1aa5c1dd92a5aae483/src/components/ReportActionItem/ReportPreview.tsx#L135

And the preview is displayed x paid amount

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

We should only check action?.childStatusNum when the iou report data isn't available

const iouSettled = iouReport ? ReportUtils.isSettled(iouReportID) : action?.childStatusNum === CONST.REPORT.STATUS_NUM.REIMBURSED;

https://github.com/Expensify/App/blob/c755314f826a771ea9b3eb1aa5c1dd92a5aae483/src/components/ReportActionItem/ReportPreview.tsx#L135

What alternative solutions did you explore? (Optional)

When we cancel the payment and unapproved the report we should update childStateNum and childStatusNum of the parent report action in optimistic data and reset it in failure data with the value like here and here

The value of childStateNum and childStatusNum will be the same as stateNum and statusNum values that we updated for the expense report. Here is an example

{
    onyxMethod: Onyx.METHOD.MERGE,
    key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.parentReportID}`,
    value: {
        [expenseReport.parentReportActionID]: {
            childStateNum: stateNum,
            childStatusNum: statusNum,
        },
    },
},

https://github.com/Expensify/App/blob/c755314f826a771ea9b3eb1aa5c1dd92a5aae483/src/libs/actions/IOU.ts#L7551-L7552

https://github.com/Expensify/App/blob/c755314f826a771ea9b3eb1aa5c1dd92a5aae483/src/libs/actions/IOU.ts#L7351-L7352

joekaufmanexpensify commented 2 weeks ago

Reproduced. Yeah, if we're showing Approve again on the report preview if you unapproved while offline, it seems odd that we are showing the report as paid when it was also canceled offline.

Seems like this is a pattern B situation based on the unapproved and payment cancel comments having .5 opacity. Not sure if we need to do something to signal on the report preview to signal pattern B too though.

https://github.com/user-attachments/assets/98b37b88-ea48-469a-ac1d-91b57398449e

melvin-bot[bot] commented 2 weeks ago

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

melvin-bot[bot] commented 2 weeks ago

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

melvin-bot[bot] commented 1 week ago

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

joekaufmanexpensify commented 1 week ago

Pending @sobitneupane review of proposals

sobitneupane commented 1 week ago

Thanks for the proposal @mkzie2

I prefer the alternative proposal as it directly addresses the root cause of the issue.

When we cancel the payment and unapproved the report we should update childStateNum and childStatusNum of the parent report action in optimistic data and reset it in failure data with the value like here and here

Could you clarify what values we should update childStateNum and childStatusNum to? It would be helpful if you could provide additional details for this alternative solution.

mkzie2 commented 1 week ago

@sobitneupane In two places, we will update childStateNum, childStatusNum with the same stateNum and statusNum value that we updated for the expense report

https://github.com/Expensify/App/blob/c755314f826a771ea9b3eb1aa5c1dd92a5aae483/src/libs/actions/IOU.ts#L7551-L7552

https://github.com/Expensify/App/blob/c755314f826a771ea9b3eb1aa5c1dd92a5aae483/src/libs/actions/IOU.ts#L7351-L7352

sobitneupane commented 1 week ago

@mkzie2 Could you please update the proposal with all the details.

mkzie2 commented 1 week ago

@sobitneupane I updated my proposal.

sobitneupane commented 1 week ago

Thanks for the update @mkzie2

Alternative proposal from @mkzie2 looks good to me.

πŸŽ€ πŸ‘€ πŸŽ€ C+ reviewed

melvin-bot[bot] commented 1 week ago

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

melvin-bot[bot] commented 1 week ago

πŸ“£ @mkzie2 πŸŽ‰ 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 πŸ“–

mkzie2 commented 5 days ago

@sobitneupane The PR is ready.

joekaufmanexpensify commented 4 days ago

PR in review