Skip to content

[Due for payment 2026-10-28] [$175] Unable to attach a receipt to Track Distance > Odometer expenses #104349

Closed

Description

@m-natarajan

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: 9.5.13-5
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from BrowserStack:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: @fergimenes
Slack conversation (hyperlinked to channel name): #Expensify Bugs

Action Performed:

  1. Go to Track Distance.
  2. Select Odometer.
  3. Create a mileage expense using an enabled distance rate.
  4. Open the created Odometer expense.
  5. Attempt to add a receipt by clicking the receipt area or dragging/dropping an image onto it.

Expected Result:

The receipt should attach to the existing Odometer mileage expense, just as it does for a Manual distance expense.

Actual Result:

The receipt does not attach to the Odometer expense. Dragging/dropping or adding the receipt creates a separate scan expense instead. The receipt expense and Odometer expense cannot be merged.

Workaround:

Unknown

Platforms:

Select the officially supported platforms where the issue was reproduced:

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

Screenshots/Videos

Recording.3713.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @mallenexpensify

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Oct 19, 2026
  2. MelvinBot commented on Oct 19, 2026

    @MelvinBot
    Contributor

    Updated 2026-10-19: Corrected based on feedback from nyomanjyotisa.

    Proposal

    What is the root cause of that problem?

    There are two causes:

    1. Attach and drop fail. The receipt check in canEditFieldOfMoneyRequest (ReportUtils.ts:6143) allows only Manual distance expenses. For odometer, canEditReceipt is false.
    2. Replace stays hidden. TransactionReceiptModalContent.tsx:191 sets isStitchedOdometerReceipt = isOdometerDistanceRequest(transaction) && !imageType. That is true for every odometer receipt, including ordinary uploads on created expenses.

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

    Base the Replace lock on where the expense is in its lifecycle, not on the receipt file. A receipt is built from odometer photos only while the expense is a draft. Once the expense is created, its receipt is a normal stored receipt.

    1. Permission: in the RECEIPT branch of canEditFieldOfMoneyRequest, also allow isOdometerDistanceRequest(transaction). This fixes click, file picker, and drop on created expenses. Delete, Rotate, and Crop also become available, the same as for Manual distance.
    2. Replace lock: change line 191 to isStitchedOdometerReceipt = isDraftTransaction && isOdometerDistanceRequest(transaction) && !imageType.
    3. Tests:
      • ReportUtilsTest: canEditFieldOfMoneyRequest with RECEIPT returns true for a distance-odometer expense, for both edit and delete.
      • TransactionReceiptModalContent: Replace is hidden for an odometer draft, and shown for a created odometer expense. Cover a receipt built from two photos, one built from one photo, and an ordinary upload.

    Your two concerns:

    • Ordinary uploads aren't misclassified. The check never reads the filename or the file itself, so the file's name can't change the result. On a created expense, every receipt gets Replace.
    • Single-photo receipts are covered, including existing ones. In a draft, the lock applies whether the receipt came from one photo or two. Expenses already created with a single photo are treated like any other created expense. They don't need a marker or a backfill.

    Drop: no extra guard is needed. Drops on the report only target created expenses (useReceiptDrop reads COLLECTION.TRANSACTION). The confirmation page already disables drops for odometer (IOURequestStepConfirmation/index.tsx:708).

    What alternative solutions did you explore? (Optional)

    • Tighter lock: also require photos on the draft, by adding && !!(transaction?.comment?.odometerStartImage || transaction?.comment?.odometerEndImage). Then a draft without photos keeps Replace for a receipt the user added. This is optional.
    • Filename prefix (my earlier update): dropped. It misclassifies files, misses single-photo receipts, and may not survive a server rename.

    Stephen3453 and sijo0218 proposed the same draft-only check before this update.

    Why the draft-only lock is safe
    • isDraftTransaction is true only in the create flow. It is set from the action route param (line 100). Routes from created expenses (TRANSACTION_RECEIPT.getRoute) never set it. Only the create-flow preview routes do.
    • Nothing rebuilds a created expense's receipt.
      • useOdometerReceiptStitcher runs only on the confirmation step and writes only to the draft, with isDraft = true (index.ts:104-125).
      • Editing a created odometer expense updates only the readings, and the photo buttons are hidden (IOURequestStepDistanceOdometer.tsx:690).
    • The lock was meant for drafts. It came from [Odometer] Image stitching, where Replace was hidden because the stitcher rebuilds the receipt from the photos during creation.
    • I verified this from code at d5772eb. I didn't test it in the browser.

    Next Steps for Contributor+ team:
    To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/104349#issuecomment-6267017537) to create a draft PR.
    To refine: @MelvinBot <your feedback>
    To reject: Explain why you are rejecting Melvin's proposal.

  3. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Oct 19, 2026
  4. melvin-bot commented on Oct 19, 2026

    @melvin-bot

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

  5. j3ffffff commented on Oct 19, 2026

    @j3ffffff
  6. changed the title [-]Unable to attach a receipt to Track Distance > Odometer expenses[/-] [+][$175] Unable to attach a receipt to Track Distance > Odometer expenses[/+] on Oct 19, 2026
  7. melvin-bot commented on Oct 19, 2026

    @melvin-bot
  8. camesenin commented on Oct 19, 2026

    @camesenin
  9. melvin-bot commented on Oct 19, 2026

    @melvin-bot

    ✅ Contributor details stored successfully. Thank you for contributing to Expensify!

  10. nyomanjyotisa commented on Oct 19, 2026

    @nyomanjyotisa
    Member

    @MelvinBot Attachment works with the permission change, but Replace remains hidden for ordinary uploads. Please distinguish photo-derived odometer receipts from ordinary uploads and cover attachment, replacement and drops.

  11. MelvinBot commented on Oct 19, 2026

    @MelvinBot
    Contributor

    Updated proposal

    nyomanjyotisa, Replace stays hidden because TransactionReceiptModalContent.tsx:191 marks every odometer receipt as stitched: isOdometerDistanceRequest(transaction) && !imageType. imageType is set only when the modal shows a raw start or end photo during creation. So it never tells you where the receipt came from.

    What is the root cause of that problem?

    There are two causes:

    1. The receipt permission check in ReportUtils.ts:6123 only allows Manual distance expenses, so attach and drop fail for odometer. The fix you tested covers this.
    2. Nothing records that a receipt was built from odometer photos. The photos stay on the device (Transaction.ts:138), and the created expense keeps only the readings (buildOptimisticTransaction.ts:137-142). The only marker is the filename prefix stitched_odometer (constants.ts:1). That prefix is missing when the user takes only one photo, because the receipt keeps the photo's own name (deriveOdometerReceipt.ts:28-33). No code reads the prefix today.

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

    1. Permission: allow isOdometerDistanceRequest in the RECEIPT branch of canEditFieldOfMoneyRequest (unchanged from my first proposal).

    2. Mark every photo-derived receipt: give the single-photo receipt a name that starts with STITCHED_ODOMETER_FILENAME_PREFIX in deriveOdometerReceipt (single mode), the same way the stitched one is named.

    3. Add a helper: create isOdometerPhotoReceipt(transaction) in TransactionUtils. It returns true only for odometer expenses where either:

      • the draft still has odometerStartImage or odometerEndImage, or
      • receipt.filename starts with the prefix.

      A file the user uploads later has its own name (Receipt.ts:256-265), so the helper returns false for it.

    4. Use the helper on each path:

      • Attach: no change needed. Attaching only happens when there's no receipt yet, so step 1 covers both the click and the file picker.
      • Replace: in TransactionReceiptModalContent, set isStitchedOdometerReceipt = !imageType && isOdometerPhotoReceipt(transaction). Replace then shows for ordinary uploads and stays hidden for photo-derived receipts.
      • Drop: in useShouldAddOrReplaceReceipt.ts, also return isPhotoReceiptLocked when the helper is true. In useReceiptDrop.ts, ignore the drop when that flag is set. Without this, the drop falls back to creating a new scan expense, which is the original bug.
      • Delete: keep it as is. It's how a user swaps out a photo-derived receipt on a created expense, because the photos can't be retaken after creation (IOURequestStepDistanceOdometer.tsx:690).
    5. Tests:

      • Unit tests for the helper: two photos, one photo, an ordinary upload, a draft with photos, and a non-odometer expense.
      • A canEditFieldOfMoneyRequest case for odometer.
      • useShouldAddOrReplaceReceipt cases for photo-derived and ordinary receipts.

    What alternative solutions did you explore? (Optional)

    • Server flag: store a flag like receipt.isOdometerReceipt on the server. This is the most reliable option, but it needs backend work.
    • Hide Replace only on drafts: use isDraftTransaction && isOdometerDistanceRequest && !imageType. This needs no classification, but it would allow replacing photo-derived receipts on created expenses.
    Before implementing, check this

    I couldn't confirm that the server keeps the uploaded filename in receipt.filename. Logs weren't available in this run, and a ReceiptUtils.ts comment shows stored receipts as w_<hash>.jpg.

    To check, create an odometer expense with two photos. Reload, then confirm receipt.filename still starts with stitched_odometer.

    If the server renames the file, the prefix only works until the server responds. In that case, use one of the alternatives above.


    Next Steps for Contributor+ team:
    To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/104349) to create a draft PR.
    To refine: @MelvinBot <your feedback>
    To reject: Explain why you are rejecting Melvin's proposal.


    view run

  12. Stephen3453 commented on Oct 19, 2026

    @Stephen3453

    Proposal

    What is the root cause of that problem?

    1. src/libs/ReportUtils.ts:6123: the RECEIPT branch of canEditFieldOfMoneyRequest allows only manual distance (!isDistanceRequest || isManualDistanceRequest). For odometer, canEditReceipt is false, so the empty receipt is disabled, and useShouldAddOrReplaceReceipt.ts:38-42 returns false, so useReceiptDrop.ts:70 skips replaceReceipt and :89 starts a new SCAN expense.
    2. TransactionReceiptModalContent.tsx:191 treats every odometer receipt as stitched (isOdometerDistanceRequest && !imageType), so Replace stays hidden even for ordinary uploads.

    A photo-derived receipt can only exist in a draft. In a draft, useOdometerReceiptStitcher writes transaction.receipt from odometerStartImage/odometerEndImage and clears any other receipt (index.ts:104-125). After creation, the photos are gone: they are local-only (Transaction.ts:138).

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

    1. canEditFieldOfMoneyRequest: add || isOdometerDistanceRequest(transaction) to line 6123. This fixes click, file picker and drop together, and enables Delete.
    2. TransactionReceiptModalContent.tsx:191: isStitchedOdometerReceipt = isDraftTransaction && isOdometerDistanceRequest(transaction) && !imageType. Replace stays hidden while the stitcher owns the receipt. It shows on created expenses, where the receipt is server-stored like any other. No filename prefix and no backend flag needed.
    3. Tests: in tests/unit/ReportUtilsTest.ts, check that edit and delete for RECEIPT return true for a distance-odometer transaction. Add a UI test showing that Replace is hidden on an odometer draft and shown on a created odometer expense.

    What alternative solutions did you explore? (Optional)

    • @MelvinBot (first) and @camesenin: the same change 1. On its own, it leaves Replace hidden, as @nyomanjyotisa found.
    • @MelvinBot (updated): classifies by the stitched_odometer filename. It flags the risk itself: the server may rename stored receipts (ReceiptUtils.ts:55). It also keeps Delete, so Delete then attach still swaps a "locked" receipt. That makes the lock cosmetic for three extra code paths. The draft check is exact and needs one line.
  13. 18 remaining items

  14. nyomanjyotisa commented on Oct 22, 2026

    @nyomanjyotisa
    Member

    Contributor+ Checklist:

    • [Contributor] The offending PR and associated issue have been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.

      Link to the comment on the PR: N/A — existing odometer receipt-editing gap; no offending regression identified.
      Link to the comment on the Issue: N/A.

    • [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 — non-critical receipt-editing issue.

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

    Precondition:

    • Workspace distance rate enabled; own editable expense and two dummy receipt images.

    Test:

    1. Create an odometer expense without photos. Note its amount and start/end readings.
    2. Click the empty receipt area and attach an image; then open it and replace it. On desktop, also replace it by drag/drop. Verify each updates the same expense without creating another scan expense.
    3. Replace the receipt offline, reconnect and reload/relaunch. Verify the replacement persists and the amount/readings remain unchanged.
    4. Start an odometer expense with start/end photos. Open its combined preview before creation. Verify Replace is unavailable and individual photos remain editable; cancel the draft.
    5. Verify manual-distance receipts remain editable and map/GPS-generated receipts remain protected.

    Do we agree 👍 or 👎

  15. added
    Awaiting PaymentAuto-added when associated PR is deployed to production
    and removed on Oct 22, 2026
  16. melvin-bot commented on Oct 27, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  17. melvin-bot commented on Oct 27, 2026

    @melvin-bot

    Payment Summary

    Resolving PRs:

    BugZero Checklist (@mallenexpensify)

    • I have confirmed assignees, roles, and Upwork contracts look correct
    • I have paid out Upwork contracts / manual NewDot requests
    • [BugZero Assignee] I have created a GH issue for creating/updating the regression test once above steps have been agreed upon
  18. mallenexpensify commented on Oct 30, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor+: @nyomanjyotisa due $175 via NewDot

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