Skip to content

[Due for payment 2025-07-28] [$250] Expense - Negative sign disappears after moving expense with negative sign to self DM #64799

Closed

Description

@mitarachim

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.1.70-6
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from TestRail: Exp
Email or phone of affected tester (no customers): jsidojnsdoisjoid2893@gmail.com
Issue reported by: Applause Internal Team
Device used: Mac 15.5 / Chrome
App Component: Money Requests

Action Performed:

  1. Go to staging.expensify.com
  2. Create a report with two expenses with negative amount.
  3. Log in to staging.new.expensify.com with the same account.
  4. Go to workspace chat.
  5. Open the expense report from Step 2.
  6. Click More > Delete.
  7. Delete the report.
  8. Go to self DM and open one of the unreported expenses.
  9. The unreported expense does not retain its negative sign in the amount.
  10. Open the same unreported expense on Old Dot.
  11. On Old Dot, the same unreported expense retains its negative sign in the amount.
  12. Go back to workspace chat on ND.
  13. Click + > Create report.
  14. Click Add expense > Add unreported expense.
  15. Select any unreported expense from Step 8.
  16. Click Add to report.
  17. Open the expense preview.
  18. The negative sign in the amount resurfaces after adding the unreported expense to a report.

Expected Result:

In Step 9, after moving expense with negative amount to self DM, the negative sign should be retained.

Actual Result:

In Step 9, after moving expense with negative amount to self DM, the negative sign is not retained.
In Step 11, the same unreported expense shows negative sign on Old Dot, but not on New Dot.
In Step 18, after adding the unreported expense to a report, the negative sign reappears.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Bug6868380_1750766455131.20250624_195220.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021938305495880593613
  • Upwork Job ID: 1938305495880593613
  • Last Price Increase: 2025-07-03
  • Automatic offers:
    • thelullabyy | Contributor | 107992969
Issue OwnerCurrent Issue Owner: @clarajones-expensify

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jun 24, 2025
  2. melvin-bot commented on Jun 24, 2025

    @melvin-bot

    Triggered auto assignment to @clarajones-expensify (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. melvin-bot commented on Jun 26, 2025

    @melvin-bot
  4. changed the title [-]Expense - Negative sign disappears after moving expense with negative sign to self DM[/-] [+][$250] Expense - Negative sign disappears after moving expense with negative sign to self DM[/+] on Jun 26, 2025
  5. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Jun 26, 2025
  6. melvin-bot commented on Jun 26, 2025

    @melvin-bot

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

  7. thelullabyy commented on Jun 27, 2025

    @thelullabyy
    Contributor

    Proposal

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

    In Step 9, after moving expense with negative amount to self DM, the negative sign is not retained.
    In Step 11, the same unreported expense shows negative sign on Old Dot, but not on New Dot.
    In Step 18, after adding the unreported expense to a report, the negative sign reappears.

    What is the root cause of that problem?

    The amount of selfDM's transaction has the same pattern with the amount of expense report's transaction

    amount: getTransactionAmount(transaction, !isEmptyObject(report) && isExpenseReport(report)),

    But we always return the positive amount if the transaction is not from expense report or it comes from tracked expense

    function getAmount(transaction: OnyxInputOrEntry<Transaction>, isFromExpenseReport = false, isFromTrackedExpense = false): number {
    // IOU requests cannot have negative values, but they can be stored as negative values, let's return absolute value
    if (!isFromExpenseReport || isFromTrackedExpense) {
    const amount = transaction?.modifiedAmount ?? 0;
    if (amount) {
    return Math.abs(amount);
    }
    return Math.abs(transaction?.amount ?? 0);
    }
    // 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;
    }
    // To avoid -0 being shown, lets only change the sign if the value is other than 0.
    amount = transaction?.amount ?? 0;
    return amount ? -amount : 0;
    }
    /**
    * Return the tax amount field from the transaction.
    */
    function getTaxAmount(transaction: OnyxInputOrEntry<Transaction>, isFromExpenseReport: boolean): number {
    // IOU requests cannot have negative values but they can be stored as negative values, let's return absolute value
    if (!isFromExpenseReport) {
    return Math.abs(transaction?.taxAmount ?? 0);
    }
    // To avoid -0 being shown, lets only change the sign if the value is other than 0.
    const amount = transaction?.taxAmount ?? 0;
    return amount ? -amount : 0;
    }
    /**
    * Return the tax code from the transaction.
    */
    function getTaxCode(transaction: OnyxInputOrEntry<Transaction>): string {
    return transaction?.taxCode ?? '';
    }
    /**
    * Return the posted date from the transaction.
    */
    function getPostedDate(transaction: OnyxInputOrEntry<Transaction>): string {
    return transaction?.posted ?? '';
    }
    /**
    * Return the formatted posted date from the transaction.
    */
    function getFormattedPostedDate(transaction: OnyxInputOrEntry<Transaction>, dateFormat: string = CONST.DATE.FNS_FORMAT_STRING): string {
    const postedDate = getPostedDate(transaction);
    const parsedDate = parse(postedDate, 'yyyyMMdd', new Date());
    if (isValid(parsedDate)) {
    return DateUtils.formatWithUTCTimeZone(format(parsedDate, 'yyyy-MM-dd'), dateFormat);
    }
    return '';
    }
    /**
    * Return the currency field from the transaction, return the modifiedCurrency if present.
    */
    function getCurrency(transaction: OnyxInputOrEntry<Transaction>): string {
    const currency = transaction?.modifiedCurrency ?? '';
    if (currency) {
    return currency;
    }
    return transaction?.currency ?? CONST.CURRENCY.USD;
    }
    /**
    * Return the original currency field from the transaction.
    */
    function getOriginalCurrency(transaction: Transaction): string {
    return transaction?.originalCurrency ?? '';
    }
    /**
    * Return the absolute value of the original amount field from the transaction.
    */
    function getOriginalAmount(transaction: Transaction): number {
    const amount = transaction?.originalAmount ?? 0;
    return Math.abs(amount);
    }
    /**
    * Verify if the transaction is expecting the distance to be calculated on the server
    */
    function isFetchingWaypointsFromServer(transaction: OnyxInputOrEntry<Transaction>): boolean {
    return !!transaction?.pendingFields?.waypoints;
    }

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

    For the tracked expense, we should return the amount with the same pattern as the expense report's transaction. We should update this condition to

    if (!isFromExpenseReport && !isFromTrackedExpense) {
    

    function getAmount(transaction: OnyxInputOrEntry<Transaction>, isFromExpenseReport = false, isFromTrackedExpense = false): number {
    // IOU requests cannot have negative values, but they can be stored as negative values, let's return absolute value
    if (!isFromExpenseReport || isFromTrackedExpense) {
    const amount = transaction?.modifiedAmount ?? 0;
    if (amount) {
    return Math.abs(amount);
    }
    return Math.abs(transaction?.amount ?? 0);
    }
    // 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;
    }
    // To avoid -0 being shown, lets only change the sign if the value is other than 0.
    amount = transaction?.amount ?? 0;
    return amount ? -amount : 0;
    }
    /**
    * Return the tax amount field from the transaction.
    */
    function getTaxAmount(transaction: OnyxInputOrEntry<Transaction>, isFromExpenseReport: boolean): number {
    // IOU requests cannot have negative values but they can be stored as negative values, let's return absolute value
    if (!isFromExpenseReport) {
    return Math.abs(transaction?.taxAmount ?? 0);
    }
    // To avoid -0 being shown, lets only change the sign if the value is other than 0.
    const amount = transaction?.taxAmount ?? 0;
    return amount ? -amount : 0;
    }
    /**
    * Return the tax code from the transaction.
    */
    function getTaxCode(transaction: OnyxInputOrEntry<Transaction>): string {
    return transaction?.taxCode ?? '';
    }
    /**
    * Return the posted date from the transaction.
    */
    function getPostedDate(transaction: OnyxInputOrEntry<Transaction>): string {
    return transaction?.posted ?? '';
    }
    /**
    * Return the formatted posted date from the transaction.
    */
    function getFormattedPostedDate(transaction: OnyxInputOrEntry<Transaction>, dateFormat: string = CONST.DATE.FNS_FORMAT_STRING): string {
    const postedDate = getPostedDate(transaction);
    const parsedDate = parse(postedDate, 'yyyyMMdd', new Date());
    if (isValid(parsedDate)) {
    return DateUtils.formatWithUTCTimeZone(format(parsedDate, 'yyyy-MM-dd'), dateFormat);
    }
    return '';
    }
    /**
    * Return the currency field from the transaction, return the modifiedCurrency if present.
    */
    function getCurrency(transaction: OnyxInputOrEntry<Transaction>): string {
    const currency = transaction?.modifiedCurrency ?? '';
    if (currency) {
    return currency;
    }
    return transaction?.currency ?? CONST.CURRENCY.USD;
    }
    /**
    * Return the original currency field from the transaction.
    */
    function getOriginalCurrency(transaction: Transaction): string {
    return transaction?.originalCurrency ?? '';
    }
    /**
    * Return the absolute value of the original amount field from the transaction.
    */
    function getOriginalAmount(transaction: Transaction): number {
    const amount = transaction?.originalAmount ?? 0;
    return Math.abs(amount);
    }
    /**
    * Verify if the transaction is expecting the distance to be calculated on the server
    */
    function isFetchingWaypointsFromServer(transaction: OnyxInputOrEntry<Transaction>): boolean {
    return !!transaction?.pendingFields?.waypoints;
    }

    Because we can check the unreported transaction via transaction.reportID, I suggest we can remove isFromTrackedExpense param and check this internally in getAmount function

    const isFromTrackedExpense = transaction?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID;
    

    If we still want to keep this parameter, we should pass this parameter when we get the amount here and other places that we want to get the real amount instead of a positive amount

    amount: getTransactionAmount(transaction, !isEmptyObject(report) && isExpenseReport(report), transaction?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID), 
    

    amount: getTransactionAmount(transaction, !isEmptyObject(report) && isExpenseReport(report)),

    const isUnReportedExpense = transaction?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID;
    updatedTransaction.modifiedAmount = isFromExpenseReport || isUnReportedExpense ? -transactionChanges.amount : transactionChanges.amount;
    

    if (Object.hasOwn(transactionChanges, 'amount') && typeof transactionChanges.amount === 'number') {
    updatedTransaction.modifiedAmount = isFromExpenseReport ? -transactionChanges.amount : transactionChanges.amount;
    shouldStopSmartscan = true;
    }
    if (Object.hasOwn(transactionChanges, 'currency')) {

    const updatedAmount = isFromExpenseReport || isUnReportedExpense ? -amount : amount; 
    

    const updatedAmount = isFromExpenseReport ? -amount : amount;

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    Update getAmount unit test to verify that this function returns the correct amount for unreported transaction.

    What alternative solutions did you explore? (Optional)

    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  8. ikevin127 commented on Jun 28, 2025

    @ikevin127
    Contributor

    Thanks for the proposal !

    Looking at PR #38709 which introduced this logic:

         // IOU requests cannot have negative values, but they can be stored as negative values, let's return absolute value 
         if (!isFromExpenseReport || isFromTrackedExpense) { 

    and from the PR description I wasn't able to find anything related to our issue, so I asked on the PR what was the purpose of adding || isFromTrackedExpense because it's causing our issue, asked whether it's expected behaviour or we can change that logic without breaking things their PR implemented.

  9. 30 remaining items

  10. melvin-bot commented on Jul 21, 2025

    @melvin-bot

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

  11. melvin-bot commented on Jul 21, 2025

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.1.83-5 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 2025-07-28. 🎊

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

  12. melvin-bot commented on Jul 21, 2025

    @melvin-bot

    @youssef-lr @clarajones-expensify @ikevin127 / @thelullabyy 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]

  13. clarajones-expensify commented on Jul 21, 2025

    @clarajones-expensify
    Contributor

    BugZero Checklist:

    • [Contributor] Classify the bug:
    Bug classification

    Source of bug:

    • 1a. Result of the original design (eg. a case wasn't considered)
    • 1b. Mistake during implementation
    • 1c. Backend bug
    • 1z. Other:

    Where bug was reported:

    • 2a. Reported on production (eg. bug slipped through the normal regression and PR testing process on staging)
    • 2b. Reported on staging (eg. found during regression or PR testing)
    • 2d. Reported on a PR
    • 2z. Other:

    Who reported the bug:

    • 3a. Expensify user
    • 3b. Expensify employee
    • 3c. Contributor
    • 3d. QA
    • 3z. Other:
    • [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:

    • [Contributor] 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:

    • [Contributor] 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.

    Regression Test Proposal Template
    • [BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.

      Link to issue:

    Regression Test Proposal

    Precondition:

    Test:

    Do we agree 👍 or 👎

  14. clarajones-expensify commented on Jul 21, 2025

    @clarajones-expensify
    Contributor

    Hi @ikevin127 ! Would you fill out the above checklist? Thank you

  15. ikevin127 commented on Jul 22, 2025

    @ikevin127
    Contributor

    BugZero Checklist:

    • [Contributor] Classify the bug:
    Bug classification

    Source of bug:

    • 1a. Result of the original design (eg. a case wasn't considered)
    • 1b. Mistake during implementation
    • 1c. Backend bug
    • 1z. Other:

    Where bug was reported:

    • 2a. Reported on production (eg. bug slipped through the normal regression and PR testing process on staging)
    • 2b. Reported on staging (eg. found during regression or PR testing)
    • 2d. Reported on a PR
    • 2z. Other:

    Who reported the bug:

    • 3a. Expensify user
    • 3b. Expensify employee
    • 3c. Contributor
    • 3d. QA
    • 3z. Other:
    • [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: No specific offending PR, this became an issue because over time the app evolved and new features were added (e.g. moving deleted report expenses to selfDM).

    • [Contributor] 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

    • [Contributor] 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.

    • [BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.

      Link to issue:

    Regression Test Proposal

    1. Go to (OD) staging.expensify.com.
    2. Create a report with two expenses with negative amount.
    3. Log in to (ND) staging.new.expensify.com with the same account.
    4. Go to workspace chat.
    5. Open the expense report from Step 2.
    6. Click More > Delete.
    7. Delete the report.
    8. Go to selfDM and open one of the unreported expenses.
    9. Verify that the unreported expense does retain its negative sign in the amount.
    10. Open the same unreported expense on OD.
    11. On Old Dot, the same unreported expense retains its negative sign in the amount.
    12. Go back to workspace chat on ND.
    13. Click + > Create report.
    14. Click Add expense > Add unreported expense.
    15. Select any unreported expense from Step 8.
    16. Click Add to report.
    17. Open the expense preview.
    18. Verify that the negative sign in the amount is persisted after adding the unreported expense to a workspace report.

    Do we agree 👍 or 👎.

  16. clarajones-expensify commented on Jul 28, 2025

    @clarajones-expensify
    Contributor

    payment summary

    C+: @ikevin127 requires $250 through NewDot Manual Requests
    Contributor: @thelullabyy paid $250 via upwork job

  17. trjExpensify commented on Jul 29, 2025

    @trjExpensify
    Contributor

    Approved $250 for @ikevin127.

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

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions