Skip to content

Keep the tax sign of a merged expense in line with its amount offline - #103677

Merged
grgia merged 1 commit into
mainfrom
claude-fixMergeOfflineTaxSign
Oct 12, 2026
Merged

grgia merged 1 commit into
mainfrom
claude-fixMergeOfflineTaxSign

Conversation

@MelvinBot

@MelvinBot MelvinBot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

When you merge two negative expenses offline, the merged expense showed a positive tax amount until the server responded.

The merge flow keeps values in mergeTransaction with the sign they are displayed with. When you pick the amount, though, getMergeFieldUpdatedValues calculated the tax from the transaction's stored amount. On expense reports, the stored amount has the opposite sign. The tax got the wrong sign, and the offline update flipped it again. Show negative tax amount for negative expenses on the expense details page removed a Math.abs() that had been hiding this.

This PR:

  • Calculates the tax from the displayed amount the user picked (fieldValue), as the taxValue branch already does with mergeTransaction.amount.
  • Carries over the displayed tax (transactionDetails.taxAmount) instead of the raw stored tax when you pick a distance merchant.
  • Shows the merge confirmation preview's tax as is in MoneyRequestView, the same way that preview already uses updatedTransaction.amount. Otherwise the now correctly signed tax would be flipped again on the confirmation page.

The server ignores this value because MergeTransaction doesn't send taxAmount. This change only fixes the optimistic offline data and the preview.

Fixed Issues

$ #103671
PROPOSAL: #103671 (comment)

Tests

Same as QA Steps

  • Verify that no errors appear in the JS console

Offline tests

Same as QA Steps

QA Steps

Precondition:

  • have a workspace with non-zero tax rates
  1. Create an expense with a negative amount in a WS chat
  2. Open the expense
  3. Change the tax rate to a non-zero rate
  4. Repeat steps 1 to 3 to create another expense with another negative amount
  5. Open any expense
  6. Go offline
  7. Press More > Merge
  8. Select the other expense > Continue
  9. Select any detail and complete the merging process
  10. Open the merged expense
  11. Verify the tax amount field is negative
  • 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 verified any copy / text that was added to the app 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 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 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.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • 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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
web.mp4

The merge flow calculated the tax from the stored amount, which has the opposite
sign on expense reports, so a merged negative expense showed a positive tax until
the server responded. Calculate it from the displayed amount instead, carry over the
displayed tax for distance expenses, and show the merge preview's tax as is.

Co-authored-by: Bernhard Owen Josephus <bernhardoj@users.noreply.github.com>
@MelvinBot
MelvinBot requested a review from a team October 10, 2026 09:28
@melvin-bot melvin-bot Bot added Melvin-Test-Android Melvin-Test-Web Triggers Melvin to run the testing steps of the PR on web labels Oct 10, 2026
@MelvinBot

Copy link
Copy Markdown
Contributor Author

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-fixMergeOfflineTaxSign
git checkout -b claude-fixMergeOfflineTaxSign upstream/claude-fixMergeOfflineTaxSign
git push -u origin claude-fixMergeOfflineTaxSign

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

const formattedTaxAmount = convertToDisplayString(transactionTaxAmount ?? 0, actualCurrency);
// Use the updated transaction tax amount in merge flow to have correct positive/negative sign
const actualTaxAmount = isFromMergeTransaction && updatedTransaction ? updatedTransaction.taxAmount : transactionTaxAmount;
const formattedTaxAmount = convertToDisplayString(actualTaxAmount ?? 0, actualCurrency);

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.

@MelvinBot hmm, this makes me think the mergeTransaction taxAmount should be stored as a stored value instead of displayed value. Why would it be different?

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.

Keep it displayed. The save path already negates mergeTransaction.amount once and diffs against displayed values, so a stored-sign tax would get flipped on write. Mark it ready and I'll review for the CP

@MelvinBot

MelvinBot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Android test steps verification results: ⚠️ partial

The PR's Tests section is empty, so I ran the reproduction steps from the linked issue. Both negative expenses showed a negative tax amount, but the expense's More menu froze after it opened, so the offline merge steps (4–7), including the key check, were not run.
More-actions sheet on the expense unresponsive to Merge tap

Step Status
Taxes are enabled on the workspaceWorkspace More features > Taxes toggle is on. The Taxes settings page shows "Tax exempt (0%) • Default" and "Tax Rate 1 (5%)".
Workspace Taxes settings showing enabled tax rates
✅
First negative expense (-$10.00) with a non-zero tax rate shows a negative tax amount"Test Merchant" shows Amount -$10.00, Tax "Tax Rate 1 (5%)", Tax amount -$0.48.
Expense 1 details with negative tax amount -$0.48
✅
Second negative expense (-$20.00) with a non-zero tax rate shows a negative tax amount"Second Merchant" shows Amount -$20.00, Tax "Tax Rate 1 (5%)", Tax amount -$0.95.
Expense 2 details with negative tax amount -$0.95
✅
Open an expense, go offline, tap More > Merge, select the other expense, ContinueThe More sheet opened with Hold, Split, Merge, Duplicate expense, Move to report, and View details. After that, taps, scrolls, and back presses did nothing. A Metro restart did not clear it. The tester could not relaunch the app, so the merge flow did not start.
More-actions sheet on the expense unresponsive to Merge tap
❌
Merge confirmation preview shows a negative tax amount offlineNot reached because the More sheet froze.
❌
Merged expense's Tax amount is negative while still offline (key check)Not reached because the More sheet froze.
❌
Merged expense's tax amount stays negative after going back onlineNot reached because the More sheet froze.
❌

The ❌ rows mean the steps were blocked, not that the fix failed. To retry, start a fresh session. The tester can go offline with Settings > Troubleshoot > Force offline.


view run · view recording

@MelvinBot

Copy link
Copy Markdown
Contributor Author

mergeTransaction holds every field as a displayed value, and taxAmount follows that rule. Storing only taxAmount with the stored sign would mix two sign conventions in one object. The code that consumes mergeTransaction would also flip it the wrong way.

  • Read: Merge values come from getTransactionDetails, which returns displayed signs (MergeTransactionUtils.ts:245-250). amount is already kept this way.
  • Write: The optimistic update compares mergeTransaction with the target's displayed values (MergeTransaction.ts:323-334). It passes the diff as transactionChanges to the regular edit helper. That helper expects displayed signs and negates them for expense reports, both amount (getUpdatedTransaction.ts:180) and taxAmount (getUpdatedTransaction.ts:384). A stored-sign tax would compare as changed and then get flipped. That double flip is the bug in this issue.
  • Report choice: The stored sign depends on the report type, and you can merge into a different report. The displayed value doesn't depend on that, so the action converts it once for the final report. For example, the API amount is converted at MergeTransaction.ts:480.

The bug came from the amount branch. It used the transaction's stored amount to compute a value that is meant to be displayed. This PR fixes that inconsistency.


view run

@bernhardoj

Copy link
Copy Markdown
Contributor

@MelvinBot add this to QA Steps

Precondition:

  • have a workspace with non-zero tax rates
  1. Create an expense with a negative amount in a WS chat
  2. Open the expense
  3. Change the tax rate to a non-zero rate
  4. Repeat steps 1 to 3 to create another expense with another negative amount
  5. Open any expense
  6. Go offline
  7. Press More > Merge
  8. Select the other expense > Continue
  9. Select any detail and complete the merging process
  10. Open the merged expense
  11. Verify the tax amount field is negative

Update Test steps and Offline steps to be "Same as QA Steps"

@MelvinBot

Copy link
Copy Markdown
Contributor Author

Updated the PR description:

  • QA Steps: Added your precondition and steps 1–11.
  • Tests: Changed to "Same as QA Steps".
  • Offline tests: Changed to "Same as QA Steps".

I kept the "Verify that no errors appear in the JS console" checkbox in Tests and QA Steps. The rest of the description is unchanged.


view run

@bernhardoj

Copy link
Copy Markdown
Contributor

@MelvinBot replace the PR Author Checklist section with below

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 verified any copy / text that was added to the app 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 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 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.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • 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.

and replace the Screenshots/Videos section with below.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
web.mp4

Then, check all "Verify that no errors appear in the JS console". Last, mark the PR as ready for review. You can do it!

@MelvinBot
MelvinBot marked this pull request as ready for review October 12, 2026 13:14
@MelvinBot
MelvinBot requested a review from a team as a code owner October 12, 2026 13:14
@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Done. I updated the PR description and marked this PR ready for review:

  • Replaced the PR Author Checklist with your version. Every item is checked.
  • Replaced the Screenshots/Videos section. Your video is under MacOS: Chrome / Safari.
  • Checked both "Verify that no errors appear in the JS console" boxes, in Tests and in QA Steps.

view run

@melvin-bot
melvin-bot Bot requested review from flaviadefaria and ikevin127 and removed request for a team October 12, 2026 13:14
@melvin-bot

melvin-bot Bot commented Oct 12, 2026

Copy link
Copy Markdown

@ikevin127 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 October 12, 2026 13:14
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T13:21:00.560029Z 329b49e Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@bernhardoj
bernhardoj removed the request for review from ikevin127 October 12, 2026 13:23
@bernhardoj
bernhardoj requested a review from grgia October 12, 2026 13:24
@melvin-bot
melvin-bot Bot requested a review from AndrewGable October 12, 2026 13:24
@bernhardoj
bernhardoj removed the request for review from AndrewGable October 12, 2026 13:24
@grgia grgia changed the title Keep the tax sign of a merged expense in line with its amount offline [CP Staging] Keep the tax sign of a merged expense in line with its amount offline Oct 12, 2026
@grgia
grgia merged commit 7e2c443 into main Oct 12, 2026
54 of 61 checks passed
@grgia
grgia deleted the claude-fixMergeOfflineTaxSign branch October 12, 2026 14:53
@github-actions

Copy link
Copy Markdown
Contributor

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

@OSBotify

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.

@grgia grgia changed the title [CP Staging] Keep the tax sign of a merged expense in line with its amount offline Keep the tax sign of a merged expense in line with its amount offline Oct 12, 2026
@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/grgia in version: 9.5.8-0 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor Author

No help site update is needed. This bug fix makes a merged negative expense show a negative tax amount while offline, which is what users already expect, and no article sentence describes the old behavior.


view run

mukhrr pushed a commit to mukhrr/App that referenced this pull request Oct 13, 2026
…MergeOfflineTaxSign"

This reverts commit 7e2c443, reversing
changes made to 4acb4ec.
@izarutskaya

izarutskaya commented Oct 13, 2026 •

Copy link
Copy Markdown

@bernhardoj Tax amount field is not negative

1791899583717.11-web.mp4

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/cristipaval in version: 9.5.8-5 🚀

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

Bundle Size Analysis (Sentry):

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/grgia in version: 9.5.9-0 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor Author

No help site update is needed. This bug fix only corrects the tax sign that merged negative expenses show offline before the server responds, which is the behavior users already expect.


view run

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/cristipaval in version: 9.5.9-4 🚀

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

Bundle Size Analysis (Sentry):

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

Labels

Melvin-Test-Android Melvin-Test-Web Triggers Melvin to run the testing steps of the PR on web

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants