Skip to content

Show negative tax amount for negative expenses, with follow-up fixes - #104306

Open
MelvinBot wants to merge 14 commits into
mainfrom
claude-reapplyNegativeTaxAmount
Open

MelvinBot wants to merge 14 commits into
mainfrom
claude-reapplyNegativeTaxAmount

Conversation

@MelvinBot

@MelvinBot MelvinBot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

This re-lands #102175, which was reverted in #103763. It also includes the follow-up fixes for the deploy blockers it raised.

On expense reports, taxAmount is stored with the opposite sign of what we display. The expense details page wrapped the tax in Math.abs(), so a negative expense showed a positive tax. The report table showed it as negative.

This PR includes:

Two small changes were needed to combine these PRs:

Not included: the split flow deploy blocker (#103723) had no fix PR in the request.

Fixed Issues

$ #98098
PROPOSAL: #98098 (comment)

Tests

Same as QA Steps

  • Verify that no errors appear in the JS console

Offline tests

Same as QA Steps

QA Steps

Prerequisite:

  • have a workspace with Taxes enabled with a non-zero tax rate and Rules enabled

A.

  1. Open a workspace chat
  2. Submit an expense with a negative amount, a currency different from the workspace, and a tax rate
  3. Open the expense
  4. Update the tax rate to another non-zero tax rate
  5. Verify the tax amount and tax converted amount are negative
  6. Edit the tax rate
  7. Verify the tax change system message shows the previous tax as negative
  8. Unreport the expense
  9. Open self DM and open the unreported expense
  10. Verify the tax amount is still negative

B.

  1. Create expense A with a negative amount
  2. Open the expense
  3. Change the tax rate to 5%
  4. Create expense B with a positive amount and a 0% tax rate
  5. Open the report
  6. Bulk select both expenses
  7. Press More > Merge
  8. Select expense B amount, 5% rate, and any other details
  9. Press Continue
  10. Verify on the confirmation page that the tax amount isn't negative
  11. Merge the expenses
  12. Open the expense
  13. Verify the tax amount isn't negative

C.

  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. Go offline
  6. Bulk select both expenses
  7. Press More > Merge
  8. Select any detail and complete the merging process
  9. Open the merged expense
  10. Verify the tax amount field is negative

D.
Extra prerequisite:

  • Open Categories > Select a category > Create new rule > Apply expense defaults > 5% tax rate
  1. Create a positive amount expense in a WS chat without a category
  2. Go offline
  3. Set the category to Advertising
  4. Verify the tax amount is positive

E.

  1. Create an expense with a negative amount in a WS chat with a 0% tax rate
  2. Open the expense
  3. Press More > Split
  4. Press on any split
  5. Change the tax rate to a non-zero tax rate
  6. Press Save > Save the split
  7. Open the split with the non-zero tax rate.
  8. Verify the tax amount is negative

F.
Extra prerequisite:

  • Have two non-zero tax rates, for example 5% and 10%
  1. Create expense A with a negative amount in a WS chat
  2. Open the expense
  3. Change the tax rate to 5%
  4. Create expense B with the same amount, merchant, and date as expense A
  5. Open the expense
  6. Change the tax rate to 10%
  7. Wait for both expenses to show "Potential duplicate"
  8. Go offline
  9. Open expense A and press Review duplicates
  10. Keep expense A and select the 10% tax rate
  11. Verify on the confirmation page that the tax amount is negative
  12. Confirm
  13. Open the kept expense
  14. Verify the tax amount is negative
  15. Go online
  16. Verify the tax amount is still negative

G.

  1. Repeat steps 1 to 7 of F, but with a positive amount
  2. Open expense A and press Review duplicates
  3. Keep expense A and select the 10% tax rate
  4. Verify on the confirmation page that the tax amount is positive
  5. Confirm
  6. Open the kept expense
  7. Verify the tax amount is positive

H.
Extra prerequisite:

  • Have two non-zero tax rates, for example 5% and 10%
  1. Create 2 expenses with different negative amounts in a WS chat
  2. Open each expense and change its tax rate to 5%
  3. Go offline
  4. Go to Reports > Expenses
  5. Select both expenses and press Edit multiple
  6. Change the tax rate to 10% and save
  7. Open each expense
  8. Verify the tax amount is negative
  9. Select both expenses again and press Edit multiple
  10. Change only the amount to another negative amount and save
  11. Open each expense
  12. Verify the tax amount is negative
  13. Go online
  14. Verify the tax amounts are still negative

I.
Extra prerequisite:

  • Same as D: a category with a 5% tax rate expense default
  1. Create 2 expenses with a positive amount in a WS chat without a category
  2. Go offline
  3. Go to Reports > Expenses
  4. Select both expenses and press Edit multiple
  5. Change the amount to a negative amount and the category to the category with the 5% tax rate rule, then save
  6. Open each expense
  7. Verify the amount and the tax amount are negative
  8. Create 2 more expenses with a negative amount in the WS chat without a category
  9. Select both new expenses and press Edit multiple
  10. Change the amount to a positive amount and the category to the category with the 5% tax rate rule, then save
  11. Open each new expense
  12. Verify the amount and the tax amount are positive
  13. Go online
  14. Verify all 4 expenses keep the same tax amount sign as their amount
  • 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
unreport.mp4
merge.1.mp4
web.mp4
merge.mp4
catg.mp4
spliot.mp4

MelvinBot and others added 10 commits October 18, 2026 00:56
Co-authored-by: Bernhard Owen Josephus <bernhardoj@users.noreply.github.com>
Co-authored-by: Bernhard Owen Josephus <bernhardoj@users.noreply.github.com>
Co-authored-by: Bernhard Owen Josephus <bernhardoj@users.noreply.github.com>
Co-authored-by: Bernhard Owen Josephus <bernhardoj@users.noreply.github.com>
Co-authored-by: Georgia Monahan <grgia@users.noreply.github.com>
…essage

The server sends taxAmount/oldTaxAmount with the stored (inverted) sign, so convert them with getTaxAmount. Store the optimistic values the same way so the message doesn't flip after the server responds.

Co-authored-by: Bernhard Owen Josephus <bernhardoj@users.noreply.github.com>
…e system message

Co-authored-by: Bernhard Owen Josephus <bernhardoj@users.noreply.github.com>
… and update the merge distance test

Co-authored-by: Bernhard Owen Josephus <bernhardoj@users.noreply.github.com>
@MelvinBot
MelvinBot requested a review from a team October 18, 2026 01:02
@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 18, 2026
@MelvinBot

MelvinBot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Android test steps verification results: ✅ pass

Negative expenses show a negative tax amount and converted tax amount in all three flows: expense report (foreign currency), merged expense (created offline), and unreported self DM expense. No JS or red-box errors appeared. This PR's Tests section is still a TODO, so I ran the QA steps from the three re-landed PRs it combines.
Unreported self DM expense with negative tax amount

Step Status
A1: Open the workspace chat"Tester Tester's expenses" workspace chat opened successfully.
Workspace chat opened
✅
A2: Submit 2 expenses (one negative, foreign currency, with tax; one other)Created -€100.00 "Negative Expense Merchant" (EUR, workspace is USD) with Tax Rate 1 (5%), and a $50.00 "Second Expense". Both landed in the same draft report.
✅
A3: Open the expense report, then open the negative expenseExpense details showed Amount -€100.00, Converted -$112.36.
Negative expense details before tax rate change
✅
A4: Change its tax rate to another non-zero tax rateChanged from Tax Rate 1 (5%) to Tax Rate 2 (10%). System message "changed the tax rate to 10% (previously 5%)" was logged.
✅
A5: Tax amount and converted tax amount are negativeTax amount -€9.09, Converted -$10.21. Both are negative.
Negative tax amount and converted tax amount after rate change
✅
B1–B3: Create a negative expense, open it, set a non-zero tax rate (expense A)Created -$75.00 "Merge Expense A" with Tax Rate 1 (5%). Tax amount -$3.57.
Merge Expense A with negative tax amount
✅
B4: Repeat B1–B3 for a second negative expense (expense B)Created -$40.00 "Merge Expense B" with Tax Rate 2 (10%). Tax amount -$3.64.
Merge Expense B with negative tax amount
✅
B5–B6: Open either expense, go offlineOpened Merge Expense A and enabled Troubleshoot > Force offline. The "You appear to be offline" banner appeared.
✅
B7–B8: More > Merge, select the other expense, ContinueMore > Merge opened the expense picker. Selected Merge Expense B and pressed Continue.
✅
B9: Select details and complete the mergeKept Amount -$75.00, Merchant "Merge Expense A", Tax Rate 2 (10%). The confirmation screen showed Tax amount -$6.82. The merge completed offline.
✅
B10–B11: Open the merged expense; tax amount is negativeMerged expense shows Amount -$75.00, Tax Rate 2 (10%), Tax amount -$6.82, while still offline.
Merged expense with negative tax amount, offline
✅
C1–C2: Go to the workspace chat, create a negative expenseBack online, created -$60.00 "Self DM Expense" in the workspace chat.
✅
C3–C4: Open the report, change the tax rate to a non-zero rateSet Tax Rate 1 (5%). Tax amount -$2.86.
✅
C5–C6: Press the Report field, Remove from reportThe Report field picker showed "Remove from report". After pressing it, the expense left the workspace report.
✅
C7–C8: Go to the self DM, open the expense"Self DM Expense" appears as an unreported expense in the self DM and its details opened.
Unreported self DM expense with negative tax amount
✅
C9: Tax amount is negativeTax amount is -$2.86, unchanged after the expense moved to the self DM.
✅
System messages and errorsTax rate change messages show unsigned percentages, as expected. No separate "changed the tax amount" message appeared in these flows. No JS or red-box errors. Side note outside the documented steps: on the create-expense confirmation form (before submitting), the Tax amount field showed a positive value (for example, 4.76 for -100 at 5%).
✅

view run · view recording

@MelvinBot

MelvinBot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Web test steps verification results: ✅ pass

In all three flows (report expense in another currency, expenses merged offline, and unreported self DM expense), changing a negative expense's tax rate gives a negative tax amount and a negative converted tax. One thing to check: right after you create a negative expense, before you change its tax rate, the details page shows a positive tax ($5.35 / €4.76 for -€100). Android showed the same positive value on the create form.
Self DM unreported expense, tax amount -$1.90

Step Status
Precondition: workspace with Taxes enabled and 2+ non-zero tax ratesEnabled Taxes and added Tax Rate 2 (10%) next to Tax Rate 1 (5%) and Tax exempt (0%).
Taxes page showing Tax exempt 0%, Tax Rate 1 5%, Tax Rate 2 10%
✅
A1: Open the workspace chatThe workspace chat opened.
Workspace chat open
✅
A2–A3: Submit a negative EUR expense with tax plus one other expense, open the report and the negative expenseCreated "Negative Expense A" (-€100, Tax Rate 1) and "Other Expense" ($50). Before the tax rate change, the details page showed a positive tax amount ($5.35 / €4.76).
Negative expense before tax rate change, tax amount shown positive
✅
A4–A5: Change the tax rate to Tax Rate 2 (10%); tax amount and converted tax amount are negativeTax amount -€9.09, Converted -$10.21. Both are negative.
Negative expense after tax rate change, tax amount and converted amount both negative
✅
B1–B4: Create two negative expenses, each with a non-zero tax rate"Merge Negative 1" (-$20 at 5%) tax -$0.95. "Merge Negative 2" (-$30 at 10%) tax -$2.73.
Merge Negative 1 expense, tax amount -$0.95Merge Negative 2 expense, tax amount -$2.73
✅
B5–B6: Open either expense, go offlineEnabled Troubleshoot > Force offline. The app showed "You appear to be offline."
Troubleshoot page with Force offline enabled
✅
B7–B10: More > Merge, select the other expense, Continue, choose details, complete the mergeThe merge completed offline. "Merge Negative 1" left the list and "Merge Negative 2" remained as the merged expense.
✅
B11: The merged expense's tax amount is negativeAmount -$30.00, Tax Rate 2 (10%), Tax amount -$2.73.
Merged expense detail page, tax amount -$2.73
✅
C1–C7: Create a negative expense, set a non-zero tax rate, Report field > Remove from report, go to the self DM"Unreported Negative" (-$40) left the report, and "tracking -$40.00 for Unreported Negative" appeared in the self DM.
✅
C8–C9: Open the expense in the self DM; tax amount is negativeAmount -$40.00, Tax Rate 1 (5%), Tax amount -$1.90.
Self DM unreported expense, tax amount -$1.90
✅
System messages and console errorsTax rate changes logged "changed the tax rate to 10% (previously 5%)", which has no sign. Editing the Tax amount field directly did not seem to save, so the "changed the tax amount" message was not tested. The test browser can't read the JS console. No errors appeared in the UI.
✅

view run · view recording

@bernhardoj

Copy link
Copy Markdown
Contributor

@MelvinBot add this to QA Steps

Prerequisite:

  • have a workspace with Taxes enabled with a non-zero tax rate and Rules enabled

A.

  1. Open a workspace chat
  2. Submit an expense with a negative amount, a currency different from the workspace, and a tax rate
  3. Open the expense
  4. Update the tax rate to another non-zero tax rate
  5. Verify the tax amount and tax converted amount are negative
  6. Edit the tax rate
  7. Verify the tax change system message shows the previous tax as negative
  8. Unreport the expense
  9. Open self DM and open the unreported expense
  10. Verify the tax amount is still negative

B.

  1. Create expense A with a negative amount
  2. Open the expense
  3. Change the tax rate to 5%
  4. Create expense B with a positive amount and a 0% tax rate
  5. Open the report
  6. Bulk select both expenses
  7. Press More > Merge
  8. Select expense B amount, 5% rate, and any other details
  9. Press Continue
  10. Verify on the confirmation page that the tax amount isn't negative
  11. Merge the expenses
  12. Open the expense
  13. Verify the tax amount isn't negative

C.

  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. Go offline
  6. Bulk select both expenses
  7. Press More > Merge
  8. Select any detail and complete the merging process
  9. Open the merged expense
  10. Verify the tax amount field is negative

D.
Extra prerequisite:

  • Open Categories > Select a category > Create new rule > Apply expense defaults > 5% tax rate
  1. Create a positive amount expense in a WS chat without a category
  2. Go offline
  3. Set the category to Advertising
  4. Verify the tax amount is positive

E.

  1. Create an expense with a negative amount in a WS chat with a 0% tax rate
  2. Open the expense
  3. Press More > Split
  4. Press on any split
  5. Change the tax rate to a non-zero tax rate
  6. Press Save > Save the split
  7. Open the split with the non-zero tax rate.
  8. Verify the tax amount is negative

Also 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: replaced the TODO with your prerequisite and scenarios A–E, word for word.
  • Tests and Offline tests: set to "Same as QA Steps".

I kept the "Verify that no errors appear in the JS console" checkbox under Tests and QA Steps. Scenario C skips step 5 in your list, so GitHub renumbers that list when it renders.


view run

@bernhardoj

Copy link
Copy Markdown
Contributor

taxAmount: Math.abs(transactionDetails?.taxAmount ?? 0),

@MelvinBot to fix E, can we simply remove Math.abs? Looks like updatedItem contains the display amount and transactionDetails already have that.

Also, to fix D, can we update this

updatedTransaction.taxAmount = categoryTaxAmount;

to updatedTransaction.taxAmount = isFromExpenseReport || isUnReportedExpense ? -categoryTaxAmount : categoryTaxAmount;

…y tax rules

Co-authored-by: Bernhard Owen Josephus <bernhardoj@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

Both changes fix the reported case but flip the sign for the opposite case. I pushed sign-aware versions instead in 0c2bb95.

E (split): Removing Math.abs breaks a positive split whose tax wasn't changed. The edit draft's tax uses two sign conventions:

  • It keeps the split's displayed sign when copied from the split item.
  • It gets the opposite sign after the tax rate step.

If you only edit a positive split's description, getTransactionDetails flips its tax to negative. The fix takes the size from the draft and the sign from the split amount: SplitExpenseItems.ts:865-868.

D (category rule): getCategoryTaxDetails calculates tax from the absolute amount. Negating it fixes positive expenses but gives a negative expense a positive tax. The fix applies the displayed amount's sign first, then negates for expense reports and unreported expenses: getUpdatedTransaction.ts:413-418.

I added unit tests for positive and negative amounts in both flows. I couldn't run Jest, lint, or typecheck locally, so CI on this push is the first check.

Supporting evidence
  • Split items keep tax in displayed sign. Redistribute, even split, and amount edits all use calculateTaxAmount with the signed amount. MoneyRequestBuilder negates amount and tax together on submit.
  • initDraftSplitExpenseDataForEdit copies the split item's tax into the draft unchanged.
  • The tax rate step calculates tax from getAmount(draft, false, true), which returns the opposite sign. It writes that value through setDraftSplitTransaction.
  • The existing getUpdatedTransaction category test stores amount 100, which is a negative expense on an expense report, and expects tax 5. Your D change would make it -5, which displays as a positive tax.

view run

@MelvinBot

Copy link
Copy Markdown
Contributor Author

⚠️ MelvinBot CI Fix Loop Detected

MelvinBot has made 11 consecutive commits trying to fix CI failures. Automatic CI fix dispatches are now paused for this PR.

Next steps: A human should review the recent commits and resolve the conflicting CI errors manually.

@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.

Replace the Screenshots/Videos section with below

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
unreport.mp4
merge.1.mp4
web.mp4
merge.mp4
catg.mp4
spliot.mp4

Also, check all Verify that no errors appear in the JS console.

And can you investigate and find if there are any cases where the tax amount should be negative, but it currently isn't?

@MelvinBot

MelvinBot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor Author

I updated the PR description:

  • I replaced the PR Author Checklist and Screenshots/Videos sections with your text.
  • I checked both "Verify that no errors appear in the JS console" boxes.

I also found 5 cases where a negative expense still gets a positive tax. They share one cause: these flows compute or show the tax with Math.abs, then the stored tax is negated, so the sign ends up wrong. I confirmed cases 1 and 2 on Android. The other three come from reading the code.

# Case Now Evidence
1 Create flow: the confirmation page for a negative expense with tax A -$10 expense at 5% shows tax 0.48. In the code, the created expense also stores the tax with the wrong sign, so details would show it as positive. I couldn't confirm that part on Android, because a category rule reset the tax to 0%. useTaxAmount.ts:77, TaxFields.tsx:70, MoneyRequestBuilder.ts:1569
2 Tax amount page: editing the tax of a negative expense A tax of -$0.91 is prefilled as 0.91, and you can't enter a minus sign. Saving 0.40 shows $0.40 on details, and the system message says "changed the tax amount to $0.40 (previously -$0.91)". DynamicIOURequestStepTaxAmountPage.tsx:181, which has no sign toggle
3 Review duplicates: picking the other expense's tax rate The review tax is always positive, and confirming sends -reviewDuplicatesTaxAmount, so a negative expense gets a positive tax. Also new with this PR: the confirmation page now shows negative tax for positive duplicates. DynamicConfirmationPage.tsx:98, DynamicReviewTaxCodePage.tsx:80
4 Bulk edit from Search: changing the amount or tax rate The tax is computed from the absolute amount, so it shows as positive. BulkEdit.ts:331, BulkEdit.ts:376
5 Moving a taxed unreported expense to a workspace The draft uses Math.abs(taxAmount), which is then negated on create, so the tax shows as positive. useTaxAmount.ts:83
Android evidence (cases 1 and 2)

Confirmation page shows tax 0.48 for a -10 expense Tax amount page prefilled with 0.91 for a -0.91 tax Details show tax 0.40 after saving on a negative expense System message: changed the tax amount to 0.40 (previously -0.91)

I couldn't run the review duplicates case on Android. A category rule on the test workspace reset both duplicates to 0% tax before the review screen opened.

Smaller cases and what already works

Edge cases from the code:

  • Splitting an expense whose tax rate was later edited or deleted uses Math.abs(amount), so a negative split gets a positive tax (SplitExpenseItems.ts:323).
  • A category tax rule applied during create has the same cause as case 1.

Already correct:

  • Changing the tax rate on an existing expense, on both expense reports and unreported expenses
  • Editing the amount
  • Applying a category tax rule on edit
  • Duplicating an expense
  • Editing and saving splits
  • The merge flow
  • The Search and report table tax column
  • Report tax totals

Distance, per diem, invoices and split bills can't have a negative taxed amount.

The fix for all five cases is the same: compute and show the tax from the signed amount instead of Math.abs. On the Tax amount page, that means prefilling the signed value and allowing a negative input.

Reply @MelvinBot fix these on this PR if you'd like me to add the fixes here.


view run · view recording

@bernhardoj

Copy link
Copy Markdown
Contributor

@MelvinBot can you give reproduction steps for 3 and 4? 1, 2, and 5 should be handled separately on a different issue to allow the user to enter a negative tax amount on the IOU flow.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

Both cases reproduce on web, but only with offline (optimistic) data. Once you go back online, the server corrects the tax to negative. Case 3 also has an online bug that's visible on the confirmation page: a positive duplicate shows a negative tax there.

This corrects my earlier table, which implied the wrong sign was saved.

Precondition: a workspace with Taxes enabled and two non-zero rates (5% and 10%).

Note: Because of case 1, a new negative expense can start with a positive tax. Before each test, open the expense and set its tax rate on the details page so the tax reads negative.

Case 3: Review duplicates

A. Negative expense, offline (wrong saved sign)

  1. In the workspace chat, create expense A: -100, merchant "Dup", today, 5% tax.
  2. Create expense B with the same amount, merchant, and date, and 10% tax. Wait for both to show "Potential duplicate".
  3. Open expense A and confirm the tax amount is negative (-4.76).
  4. Go offline.
  5. Press Review duplicates, keep expense A, pick the 10% rate on the tax step, and confirm.
  6. Open the kept expense. Bug: the tax amount is $9.09. Expected: -$9.09.
  7. Go online. The tax changes to -$9.09.

B. Positive expense, online (wrong confirmation page)

  1. Repeat steps A1–A2 with +100.
  2. Press Review duplicates, keep the 5% expense, and pick the 10% rate.
  3. Bug: the confirmation page shows the tax as -$9.09. After you confirm, the saved expense shows $9.09, which is correct.
Screenshots

Offline: kept duplicate shows tax 9.09 for a -100 expense Online: tax corrected to -9.09 Review duplicates confirmation shows -9.09 tax for a +100 expense

Cause: DynamicReviewTaxCodePage.tsx:80 calculates the tax from getAmount(transaction), which is always positive. The confirmation page shows that value in the stored sign, so it always reads negative. DynamicConfirmationPage.tsx:98 then saves -tax, so the saved tax always reads positive.

Case 4: Bulk edit from Search (offline)

  1. In the workspace chat, create two expenses, -50 and -80, with 5% tax. Confirm each tax reads negative (-2.38 and -3.81).
  2. Go offline.
  3. Go to Reports > Expenses, select both, press Edit multiple, set the tax rate to 10%, and save.
  4. Open each expense. Bug: the tax amounts are $4.55 and $7.27. Expected: negative.
  5. While still offline, select both again, press Edit multiple, change only Amount to -60, and save.
  6. Open each expense. Bug: both tax amounts are $5.45.
  7. Go online. Both change to -$5.45.
Screenshots

Offline: bulk edit tax rate, -80 expense shows tax 7.27 Offline: bulk edit amount to -60, tax shows 5.45 Online: tax corrected to -5.45

Cause: BulkEdit.ts:331 and BulkEdit.ts:376 calculate the tax from Math.abs(amount). getUpdatedTransaction treats that as the displayed tax, so the optimistic tax is always positive.


view run

@MelvinBot

Copy link
Copy Markdown
Contributor Author

⏱️ Ran out of time before I could finish. This usually means the task was too complex or I got stuck exploring. Please try again with a more specific request or post in #melvinbot-ai.

Run details

@bernhardoj

Copy link
Copy Markdown
Contributor

@MelvinBot fix both cases 3 and 4

…ulk edit

Review duplicates calculated the tax from the absolute amount, so the
confirmation page showed a negative tax for positive expenses and the
optimistic tax of a negative expense became positive. Calculate it from
the stored amount so it matches the stored tax sign.

Bulk edit calculated the tax from the absolute amount, so a negative
expense got a positive optimistic tax. Use the displayed amount instead.

Co-authored-by: Bernhard Owen Josephus <bernhardoj@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 I added cases 3 and 4 to the QA Steps as new scenarios after E:

  • F: review duplicates for a negative expense while offline. The tax stays negative on the confirmation page, on the kept expense, and after you go back online.
  • G: review duplicates for a positive expense while online. The tax stays positive on the confirmation page and on the kept expense.
  • H: bulk edit with Edit multiple while offline. The tax stays negative after you change the tax rate, and again after you change only the amount.

F and H each have an extra prerequisite: two non-zero tax rates, for example 5% and 10%. The rest of the description is unchanged.

The amount-only step in H (step 10) has a unit test but hasn't been confirmed in the UI yet. In the last web run, entering -60 saved as +60. Typing "-" in that field switches the sign, so check that the amount reads negative before you save.


view run

@bernhardoj

Copy link
Copy Markdown
Contributor

@MelvinBot mark it as ready for review

@MelvinBot
MelvinBot marked this pull request as ready for review October 19, 2026 08:27
@MelvinBot
MelvinBot requested a review from a team as a code owner October 19, 2026 08:27
@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 This PR is now marked as ready for review.

The Tests and QA Steps sections in the PR body are still TODO placeholders. Please fill them in before review, or the PR Author Checklist check will keep failing.


view run

@melvin-bot
melvin-bot Bot requested review from bernhardoj and removed request for a team October 19, 2026 08:27
@melvin-bot

melvin-bot Bot commented Oct 19, 2026

Copy link
Copy Markdown

@bernhardoj 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 requested review from JmillsExpensify and removed request for a team October 19, 2026 08:27
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 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-19T08:34:58.047287Z cfad553 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 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • 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 verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • 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).
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari
unreport.mp4
merge.1.mp4
web.mp4
merge.mp4
catg.mp4
spliot.mp4
bulk.edit.mp4
dupe.positive.mp4
dupe.neg.mp4

@bernhardoj

Copy link
Copy Markdown
Contributor

Still need to wait for this BE issue to be fixed.

@grgia also, there is another BE issue when splitting expenses. The reproduction steps are in the QA Steps case E. When we open the split expense page and edit one of the expenses' tax rates, the BE then returns the previous/old tax rate.

spliot.mp4

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cfad55344e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

if (categoryTaxCode && categoryTaxAmount !== undefined && categoryTaxValue) {
// The category tax is calculated from the absolute amount, so give it the sign of the displayed amount,
// then store it with the opposite sign on expense reports and unreported expenses, the same as the amount.
const isNegativeAmount = getAmount(transaction, isFromExpenseReport, isUnReportedExpense) < 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Base the category-tax sign on the edited amount

When a bulk edit changes both the amount's sign and the category, and the new category has a default tax rule, this reads the original transaction amount to choose the tax sign. For example, changing a positive expense to a negative amount while assigning such a category leaves the optimistic tax positive (and the reverse transition leaves it negative), so the expense displays an amount and tax with opposite signs while offline or until the server response arrives. Use transactionChanges.amount when present before falling back to the current displayed amount.

Useful? React with 👍 / 👎.

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 can you check this and fix it

@MelvinBot MelvinBot Oct 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Codex is right. I pushed a fix in 59ec093.

The category tax now uses the edited transaction instead of the original one (getUpdatedTransaction.ts:411-416). This fixes the sign. It also fixes the tax size, which was calculated from the old amount when the amount changed in the same edit.

I added a unit test for both sign flips. I couldn't run Jest, lint, or typecheck locally, so CI on this push is the first check.

On web, I bulk-edited a +$100 expense offline to -$100 with a 5% category rule. The tax amount showed -$4.76 offline and stayed -$4.76 after going online.
Offline after bulk edit: amount -100, tax amount -4.76

Other notes
  • Edit multiple only appears when 2 or more expenses are selected, so the test edited both expenses.
  • After going online, the system message said "the tax amount to $4.76" with no minus sign, while the field showed -$4.76. That message came from the server, so this fix doesn't change it.

view run · view recording

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 can you add this to a new QA Steps test case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🤖 I added this to the QA Steps as case I, after H. It covers both sign flips, offline, with Edit multiple:

  • Positive to negative, with the category that has the 5% tax rule: the tax amount is negative.
  • Negative to positive, with the same category: the tax amount is positive.
  • After you go online, all 4 expenses keep a tax sign that matches their amount.

It reuses D's category rule as its prerequisite. The rest of the description is unchanged.

I confirmed only the positive-to-negative flip in the UI, in my last web run. A unit test covers the negative-to-positive flip, but no one has checked it in the UI yet.


view run

Co-authored-by: Bernhard Owen Josephus <bernhardoj@users.noreply.github.com>
@MelvinBot
MelvinBot requested a review from a team as a code owner October 19, 2026 09:44
@melvin-bot
melvin-bot Bot requested review from grgia and removed request for a team October 19, 2026 09:44
@melvin-bot

melvin-bot Bot commented Oct 19, 2026

Copy link
Copy Markdown

@grgia 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]

@JmillsExpensify JmillsExpensify 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.

No product review required on these. All fixes.

@grgia

grgia commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

@bernhardoj could you help me to outline the BE issues we need to file? Im going to find someone to take lead on these tax issues from the BE

@bernhardoj

Copy link
Copy Markdown
Contributor

@grgia
BE issue:

  1. Create an expense with a negative amount in a WS chat with a 0% tax rate
  2. Open the expense
  3. Press More > Split
  4. Press on any split
  5. Change the tax rate to a non-zero tax rate
  6. Press Save > Save the split
  7. Open the expense with the non-zero tax rate

Optimistically, the tax rate is updated, but the BE (Transaction_Split) then returns the previous/old tax rate.

@hoangzinh

Copy link
Copy Markdown
Contributor

Hey @bernhardoj @grgia I’m addressing an issue with a duplicate negative expense here: #103727.

My question is: Considering the work we’re doing here, what do you expect the taxAmount to be when a user submits a negative expense with a non-zero tax?

Screen.Recording.2026-10-21.at.17.35.17.mov

Is taxAmount -$0.48 or $0.48

@bernhardoj

bernhardoj commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

@hoangzinh it should be -$0.48, but it's an existing bug. The tax input currently can't accept a negative amount, and we don't handle it in this PR. If you want to have a negative tax amount, you can change the tax rate later on the expense report.

@bernhardoj

Copy link
Copy Markdown
Contributor

@MelvinBot please merge with main and fix the conflict

…eTaxAmount

Co-authored-by: Bernhard Owen Josephus <bernhardoj@users.noreply.github.com>

# Conflicts:
#	src/pages/TransactionDuplicate/DynamicReviewTaxCodePage.tsx
#	tests/unit/ReportUtilsTest.ts
@MelvinBot

Copy link
Copy Markdown
Contributor Author

I merged main into this branch and fixed the conflicts in d7a44a3.

  • DynamicReviewTaxCodePage.tsx: kept main's version without useMemo/useCallback and applied this PR's change, which calculates the tax from the stored amount.
  • ReportUtilsTest.ts: kept both new describe blocks: this PR's tax amount tests and main's clock skew tests.

I couldn't run typecheck or Jest here because of a local tooling problem, so CI will be the first check.


view run

Comment on lines +461 to +462
const taxAmount = convertToDisplayString(normalizeTaxAmountSign(reportActionOriginalMessage?.taxAmount, true), currency);
const oldTaxAmount = convertToDisplayString(normalizeTaxAmountSign(reportActionOriginalMessage?.oldTaxAmount, true), currency);

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.

Blocks

an employee who edits a split's tax amount sees the new and previous tax shown as negative on a positive split.

UpdateSplitTransaction.cpp:800 sends abs() tax amounts in the split message, and normalizeTaxAmountSign(x, true) negates them. should the Auth side send the stored sign first, before this lands?

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.

@grgia yes please

This branch has not been deployed

No deployments
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