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

[$500] Distance - Total amount in report is not reset to 0.00 when changing distance request offline #36892

Closed
6 tasks done
lanitochka17 opened this issue Feb 20, 2024 · 21 comments
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Engineering 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

Comments

@lanitochka17
Copy link

lanitochka17 commented Feb 20, 2024

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: 1.4.43-2
Reproducible in staging?: Y
Reproducible in production?: N
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: Applause - Internal Team
Slack conversation:

Action Performed:

  1. Navigate to staging.new.expensify.com
  2. Create a new workspace (so that there is no existing request)
  3. Go to workspace chat
  4. Create a distance request
  5. Go to request details page
  6. Go offline
  7. Click Distance
  8. Add another stop
  9. Return to expense report

Expected Result:

The total amount will change to 0.00 (PROD behavior)

Actual Result:

The total amount does not change to 0.00

Workaround:

Unknown

Platforms:

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

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

Screenshots/Videos

Add any screenshot/video evidence

Bug6385602_1708428297435.bandicam_2024-02-20_15-58-44-921.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01ed2116286bd18632
  • Upwork Job ID: 1759952290692452352
  • Last Price Increase: 2024-03-15
@lanitochka17 lanitochka17 added DeployBlockerCash This issue or pull request should block deployment External Added to denote the issue can be worked on by a contributor labels Feb 20, 2024
@melvin-bot melvin-bot bot changed the title Distance - Total amount in report is not reset to 0.00 when changing distance request offline [$500] Distance - Total amount in report is not reset to 0.00 when changing distance request offline Feb 20, 2024
Copy link

melvin-bot bot commented Feb 20, 2024

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

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

melvin-bot bot commented Feb 20, 2024

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

@melvin-bot melvin-bot bot added the Daily KSv2 label Feb 20, 2024
@github-actions github-actions bot added Engineering Hourly KSv2 and removed Daily KSv2 labels Feb 20, 2024
Copy link
Contributor

👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

  1. Identify the pull request that introduced this issue and revert it.
  2. Find someone who can quickly fix the issue.
  3. Fix the issue yourself.

Copy link

melvin-bot bot commented Feb 20, 2024

Triggered auto assignment to @madmax330 (Engineering), see https://stackoverflowteams.com/c/expensify/questions/9980/ for more details.

@lanitochka17
Copy link
Author

We think that this bug might be related to #wave5
CC @dylanexpensify

@paultsimura
Copy link
Contributor

paultsimura commented Feb 20, 2024

Proposal

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

The money request total is not changed when the waypoints are changed offline

What is the root cause of that problem?

This is a regression from #35880 – the conflict with main was resolved incorrectly.

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

First, we should move the total recalculation out of the if (!hasPendingWaypoints) check how it was done in #34135:

    if (!hasPendingWaypoints) {
        params.reportActionID = updatedReportAction.reportActionID;

        optimisticData.push({
            onyxMethod: Onyx.METHOD.MERGE,
            key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThread?.reportID}`,
            value: {
                [updatedReportAction.reportActionID]: updatedReportAction as OnyxTypes.ReportAction,
            },
        });
        successData.push({
            onyxMethod: Onyx.METHOD.MERGE,
            key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThread?.reportID}`,
            value: {
                [updatedReportAction.reportActionID]: {pendingAction: null},
            },
        });
        failureData.push({
            onyxMethod: Onyx.METHOD.MERGE,
            key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThread?.reportID}`,
            value: {
                [updatedReportAction.reportActionID]: {
                    ...(updatedReportAction as OnyxTypes.ReportAction),
                    errors: ErrorUtils.getMicroSecondOnyxError('iou.error.genericEditFailureMessage'),
                },
            },
        });
+   }

        // Step 4: Compute the IOU total and update the report preview message (and report header) so LHN amount owed is correct.
        let updatedMoneyRequestReport = {...iouReport};
        const diff = calculateDiffAmount(iouReport, updatedTransaction, transaction);

        if (ReportUtils.isExpenseReport(iouReport) && typeof updatedMoneyRequestReport.total === 'number') {
            // For expense report, the amount is negative so we should subtract total from diff
            updatedMoneyRequestReport.total -= diff;
        } else {
            updatedMoneyRequestReport = iouReport
                ? IOUUtils.updateIOUOwnerAndTotal(iouReport, updatedReportAction.actorAccountID ?? -1, diff, TransactionUtils.getCurrency(transaction), false, true)
                : {};
        }
        updatedMoneyRequestReport.cachedTotal = CurrencyUtils.convertToDisplayString(updatedMoneyRequestReport.total, updatedTransaction?.modifiedCurrency);

        optimisticData.push({
            onyxMethod: Onyx.METHOD.MERGE,
            key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.reportID}`,
            value: updatedMoneyRequestReport,
        });
        successData.push({
            onyxMethod: Onyx.METHOD.MERGE,
            key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.reportID}`,
            value: {pendingAction: null},
        });
-    }

App/src/libs/actions/IOU.ts

Lines 1103 to 1155 in 0f409d4

if (!hasPendingWaypoints) {
params.reportActionID = updatedReportAction.reportActionID;
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThread?.reportID}`,
value: {
[updatedReportAction.reportActionID]: updatedReportAction as OnyxTypes.ReportAction,
},
});
successData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThread?.reportID}`,
value: {
[updatedReportAction.reportActionID]: {pendingAction: null},
},
});
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThread?.reportID}`,
value: {
[updatedReportAction.reportActionID]: {
...(updatedReportAction as OnyxTypes.ReportAction),
errors: ErrorUtils.getMicroSecondOnyxError('iou.error.genericEditFailureMessage'),
},
},
});
// Step 4: Compute the IOU total and update the report preview message (and report header) so LHN amount owed is correct.
let updatedMoneyRequestReport = {...iouReport};
const diff = calculateDiffAmount(iouReport, updatedTransaction, transaction);
if (ReportUtils.isExpenseReport(iouReport) && typeof updatedMoneyRequestReport.total === 'number') {
// For expense report, the amount is negative so we should subtract total from diff
updatedMoneyRequestReport.total -= diff;
} else {
updatedMoneyRequestReport = iouReport
? IOUUtils.updateIOUOwnerAndTotal(iouReport, updatedReportAction.actorAccountID ?? -1, diff, TransactionUtils.getCurrency(transaction), false, true)
: {};
}
updatedMoneyRequestReport.cachedTotal = CurrencyUtils.convertToDisplayString(updatedMoneyRequestReport.total, updatedTransaction?.modifiedCurrency);
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.reportID}`,
value: updatedMoneyRequestReport,
});
successData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.reportID}`,
value: {pendingAction: null},
});
}

Second, we should update the IOU.calculateDiffAmount function to allow the updatedTransaction?.modifiedAmount to be 0:

if (updatedCurrency === iouReport?.currency && updatedTransaction?.modifiedAmount !== undefined) {
        // Calculate the diff between the updated amount and the current amount if we change the amount and the currency of the transaction is the currency of the report
        return updatedAmount - currentAmount;
}

App/src/libs/actions/IOU.ts

Lines 1006 to 1009 in 0f409d4

if (updatedCurrency === iouReport?.currency && updatedTransaction?.modifiedAmount) {
// Calculate the diff between the updated amount and the current amount if we change the amount and the currency of the transaction is the currency of the report
return updatedAmount - currentAmount;
}

What alternative solutions did you explore? (Optional)

@ishpaul777
Copy link
Contributor

ishpaul777 commented Feb 20, 2024

@paultsimura Can you please elaborate the root cause and solution or should i find it myself looking at large diffs mentioned

https://github.com/Expensify/App/pull/34135/files#diff-9c07b44e092fd3d975806649be46d76b75a377c16e32ed86597b630a84c290d0

@paultsimura
Copy link
Contributor

You're right @ishpaul777 – updated it in the proposal

@ishpaul777
Copy link
Contributor

ishpaul777 commented Feb 20, 2024

@paultsimura Unfortunately you solution was not working for me, do you mind sharing a working branch if you have it handy? may be i am missing something

@paultsimura
Copy link
Contributor

@paultsimura Unfortunately you solution was not working for me, do you mind sharing a working branch if you have it handy? may be i am missing something

Sure, will share within 2-3 hours - I'm afk at the moment

@paultsimura
Copy link
Contributor

@ishpaul777 here it is: #36960

Screen.Recording.2024-02-20.at.22.50.39-compressed.mp4

@ishpaul777
Copy link
Contributor

ishpaul777 commented Feb 20, 2024

Thanks i'll take a look in my morning, but most probably this might be handled by Pr author as we won't deploy until Thursday.

cc @dukenv0307

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Hourly KSv2 labels Feb 21, 2024
@dukenv0307
Copy link
Contributor

The PR to fix this issue here #37005

cc @cubuspl42

@neil-marcellini
Copy link
Contributor

Taking over this issue to get the blocker fixed quickly

@cubuspl42
Copy link
Contributor

Thank you!

@puneetlath puneetlath removed the DeployBlockerCash This issue or pull request should block deployment label Feb 29, 2024
@mvtglobally
Copy link

Issue not reproducible during KI retests. (First week)

@ishpaul777
Copy link
Contributor

This should be ready for C+ payment @neil-marcellini Can you please remove reviewing label

@neil-marcellini neil-marcellini added Bug Something is broken. Auto assigns a BugZero manager. and removed Reviewing Has a PR in review labels Mar 15, 2024
Copy link

melvin-bot bot commented Mar 15, 2024

Triggered auto assignment to @twisterdotcom (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Mar 15, 2024
Copy link

melvin-bot bot commented Mar 15, 2024

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

@twisterdotcom
Copy link
Contributor

Payment Summary:

@ishpaul777
Copy link
Contributor

@twisterdotcom accepted offer 🙂 Thanks!

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 Engineering 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
Projects
None yet
Development

No branches or pull requests

10 participants