Skip to content

Duplicate GPS distance expenses as manual distance - #98189

Merged
blimpich merged 31 commits into
Expensify:mainfrom
x-dev90:fix/gps-distance-duplicate-manual
Sep 7, 2026
Merged

Duplicate GPS distance expenses as manual distance#98189
blimpich merged 31 commits into
Expensify:mainfrom
x-dev90:fix/gps-distance-duplicate-manual

Conversation

@x-dev90

@x-dev90 x-dev90 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

GPS distance expenses are now duplicated as manual distance expenses because the saved transaction no longer contains the original GPS coordinate trace.

The duplicate flow now maps DISTANCE_GPS to DISTANCE_MANUAL, skips copied GPS endpoint waypoints, keeps the saved measured distance, and uses the duplicated request type consistently for both workspace and self-DM duplicates.

Added tests for GPS distance duplication in both workspace and self-DM flows, plus coverage to confirm normal map distance duplicates still preserve waypoints.

Fixed Issues

$#91814
PROPOSAL:#91814 (comment)

Tests

  1. Open the app and sign in.
  2. Open self-DM.
  3. Create a GPS distance expense.
  4. Open the created GPS distance expense.
  5. Tap More > Duplicate.
  6. Open the duplicated expense.
  7. Verify the duplicated expense opens without an unexpected error.
  • Verify that no errors appear in the JS console

Offline tests

N/A

QA Steps

Same as tests

// TODO: These must be filled out, or the issue title must include "[No QA]."

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Screenrecorder-2026-08-10-23-42-52-914.mp4
Android: mWeb Chrome
iOS: Native
Screen.Recording.2026-08-28.at.11.21.57.AM.mov
iOS: mWeb Safari
Screen.Recording.2026-08-28.at.11.24.10.AM.mov
MacOS: Chrome / Safari
Screen.Recording.2026-08-28.at.11.26.31.AM.mov

@x-dev90
x-dev90 marked this pull request as ready for review August 10, 2026 20:22
@x-dev90
x-dev90 requested review from a team as code owners August 10, 2026 20:22
@melvin-bot
melvin-bot Bot requested review from garrettmknight and marufsharifi and removed request for a team August 10, 2026 20:22
@melvin-bot

melvin-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown

@marufsharifi Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot
melvin-bot Bot removed the request for review from a team August 10, 2026 20:22
@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/libs/actions/IOU/Duplicate.ts 92.41% <100.00%> (+0.26%) ⬆️
... and 14 files with indirect coverage changes

@marufsharifi

Copy link
Copy Markdown
Contributor

@x-dev90, could you please check the failed actions. thanks.

@x-dev90

x-dev90 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@x-dev90, could you please check the failed actions. thanks.

Hi @marufsharifi, all actions have now passed successfully. Could you please review them again when you have a chance? Thank you.

garrettmknight
garrettmknight previously approved these changes Aug 11, 2026

@garrettmknight garrettmknight left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good from a product perspective.

Comment thread src/libs/actions/IOU/Duplicate.ts Outdated
Comment thread src/libs/actions/IOU/Duplicate.ts Outdated
Comment thread src/libs/actions/IOU/Duplicate.ts Outdated
Comment thread tests/actions/IOUTest/DuplicateTest.ts Outdated
@marufsharifi

Copy link
Copy Markdown
Contributor

@MelvinBot Review.

@MelvinBot

Copy link
Copy Markdown
Contributor

Review: LGTM ✅

The change correctly fixes the unexpected error when duplicating a GPS distance expense. A saved GPS transaction only keeps the derived waypoints/distance, not the raw GPS coordinate trace (that lives in a transient gpsDraftDetails draft that's cleared after submission), so re-creating it as a GPS request produces a request with no coordinates → the error. Mapping distance-gpsdistance-manual on duplicate is the right workaround, and the fix is applied consistently across all three duplicate paths (workspace, self-DM/track, report).

I traced the logic and found no correctness or regression issues:

Correctness / regression analysis
  • getDuplicateRequestType cleanly extends the existing SCAN→MANUAL pattern with GPS→MANUAL. Computing duplicateRequestType once and reusing it is a nice tidy-up.

  • Workspace pathcreateExpenseByType:L732 swaps getDistanceRequestType(transaction) for duplicateRequestType. This is behavior-preserving for all non-GPS distance types: the DISTANCE case only runs when getTransactionType === DISTANCE, so iouRequestType is always a distance type, and for MAP/MANUAL/ODOMETER/plain-DISTANCE getDuplicateRequestType returns the identical value getDistanceRequestType did. Only GPS changes (the intended fix).

  • Self-DM / track pathL916 newly adds distanceRequestType for every distance request (previously unset). I checked this is not a regression: in TrackExpense.ts, transactionParams.distanceRequestType is only forwarded to the backend TRACK_EXPENSE command — it does not drive the optimistic iouRequestType (that comes from existingTransaction.iouRequestType, also set to duplicateRequestType) nor waypoint stripping. The normal (non-duplicate) creation flow already sends this exact field, so the duplicate path is just becoming consistent with it.

  • Waypoint strippingL609-L610 drops the GPS endpoint waypoints and L642 keeps the saved measured distance — appropriate for a manual distance expense.

Minor (non-blocking) note: because the waypoints are stripped, the duplicated expense loses the original start/end addresses and shows only the distance/amount (as any manual distance expense does). This satisfies the issue's expected result ("must not show unexpected error") and the merchant field is preserved separately, so it's fine — just calling out the intentional UX trade-off in case you want to confirm it's acceptable.

Tests: Good coverage — 3 new tests exercise the workspace, self-DM, and report duplicate paths for GPS, plus the existing "map distance preserves waypoints" test guards the non-GPS path against regression. All CI is green (tests, typecheck, ESLint, Oxfmt, React Compiler). The only failing check is the Reviewer Checklist, which just needs to be filled out.

Note on manual verification

I couldn't reproduce the flow end-to-end myself: GPS distance expenses can only be created via native GPS tracking on mobile (not web), and my web regression session hit an unrelated infra hiccup. The unit tests + green CI cover the behavior, but it's worth confirming the on-device flow (create GPS expense on Android → duplicate → open) matches the author's recording before approving.

@x-dev90

x-dev90 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

@marufsharifi , gentle bump. Thanks!

@x-dev90

x-dev90 commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

@marufsharifi, quick bump—thanks!

@marufsharifi

Copy link
Copy Markdown
Contributor

@x-dev90, could you please, merge the main. thanks.

Comment thread src/libs/actions/IOU/Duplicate.ts Outdated
Comment thread src/libs/actions/IOU/Duplicate.ts
Comment thread tests/actions/IOUTest/DuplicateTest.ts Outdated
@x-dev90

x-dev90 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

@marufsharifi ,I’ve addressed all your feedback. Could you please review the latest changes? thanks!

@marufsharifi

Copy link
Copy Markdown
Contributor

@x-dev90, could you please merge the main. thanks.

@x-dev90

x-dev90 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

@x-dev90, could you please merge the main. thanks.

@marufsharifi, Done.

Comment thread src/libs/actions/IOU/Duplicate.ts Outdated
Comment thread src/libs/actions/IOU/Duplicate.ts Outdated
Comment thread src/libs/actions/IOU/Duplicate.ts Outdated
Comment thread src/libs/actions/IOU/Duplicate.ts
@x-dev90

x-dev90 commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Hi @marufsharifi , I’ve addressed all feedback on the PR. Could you please review the latest changes? thanks

@marufsharifi marufsharifi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@melvin-bot
melvin-bot Bot requested a review from blimpich September 7, 2026 05:30

@blimpich blimpich left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job!

@blimpich
blimpich merged commit fea04ad into Expensify:main Sep 7, 2026
39 of 41 checks passed
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

🚧 blimpich has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

OSBotify commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify

OSBotify commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/blimpich in version: 9.4.74-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 Yes — help site changes were required. Draft PR: #100630

This PR changes user-visible behavior that neither help article described: duplicating a GPS distance expense that is not on a report (Unreported), or when the member has no workspace, now produces a manual distance expense. The copy keeps the saved total distance, but the route map and its start/end waypoints are dropped, because the raw GPS trace isn't stored on the saved transaction. A GPS distance expense already on a workspace report still duplicates as GPS with the route intact.

Articles updated:

  • How-to-Duplicate-an-Expense.md — new ## What happens when you duplicate a GPS distance expense section, matching FAQ entry, updated keywords / internalScope.
  • Distance-Expenses.md — new FAQ entry ## What happens when I duplicate a GPS Distance expense?, updated keywords.

⚠️ I could not assign the docs PR to you. GitHub rejects both assignment and review requests for x-dev90 on Expensify/App ("Reviews may only be requested from collaborators" / not in the assignable list), because the account has read-only access. The HelpDot label is applied, PullerBear is requested, and you're @-mentioned in the PR body — an internal engineer will need to add you as an assignee if that's required.

How I verified the behavior and the copy

Behavior, from the diff in src/libs/actions/IOU/Duplicate.ts:

  • shouldDuplicateAsManualDistance() is true only when shouldDuplicateSelfDMExpense && isGPSDistanceRequest(transaction), and shouldDuplicateSelfDMExpense = !targetPolicy || isSourceUnreported.
  • When true: getDuplicateRequestType() returns DISTANCE_MANUAL, buildDuplicateTransactionParams() drops waypoints, and transactionParams.distance falls back to comment.customUnit.quantity.
  • Your two new tests confirm both branches — unreported/no-policy → DISTANCE_MANUAL with waypoints: undefined and quantity: 56.78; reported workspace source → DISTANCE_GPS with waypoints preserved.

shouldDuplicateSelfDMExpense only feeds the request-type decision — the target report selection (!targetPolicy || isSourceUnreportedTRACK_EXPENSE) is unchanged — so I documented only the request-type change and left placement alone.

UI labels were checked against the live web app before writing: Spend / Expenses nav tabs, More button, Duplicate expense menu item, Track distance in the Create menu, and the Map / Manual / GPS / Odometer tabs on the Track distance screen. All matched the existing articles' capitalization. Written against docs/HELPSITE_NAMING_CONVENTIONS.md, docs/HELP_AUTHORING_GUIDELINES.md, and docs/TEMPLATE.md.

One thing I left out of scope: How-to-Duplicate-an-Expense.md opens with "This generates new expenses on your primary workspace", which isn't accurate for Unreported sources (they stay unreported via TRACK_EXPENSE). That's pre-existing and not changed by this PR, so I didn't touch it — worth a separate docs fix if you agree.

@x-dev90, please review the linked help site PR and confirm it reflects the current behavior. Then mark the linked help site PR Ready for review

@OSBotify

OSBotify commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/mountiny in version: 9.4.74-2 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants