Skip to content

[Odometer] [$250] Odometer distance page shows wrong amount after changing distance unit #82650

Closed

Description

@jponikarchuk

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.20-2
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #77292
Email or phone of affected tester (no customers): applausetester+ihbuiivyw@applause.expensifail.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:

Precondition:

  • Log in with Expensifail account.
  • Distance rates are enabled.
  • Workspace has at least two different rates.
  1. Go to staging.new.expensify.com
  2. Go to workspace chat.
  3. Click + > Track distance > Odometer.
  4. Create a 400 mi odometer expense with 100mi start reading and 500mile end reading.
  5. Go to workspace settings > Distance rates.
  6. Click Settings > Unit.
  7. Change the unit to Kilometers (or Miles if the current unit is Kilometers).
  8. Go to workspace chat and open odometer expense.
  9. Click Rate.
  10. Select another rate.
    → Distance field shows 643.74 kilometers.
  11. Click Distance rate.

Expected Result:

  • Start reading and End reading should convert to kilometers.
  • Total distance should also convert to kilometers, which should be 643.74 kilometers (from Step 10).

Actual Result:

  • Start reading and End reading does not convert to kilometers.
  • Total distance does not correctly convert to kilometers. It shows 400 km, while Distance field in expense details page shows 643.74 kilometers (from Step 10).

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

1.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @shubham1206agra
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022026440401498482120
  • Upwork Job ID: 2026440401498482120
  • Last Price Increase: 2026-02-24

Activity

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

    @melvin-bot

    Triggered auto assignment to @laurenreidexpensify (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. MelvinBot commented on Feb 24, 2026

    @MelvinBot
    Contributor

    Proposal

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

    After creating an odometer expense in miles (e.g., start=100, end=500, total=400 mi) and then changing the workspace distance unit to kilometers and selecting a new rate, the odometer distance page shows incorrect values: the start/end readings remain unconverted (100, 500) and the total distance shows "400 km" instead of the correct "643.74 km". Meanwhile, the expense detail view (Distance field) correctly shows 643.74 km.

    What is the root cause of that problem?

    When the user selects a new rate with a different unit, the code in TransactionUtils/index.ts:769-772 correctly converts transaction.comment.customUnit.quantity (400 mi → 643.74 km) and updates distanceUnit to 'km'. However, it does not convert transaction.comment.odometerStart or transaction.comment.odometerEnd — these raw values (100, 500) remain unchanged.

    The odometer page (IOURequestStepDistanceOdometer.tsx) displays these values with no conversion:

    • Start/end readings (lines 195-217): Loaded directly from odometerStart/odometerEnd via .toString() with no conversion applied.
    • Total distance (lines 223-232): Computed as endReading - startReading (a raw subtraction), not read from the properly-converted quantity field.
    • Unit label (line 132): Correctly resolved to 'km' from the current rate.

    The result is the raw mile values (100, 500, 400) displayed with the "km" label — producing "400 km" instead of "643.74 km".

    In contrast, MoneyRequestView.tsx:419-427 reads the authoritative quantity field (which was properly converted to 643.74) through the getDistanceInMeters → getDistanceForDisplay pipeline, so it shows "643.74 km" correctly.

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

    Two changes are needed:

    1. TransactionUtils/index.ts (lines 769-773): When the rate change triggers a unit conversion, also convert odometerStart and odometerEnd by the same conversion factor. After the existing quantity conversion block, add logic to convert both odometer readings:

      • If converting mi → km, multiply odometerStart and odometerEnd by MILES_TO_KILOMETERS
      • If converting km → mi, multiply by KILOMETERS_TO_MILES
      • Set the converted values on the updatedTransaction via lodashSet
    2. IOURequestStepDistanceOdometer.tsx (lines 223-232): As a safety measure for the display, when in editing mode (isEditing), the totalDistance should prefer reading from transaction.comment.customUnit.quantity (the authoritative converted value) rather than recalculating from the raw odometer readings. This ensures the display is consistent with MoneyRequestView even if the odometer readings haven't been converted yet.

    What alternative solutions did you explore? (Optional)

    • Only fix the display (not the data): We could make the odometer page read quantity for the total distance and apply a conversion factor to the displayed start/end readings without persisting the converted values. However, this would leave the stored data inconsistent — odometerStart/odometerEnd would be in miles while quantity and distanceUnit are in km. This inconsistency would cause issues if the readings are used elsewhere or if the user re-edits and saves (the raw mile values would be saved back as km values).

    • Only fix TransactionUtils: Converting the stored odometer readings on rate change would fix the issue for the common flow, but without the safety measure in the display component, any edge case where the conversion doesn't fire (e.g., if the backend updates quantity but the client doesn't re-trigger the conversion) would still show stale values.

    Relevant Code

    • App/src/libs/TransactionUtils/index.ts:757-773 — Rate change conversion logic (converts quantity but not odometer readings)
    • App/src/pages/iou/request/step/IOURequestStepDistanceOdometer.tsx:195-232 — Odometer page display (loads raw readings, computes raw subtraction)
    • App/src/pages/iou/request/step/IOURequestStepDistanceOdometer.tsx:132 — Unit resolution
    • App/src/components/ReportActionItem/MoneyRequestView.tsx:419-427 — Expense detail view (correct conversion pipeline)
    • App/src/pages/iou/request/step/IOURequestStepDistanceManual.tsx:112-118 — Manual distance page (correct conversion pattern to reference)

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

  4. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Feb 24, 2026
  5. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Feb 24, 2026
  6. melvin-bot commented on Feb 24, 2026

    @melvin-bot

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

  7. changed the title [-]Odometer - Odometer distance page shows wrong amount after changing distance unit[/-] [+][$250] Odometer - Odometer distance page shows wrong amount after changing distance unit[/+] on Feb 24, 2026
  8. melvin-bot commented on Feb 24, 2026

    @melvin-bot
  9. shubham1206agra commented on Feb 25, 2026

    @shubham1206agra
    Contributor

    @MelvinBot implement this

  10. 31 remaining items

  11. DylanDylann commented on Mar 3, 2026

    @DylanDylann
    Contributor

    @Julesssss Do you want to update the flow to match the oldDot behavior?

  12. Julesssss commented on Mar 3, 2026

    @Julesssss
    Contributor

    This looks incorrect to me. I can still change the rate of the created expense

    Oh you're right. I see that now. Perhaps it was due to my report policy 😕

    @Julesssss Do you want to update the flow to match the oldDot behavior?

    So yeah, lets keep things as simple as possible and align with classic.

  13. DylanDylann commented on Mar 4, 2026

    @DylanDylann
    Contributor

    @MelvinBot We need to update the expectation. When the user changes the rate unit, we will not convert the distance to the new unit automatically. The distance number is still retained and only changes the unit of distance

  14. MelvinBot commented on Mar 4, 2026

    @MelvinBot
    Contributor

    Updated Proposal (revised per feedback from DylanDylann and Julesssss)

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

    After creating an odometer expense in miles (e.g., start=100, end=500, total=400 mi) and then changing the workspace distance unit to kilometers and selecting a new rate, the odometer distance page and the expense detail view show inconsistent values. The expense detail view converts the distance (showing 643.74 km) while the odometer page shows the raw number with the new unit label (400 km).

    Per the updated expectation aligned with OldDot behavior: when the user changes the rate to one with a different unit, the distance number should NOT be converted — it is retained as-is and only the unit label changes. So 400 mi becomes 400 km (not 643.74 km).

    What is the root cause of that problem?

    There are two places where distance is currently converted when the rate unit changes, which contradicts the desired OldDot behavior:

    1. TransactionUtils/index.ts:766-770 (getUpdatedTransaction): When customUnitRateID changes and the new rate has a different unit, this code converts quantity by multiplying with MILES_TO_KILOMETERS or KILOMETERS_TO_MILES. This causes the expense detail view to show 643.74 km instead of keeping the raw 400.

    2. IOU/index.ts:1805-1806 (setMoneyRequestDistanceRate): Same conversion for draft transactions — converts quantity via convertDistanceUnit(getDistanceInMeters(...), newDistanceUnit) when the rate unit differs.

    Additionally, the amount recalculation at TransactionUtils/index.ts:780 uses the OLD unit to interpret the quantity (getDistanceInMeters(transaction, oldMileageRate?.unit)), which produces the correct physical distance in meters. Under the new expectation, the raw quantity should be treated as being in the NEW unit for amount calculation purposes.

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

    Three changes to stop converting the distance number on rate change:

    1. TransactionUtils/index.ts:766-770: Remove the distance conversion block. Keep the distanceUnit update (line 763) but delete the if (existingDistanceUnit && newDistanceUnit !== existingDistanceUnit) block that multiplies quantity by a conversion factor.

    2. TransactionUtils/index.ts:780: Update the amount recalculation to use the new unit instead of the old unit, since the raw quantity is now treated as being in the new unit:

      • Change getDistanceInMeters(transaction, oldMileageRate?.unit) to getDistanceInMeters(updatedTransaction, unit) so the unchanged quantity (400) is interpreted as the new unit (km) for amount calculation.
      • This ensures amount = 400 * newRate (matching OldDot behavior), not 643.74 * newRate.
    3. IOU/index.ts:1805-1807: Remove the distance conversion for draft transactions. Keep the distanceUnit update but remove the newDistance calculation and its application to quantity. The Onyx merge should update customUnitRateID and distanceUnit but NOT quantity.

    No changes needed to IOURequestStepDistanceOdometer.tsx — it already displays the raw odometer readings and raw total distance, which is now the correct behavior.

    What alternative solutions did you explore? (Optional)

    • Only removing the conversion in getUpdatedTransaction: This would fix existing transactions but leave draft transactions still converting in setMoneyRequestDistanceRate. Both paths need to be updated for consistency.
    • Converting odometer readings along with quantity (original proposal): This was the previous approach, now superseded by the product decision to align with OldDot behavior where the number stays the same.

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

  15. DylanDylann commented on Mar 5, 2026

    @DylanDylann
    Contributor

    @MelvinBot implement this (and close the previous PR)

  16. MelvinBot commented on Mar 5, 2026

    @MelvinBot
    Contributor

    🤖 Draft PR created: #84253
    Please mark it as "Ready for review" when it is ready for review.

    I created this PR from an upstream branch since I don't have push access to your fork.

    To take ownership of this branch and be able to push updates, run:

    git remote add upstream https://github.com/Expensify/App.git
    git fetch upstream claude-stopOdometerDistanceConversionOnRateChange
    git checkout -b claude-stopOdometerDistanceConversionOnRateChange upstream/claude-stopOdometerDistanceConversionOnRateChange
    git push -u origin claude-stopOdometerDistanceConversionOnRateChange
    

    Then you can close this PR and open a new one from your fork.

  17. DylanDylann commented on Mar 5, 2026

    @DylanDylann
    Contributor

    @Julesssss We likely need an update from the BE side (Command: UpdateMoneyRequestDistanceRate).
    When updating the rate (with a new unit) for an odometer request, we should only update the unit and not convert the distance (transaction.comment.customUnit.quantity). The transaction.comment.customUnit.quantity should always remain odometerEnd - odometerStart.

    As a workaround on the FE, we could calculate the distance using odometerEnd - odometerStart instead of relying on the quantity field. However, I think updating this in the BE would be the better long-term approach.

    Image
  18. DylanDylann commented on Mar 5, 2026

    @DylanDylann
    Contributor

    The FE PR is complete. Waiting for the BE update to move forward

  19. Julesssss commented on Mar 6, 2026

    @Julesssss
    Contributor

    Backend issue created for UpdateMoneyRequestDistanceRate converting quantity on odometer expenses: https://github.com/Expensify/Expensify/issues/608482

  20. Julesssss commented on Mar 6, 2026

    @Julesssss
    Contributor

    Backend PR in progress

  21. IuliiaHerets commented on Mar 16, 2026

    @IuliiaHerets

    Windows 10 / Chrome
    Not Repro
    v9.3.38-1

    bandicam.2026-03-16.15-13-24-503.mp4
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 contributorReviewingHas a PR in reviewWeeklyKSv2

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions