Skip to content

[$500] Expense - Preview shows 0.00 when receipt currency is different from workspace currency #34064

Closed

Description

@lanitochka17

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.22-0
Reproducible in staging?: Y
Reproducible in production?: Y
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. Go to workspace chat
  2. Create a scan request with a receipt which has different currency from the workspace default currency
  3. Stay in the workspace chat and wait until the scanning is complete

Expected Result:

The expense preview shows the correct amount when the scanning is complete

Actual Result:

When the scanning is complete, the expense preview shows 0.00, while LHN preview has no issue displaying the amount

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

Bug6333473_1704485173645!E_receipt_

Bug6333473_1704485173648.20240105_102725__1_.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01487b67fb3f39c5a0
  • Upwork Job ID: 1743372007763001344
  • Last Price Increase: 2024-01-05
  • Automatic offers:
    • cubuspl42 | Reviewer | 28106113
    • bernhardoj | Contributor | 28106114

Activity

  1. added
    ExternalAdded to denote the issue can be worked on by a contributor
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jan 5, 2024
  2. changed the title [-]Expense - Preview shows 0.00 when receipt currency is different from workspace currency[/-] [+][$500] Expense - Preview shows 0.00 when receipt currency is different from workspace currency[/+] on Jan 5, 2024
  3. melvin-bot commented on Jan 5, 2024

    @melvin-bot
  4. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Jan 5, 2024
  5. melvin-bot commented on Jan 5, 2024

    @melvin-bot

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

  6. melvin-bot commented on Jan 5, 2024

    @melvin-bot

    Bug0 Triage Checklist (Main S/O)

    • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
    • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
      • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
    • This bug is reproducible using the reproduction steps in the OP. S/O
      • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
      • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
    • This issue is filled out as thoroughly and clearly as possible
      • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
    • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync
  7. melvin-bot commented on Jan 5, 2024

    @melvin-bot

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

  8. Tony-MK commented on Jan 6, 2024

    @Tony-MK
    Contributor

    Proposal

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

    What is the root cause of that problem?

    The getDisplayAmount in the ReportPreview is returning the value '0.00' because totalDisplaySpend is zero and the REPORTPREVIEW action message does not update the message when the receipt has completed scanning.
    However, the OptionRow and MoneyReportHeader components will be updated.

    const actionMessage = lodashGet(props.action, ['message', 0, 'text'], '');
    const splits = actionMessage.split(' ');
    for (let i = 0; i < splits.length; i++) {
    if (/\d/.test(splits[i])) {
    displayAmount = splits[i];
    }
    }
    return displayAmount;

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

    The best option is to fix this at the backend, but frontend solution can also fix the issue.

    Since the MoneyReportHeader components update immediately, we can use the ReportUtils.getReportName function if the props.action.message is not updated yet in the REPORTPREVIEW to update the displayAmount.

    We should create a function to simplify the code above called getAmountFromMessage.

    function getAmountFromMessage(message){
     let displayAmount = '';
     const splits = actionMessage.split(' ');
      for (let i = 0; i < splits.length; i++) {
        if (/\d/.test(splits[i])) {
            displayAmount = splits[i];
        }
      }
     return displayAmount
    }
    

    In the getDisplayAmount function, create a condition to return the appropriate amount to display.

    const amountMessage = getAmountFromMessage(lodashGet(props.action, ['message', 0, 'text'], ''));
    return amountMessage && amountMessage !== '0.00' ? amountMessage : getAmountFromMessage(ReportUtils.getReportName(props.chatReport))
    

    Optional: We should probably optimize and simplify the getAmountFromMessage function further than is currently implemented in main.

  9. aim-salam commented on Jan 6, 2024

    @aim-salam

    .

  10. bernhardoj commented on Jan 6, 2024

    @bernhardoj
    Contributor

    Proposal

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

    When we do a scan request, the amount preview shows 0. This happens even if we have the same currency as workspace.

    What is the root cause of that problem?

    The amount will show based on getDisplayAmount function.

    const getDisplayAmount = () => {
    if (hasPendingWaypoints) {
    return props.translate('common.tbd');
    }
    if (totalDisplaySpend) {
    return CurrencyUtils.convertToDisplayString(totalDisplaySpend, props.iouReport.currency);
    }
    if (isScanning) {
    return props.translate('iou.receiptScanning');
    }
    if (hasOnlyDistanceRequests) {
    return props.translate('common.tbd');
    }
    // If iouReport is not available, get amount from the action message (Ex: "Domain20821's Workspace owes $33.00" or "paid ₫60" or "paid -₫60 elsewhere")
    let displayAmount = '';
    const actionMessage = lodashGet(props.action, ['message', 0, 'text'], '');
    const splits = actionMessage.split(' ');
    for (let i = 0; i < splits.length; i++) {
    if (/\d/.test(splits[i])) {
    displayAmount = splits[i];
    }
    }
    return displayAmount;
    };

    It will show the amount if totalDisplaySpend > 0, otherwise, it will take the amount from the report action message. However, the report action message amount is 0.
    image

    And the totalDisplaySpend is 0 too. When we reopen the report or open the associated IOU report, we will get the correct amount.

    I think the report action message amount is 0 is already obvious that this is a BE problem. But why totalDisplaySpend is 0? We get the totalDisplaySpend from getMoneyRequestSpendBreakdown. It will return a non 0 totalDisplaySpend ONLY if nonReimbursableSpend + totalSpend is not 0.

    App/src/libs/ReportUtils.ts

    Lines 1728 to 1742 in 0c351a4

    if (nonReimbursableSpend + totalSpend !== 0) {
    // There is a possibility that if the Expense report has a negative total.
    // This is because there are instances where you can get a credit back on your card,
    // or you enter a negative expense to “offset” future expenses
    nonReimbursableSpend = isExpenseReport(moneyRequestReport) ? nonReimbursableSpend * -1 : Math.abs(nonReimbursableSpend);
    totalSpend = isExpenseReport(moneyRequestReport) ? totalSpend * -1 : Math.abs(totalSpend);
    const totalDisplaySpend = totalSpend;
    const reimbursableSpend = totalDisplaySpend - nonReimbursableSpend;
    return {
    nonReimbursableSpend,
    reimbursableSpend,
    totalDisplaySpend,
    };

    If we check the amount of both nonReimbursableSpend and totalSpend, we can see that the amount cancel out each other.
    image

    Thus, we return a 0 totalDisplaySpend.

    App/src/libs/ReportUtils.ts

    Lines 1745 to 1749 in 0c351a4

    return {
    nonReimbursableSpend: 0,
    reimbursableSpend: 0,
    totalDisplaySpend: 0,
    };

    But if we reopen the report or open the IOU report, the BE will returns a 0 nonReimbursableSpend.
    image

    But why LHN's last message show the correct amount?
    image

    It's because the last message doesn't use getMoneyRequestSpendBreakdown logic and just gets the money request total amount.

    const totalAmount = getMoneyRequestReimbursableTotal(report);

    App/src/libs/ReportUtils.ts

    Lines 1693 to 1713 in 0c351a4

    function getMoneyRequestReimbursableTotal(report: OnyxEntry<Report>, allReportsDict: OnyxCollection<Report> = null): number {
    const allAvailableReports = allReportsDict ?? allReports;
    let moneyRequestReport: OnyxEntry<Report> | undefined;
    if (isMoneyRequestReport(report)) {
    moneyRequestReport = report;
    }
    if (allAvailableReports && report?.iouReportID) {
    moneyRequestReport = allAvailableReports[`${ONYXKEYS.COLLECTION.REPORT}${report.iouReportID}`];
    }
    if (moneyRequestReport) {
    const total = moneyRequestReport?.total ?? 0;
    if (total !== 0) {
    // There is a possibility that if the Expense report has a negative total.
    // This is because there are instances where you can get a credit back on your card,
    // or you enter a negative expense to “offset” future expenses
    return isExpenseReport(moneyRequestReport) ? total * -1 : Math.abs(total);
    }
    }
    return 0;
    }

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

    If we look at this PR commit, we previously show the total amount.

    I think ideally we should fix this on the BE, but in case we want to have the same behavior as LHN's last message, we can fallback to the amount total

    const total = ReportUtils.getMoneyRequestReimbursableTotal(props.iouReport);
    
    if (totalDisplaySpend || total) {
        return CurrencyUtils.convertToDisplayString(totalDisplaySpend || total, props.iouReport.currency);
    }
    (or do the fallback inside getMoneyRequestSpendBreakdown by replacing 0 with getMoneyRequestReimbursableTotal)
    

    But with this fallback, we can potentially show the wrong amount when the totalDisplaySpend is indeed 0 (that is the case where both nonReimbursableSpend and totalSpend really cancel out each other, not because of a bug). In that case, perhaps we can update the last message logic to use getMoneyRequestSpendBreakdown and get the totalDisplaySpend so we can have consistent behavior.

  11. 35 remaining items

  12. bernhardoj commented on Jan 23, 2024

    @bernhardoj
    Contributor

    Could you sum up what the issue is after the backend fixes? Are we left with some technical debt / duplicated frontend utils that cannot be directly expressed as a user-perceived scenario, or what?

    After the BE is fixed, we actually don't need any FE changes for the OP repro steps, but I'm under the assumption that we want to update the last message and preview amount to use the same logic (for consistency) with the fact that the last message shows a different amount when the BE issue persists.
    image

    BE and FE issues are basically different, with the FE issue only noticeable when the BE issue persists.

  13. jakub-trzebiatowski commented on Jan 23, 2024

    @jakub-trzebiatowski
    Contributor

    @tgolen @luacmartins However I always personally favor all efforts to make the code cleaner, more consistent and better in general, we'd need an approval to go forward here.

    The fact is that the issue, as described, is not reproducible.

  14. luacmartins commented on Jan 23, 2024

    @luacmartins
    Contributor

    @bernhardoj I'm removing getMoneyRequestReimbursableTotal in this PR, so I think we'd solve the consistency issue there.

  15. luacmartins commented on Jan 23, 2024

    @luacmartins
    Contributor

    I think we can close this issue, since it's no longer reproducible.

  16. tgolen commented on Jan 23, 2024

    @tgolen
    Contributor

    OK, looks like #34909 should cover the inconsistent frontend logic, so I agree with closing this.

  17. jakub-trzebiatowski commented on Jan 24, 2024

    @jakub-trzebiatowski
    Contributor

    @luacmartins @tgolen Please confirm whether you consider @bernhardoj not entitled for 25%/50% compensation. He investigated the issue and pointed the exact place in the backend which needs fixing.

  18. tgolen commented on Jan 24, 2024

    @tgolen
    Contributor

    Thank you for asking. I agree @bernhardoj should be partially compensated at 50%, so reopening this. @miljakljajic can you assist with this payment, please?

  19. reopened this on Jan 24, 2024
  20. melvin-bot commented on Feb 19, 2024

    @melvin-bot

    This issue has not been updated in over 15 days. @tgolen, @cubuspl42, @luacmartins, @miljakljajic, @bernhardoj eroding to Monthly issue.

    P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

  21. miljakljajic commented on Mar 22, 2024

    @miljakljajic
    Contributor

    Paying now - missed this one

  22. miljakljajic commented on Mar 22, 2024

    @miljakljajic
    Contributor

    Paid!

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

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorMonthlyKSv2ReviewingHas a PR in review

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions