Skip to content

[HOLD for payment 2024-12-16] [HOLD for payment 2024-12-11] [$250] [Held requests] Partial paying a report causes the wrong amounts to show in the LHN #48760

Closed

Description

@m-natarajan

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.30-15
Reproducible in staging?: Yes
Reproducible in production?: Yes
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: @JmillsExpensify
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1725649428907579

Action Performed:

  1. On a Collect policy, have user A submit several expenses to User B
  2. As User B, hold at least two expenses, approve the rest

Expected Result:

The report amount in the LHN is correct.

Actual Result:

The report amount in the LHN only shows the amount of one expense

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

CleanShot 2024-09-06 at 20 44 35@2x

CleanShot 2024-09-06 at 20 45 06@2x

Recording.522.mp4

Add any screenshot/video evidence

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021833144594407206391
  • Upwork Job ID: 1833144594407206391
  • Last Price Increase: 2024-09-09
Issue OwnerCurrent Issue Owner: @robertjchen

Activity

  1. added
    Daily
    Bug
    on Sep 7, 2024
  2. melvin-bot commented on Sep 7, 2024

    @melvin-bot

    Triggered auto assignment to @kevinksullivan (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. bernhardoj commented on Sep 9, 2024

    @bernhardoj
    Contributor

    Proposal

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

    Approving partly a report with held transaction will show the incorrect amount for the new report that contains all the held transaction.

    What is the root cause of that problem?

    There are 2 problems. First, when we approve the report, we create the new expense report optimistically that contains all the held transactions, but, we only use the first amount as the report total amount.

    App/src/libs/actions/IOU.ts

    Lines 6390 to 6394 in 03ec468

    const optimisticExpenseReport = ReportUtils.buildOptimisticExpenseReport(
    chatReport.reportID,
    chatReport.policyID ?? iouReport.policyID ?? '',
    recipient.accountID ?? 1,
    (firstHoldTransaction?.amount ?? 0) * -1,

    Also, we don't optimistically update the approved report total by subtracting the current total with the new expense report total

    App/src/libs/actions/IOU.ts

    Lines 6943 to 6949 in 03ec468

    const optimisticIOUReportData: OnyxUpdate = {
    onyxMethod: Onyx.METHOD.MERGE,
    key: `${ONYXKEYS.COLLECTION.REPORT}${expenseReport?.reportID}`,
    value: {
    ...expenseReport,
    lastMessageText: ReportActionsUtils.getReportActionText(optimisticApprovedReportAction),
    lastMessageHtml: ReportActionsUtils.getReportActionHtml(optimisticApprovedReportAction),

    Second, even though the optimistic data is incorrect, we receive the correct data from the BE response. However, the LHN last message isn't updated immediately. The LHN shows the total from the expense report and we get the report inside the function instead of connecting the LHN component with the report.

    } else if (ReportActionUtils.isReportPreviewAction(lastReportAction)) {
    const iouReport = ReportUtils.getReportOrDraftReport(ReportActionUtils.getIOUReportIDFromReportActionPreview(lastReportAction));

    And even though we connect all reports inside lhn list,

    const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);

    the OptionRowLHNData is memoized, so it won't re-render if the props are not changed.

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

    Update the optimistic data to set the correct amount for the new expense report.

    (firstHoldTransaction?.amount ?? 0) * -1,

    We can calculate it from the report total and unheldTotal,
    (iouReport.total - iouReport.unheldTotal) * -1,

    or sum the amount from the individual transaction amount.
    holdTransactions.reduce((acc, transaction) => acc + transaction.amount, 0)

    Then, we need to update the current expense report total too.

    App/src/libs/actions/IOU.ts

    Lines 6918 to 6922 in 03ec468

    let total = expenseReport?.total ?? 0;
    const hasHeldExpenses = ReportUtils.hasHeldExpenses(expenseReport?.reportID);
    if (hasHeldExpenses && !full && !!expenseReport?.unheldTotal) {
    total = expenseReport?.unheldTotal;
    }

    App/src/libs/actions/IOU.ts

    Lines 6943 to 6949 in 03ec468

    const optimisticIOUReportData: OnyxUpdate = {
    onyxMethod: Onyx.METHOD.MERGE,
    key: `${ONYXKEYS.COLLECTION.REPORT}${expenseReport?.reportID}`,
    value: {
    ...expenseReport,
    lastMessageText: ReportActionsUtils.getReportActionText(optimisticApprovedReportAction),
    lastMessageHtml: ReportActionsUtils.getReportActionHtml(optimisticApprovedReportAction),

    ...expenseReport,
    total,
    ...,
    

    Solving the optimistic data is currently enough for the LHN to show the correct amount. But if we also want to fix the 2nd issue, then we can connect the expense report in OptionRowLHNData.

    const [iouReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${fullReport?.iouReportID}`);
    

    Then, pass it to SidebarUtils.getOptionData > OptionsListUtils.getLastMessageTextForReport and replace the iouReport here with the new iouReport params.

    } else if (ReportActionUtils.isReportPreviewAction(lastReportAction)) {
    const iouReport = ReportUtils.getReportOrDraftReport(ReportActionUtils.getIOUReportIDFromReportActionPreview(lastReportAction));

    However, there is a BE issue, specifically the ApproveMoneyRequest API where the response returns the previous iouReportID instead of the new one. For example, let's say the current iouReportID is 1 which has 2 held transactions. After approving it, we optimistically move the 2 held transactions to a new report with an ID of 2 then update iouReportID to 2. But the ApproveMoneyRequest response revert the iouReportID back to 1. If we refresh/reopen the chat report, the OpenReport will return the correct iouReportID, 2. So, we need to fix the BE if we want to apply this solution.

    If we don't want to rely on iouReportID, then we can follow the same logic here by taking the last action and extract the iouReportID.

    const iouReport = ReportUtils.getReportOrDraftReport(ReportActionUtils.getIOUReportIDFromReportActionPreview(lastReportAction));

    Fortunately, we already get the iouReportID here,

    const iouReportIDOfLastAction = OptionsListUtils.getIOUReportIDOfLastAction(itemFullReport);

    so we just need to retrieve the report and pass it down to OptionRowLHNData.

    const itemIouReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${iouReportIDOfLastAction}`];
    ...
    
    iouReport={itemIouReport}
    
  4. changed the title [-]Partial paying a report causes the wrong amounts to show in the LHN[/-] [+][Held requests] Partial paying a report causes the wrong amounts to show in the LHN[/+] on Sep 9, 2024
  5. added
    External
    on Sep 9, 2024
  6. changed the title [-][Held requests] Partial paying a report causes the wrong amounts to show in the LHN[/-] [+][$250] [Held requests] Partial paying a report causes the wrong amounts to show in the LHN[/+] on Sep 9, 2024
  7. melvin-bot commented on Sep 9, 2024

    @melvin-bot
  8. added
    Help Wanted
    on Sep 9, 2024
  9. melvin-bot commented on Sep 9, 2024

    @melvin-bot

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

  10. 114 remaining items

  11. bernhardoj commented on Dec 13, 2024

    @bernhardoj
    Contributor

    Yes, I've been paid $250 before.

  12. melvin-bot commented on Dec 16, 2024

    @melvin-bot

    Payment Summary

    Upwork Job

    • Reviewer: @s77rt owed $500 via NewDot
    • Reviewer: @bernhardoj owed $250 via NewDot (already paid $250 in past)

    BugZero Checklist (@RachCHopkins)

    • I have verified the correct assignees and roles are listed above and updated the necessary manual offers
    • I have verified that there are no duplicate or incorrect contracts on Upwork for this job (https://www.upwork.com/ab/applicants/1833144594407206391/hired)
    • I have paid out the Upwork contracts or cancelled the ones that are incorrect
    • I have verified the payment summary above is correct
  13. melvin-bot commented on Dec 16, 2024

    @melvin-bot

    @robertjchen, @s77rt, @RachCHopkins, @bernhardoj Whoops! This issue is 2 days overdue. Let's get this updated quick!

  14. robertjchen commented on Dec 17, 2024

    @robertjchen
    Contributor

    @RachCHopkins Agreed with the increase due to the efforts involved here 👍

  15. s77rt commented on Dec 17, 2024

    @s77rt
    Member

    Thank you! Can you please update the payment summary above so the approver sees the correct values

  16. RachCHopkins commented on Dec 18, 2024

    @RachCHopkins
    Contributor

    @s77rt summary is up to date now!

  17. moved this from Hold for Payment to Done in #expensify-bugson Dec 18, 2024
  18. bernhardoj commented on Dec 18, 2024

    @bernhardoj
    Contributor

    Thanks!

    Requested in ND. (again)

  19. JmillsExpensify commented on Dec 19, 2024

    @JmillsExpensify
    Contributor

    $500 approved for @s77rt

  20. JmillsExpensify commented on Dec 19, 2024

    @JmillsExpensify
    Contributor

    Additional $250 approved for @bernhardoj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentBugDailyExternal

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions