Skip to content

Distance - Duplicated expense amount is the original amount instead of the edited amount #84194

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: 9.3.31-0
Reproducible in staging?: Yes
Reproducible in production?: N/A - new feature, doesn't exist in prod
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #82005
Email or phone of affected tester (no customers): jsodijnsoinjdojoijsoid@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Mac 26.2 / Chrome
App Component: Money Requests

Action Performed:

  1. Go to staging.new.expensify.com
  2. Go to workspace chat.
  3. Create a manual distance expense.
  4. Open the distance expense.
  5. Click Amount.
  6. Edit the amount and save it.
  7. Click More > Duplicate expense.
  8. Open the duplicated expense.

Expected Result:

Duplicated expense amount will be the edited amount (similar to OD).

Actual Result:

Duplicated expense amount is the original amount instead of the edited amount.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7093975_1772651918565.11.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @jjcoffee

Activity

  1. added
    DeployBlockerCash
    Daily
    Bug
    on Mar 4, 2026
  2. melvin-bot commented on Mar 4, 2026

    @melvin-bot

    You have been assigned to this deploy blocker because you recently merged this PR: #82005

  3. melvin-bot commented on Mar 4, 2026

    @melvin-bot

    💬 A slack conversation has been started in #expensify-open-source

  4. melvin-bot commented on Mar 4, 2026

    @melvin-bot

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

  5. github-actions commented on Mar 4, 2026

    @github-actions
    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.
  6. MelvinBot commented on Mar 4, 2026

    @MelvinBot
    Contributor

    Proposal

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

    When a user edits the amount on a distance expense and then duplicates it, the duplicated expense shows the original rate-calculated amount instead of the user's manually edited amount.

    What is the root cause of that problem?

    PR #82005 re-enabled distance expense duplication by removing a blanket block and routing duplicated distance expenses through createDistanceRequest. The problem has two parts:

    1. modifiedAmount is explicitly cleared during duplication at Duplicate.ts:573 — when a user edits an expense amount, the edit is stored in modifiedAmount, but the duplication code sets modifiedAmount: undefined.

    2. The backend recalculates the amount from scratch — CreateDistanceRequestParams (definition) does not include an amount field. When the duplicated distance request is created, the backend receives only waypoints, distance, and customUnitRateID, then calculates amount = distance * rate, producing the original amount and overwriting the correct optimistic value.

    The frontend actually computes the correct edited amount optimistically (via getTransactionDetails → getAmount which respects modifiedAmount), but the backend response overwrites it with the recalculated original amount.

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

    When duplicating a distance expense whose amount was manually edited, preserve the modifiedAmount on the duplicated transaction instead of clearing it to undefined. Specifically:

    • In Duplicate.ts, when building transactionParams for duplication, check if the original transaction has a valid modifiedAmount (using hasValidModifiedAmount from TransactionUtils). If it does, pass the original modifiedAmount value through instead of setting it to undefined.
    • This way, even though the backend recalculates the base amount from distance/rate, the modifiedAmount field will be preserved on the duplicated transaction, and getAmount() (which already prioritizes modifiedAmount over amount) will display the correct edited value.

    What alternative solutions did you explore? (Optional)

    • Adding an amount field to CreateDistanceRequestParams so the backend uses the provided amount instead of recalculating. This would require backend changes and is more invasive.
    • Skipping waypoint processing for duplicated distance expenses with edited amounts (not sending the receipt as OPEN state). This could break the route display on the duplicate.
    Detailed Investigation

    Evidence Chain

    File Line(s) Significance
    Duplicate.ts 573 modifiedAmount: undefined — clears the edited amount
    Duplicate.ts 649-676 Distance duplication routes through createDistanceRequest
    CreateDistanceRequestParams.ts 3-34 No amount field — backend recalculates from rate/distance
    IOU/index.ts 8368-8374 Receipt set to OPEN for map-based distance, triggering backend recalc
    IOU/index.ts 3538 pendingFields.waypoints = ADD triggers backend route/amount calculation
    TransactionUtils/index.ts 945-953 getAmount() correctly returns edited amount from modifiedAmount

    Data Flow

    1. User has distance expense: amount=-5000, modifiedAmount=-7500 (edited from $50.00 to $75.00)
    2. User duplicates → duplicateExpenseTransaction() called
    3. getTransactionDetails() resolves amount to 7500 (correctly uses modifiedAmount)
    4. transactionParams built with amount=7500, modifiedAmount=undefined (cleared at line 573)
    5. createDistanceRequest() called with original waypoints
    6. Optimistic transaction has correct amount (-7500) temporarily
    7. CreateDistanceRequestParams sent to backend without amount — only waypoints, distance, customUnitRateID
    8. Backend recalculates: rate × distance = $50.00 (original amount)
    9. Backend response overwrites optimistic amount → UI shows $50.00 instead of $75.00

    Confidence: High

    Both independent code investigations converge on the same root cause with specific file:line evidence.


    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, or @MelvinBot <your feedback> to refine this analysis.

  7. hoangzinh commented on Mar 5, 2026

    @hoangzinh
    Contributor

    Adding an amount field to CreateDistanceRequestParams so the backend uses the provided amount instead of recalculating. This would require backend changes and is more invasive.

    I think we should go with this alternative solution, or another alternative is adding modifiedAmount field to CreateDistanceRequestParams

  8. hoangzinh commented on Mar 5, 2026

    @hoangzinh
    Contributor
  9. jjcoffee commented on Mar 5, 2026

    @jjcoffee
    Contributor

    Hmm, wasn't aware you could edit the amount for a distance expense. It seems a bit counter-intuitive - what are the Distance and Rate fields for if you just enter a manual value? 😄 I don't know how often manually editing the amount is done, but I can see an argument for this not being a blocker.

    This way, even though the backend recalculates the base amount from distance/rate, the modifiedAmount field will be preserved on the duplicated transaction

    I'm pretty sure modifiedAmount wouldn't be preserved by the BE. We explicitly clear modifiedAmount because for the duplicated transaction it's meant to act as a fresh transaction (so the "modified" state shouldn't be preserved).

    I think the BE solution is the only one that makes sense here. I'm guessing the Transaction_Duplicate command for OD handles this all in the BE. cc @JS00001

  10. hoangzinh commented on Mar 5, 2026

    @hoangzinh
    Contributor

    I can see an argument for this not being a blocker

    Agreed

  11. JS00001 commented on Mar 5, 2026

    @JS00001
    Contributor

    Agreed NAB, lets fix this though please

  12. added
    Daily
    and removed
    DeployBlockerCash
    Hourly
    on Mar 5, 2026
  13. JS00001 commented on Mar 5, 2026

    @JS00001
    Contributor

    Closing out in favor of #84280, so there's less noise

  14. added
    Reviewing
    Weekly
    and removed
    Daily
    on Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugEngineeringReviewingWeekly

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions