Skip to content

Keep the sign of tax amounts in the modified expense system message - #103712

Closed
MelvinBot wants to merge 3 commits into
mainfrom
claude-negativeTaxAmountSystemMessage
Closed

MelvinBot wants to merge 3 commits into
mainfrom
claude-negativeTaxAmountSystemMessage

Conversation

@MelvinBot

Copy link
Copy Markdown
Contributor

Explanation of Change

The "changed the tax amount to X (previously Y)" system message ran both tax amounts through Math.abs(). So on a negative expense, the previous tax amount showed as positive.

That Math.abs() was written when tax amounts were always shown as positive. Since #102175, the expense details page shows the signed tax amount, so the message and the page disagreed.

This PR removes getTaxAmountAbsValue and formats taxAmount and oldTaxAmount with their sign, the same way the amount message already does. The optimistic action already stores both values with the display sign (ReportUtils.ts sets oldTaxAmount from getTaxAmount(oldTransaction, isFromExpenseReport)).

Reviewer note: I couldn't check the backend's MODIFIED_EXPENSE originalMessage from App code. Please confirm the server sends oldTaxAmount/taxAmount with the display sign, as it does for oldAmount/amount. If it sends the stored (inverted) sign, the message will flip after the server response.

Fixed Issues

$ #103702
PROPOSAL: #103702 (comment)

Tests

// TODO: The human co-author must fill out the tests you ran before marking this PR as "ready for review"
// Please describe what tests you performed that validates your changed worked.

  • Verify that no errors appear in the JS console

Offline tests

QA Steps

// TODO: The human co-author must fill out the QA tests you ran before marking this PR as "ready for review".
// Please describe what QA needs to do to validate your changes and what areas do they need to test for regressions.

  • 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

Co-authored-by: Georgia Monahan <grgia@users.noreply.github.com>
@MelvinBot
MelvinBot requested a review from a team October 12, 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 12, 2026
@MelvinBot

MelvinBot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Web test steps verification results: ❌ fail

The PR's Tests section is still a TODO, so I ran the reproduction steps from the linked issue. Creating the negative expense and editing the tax rate and tax amount all worked, but the system message shows the signs reversed: "changed the tax amount to -$2.00 (previously $4.76)" instead of "changed the tax amount to $2.00 (previously -$4.76)". This matches the PR's reviewer note: the server likely sends oldTaxAmount/taxAmount with the stored (inverted) sign.
Transaction thread showing the tax amount change system message

Step Status
Create a manual expense with a negative amount (-100) in the workspace chatAmount field read back as -100 before creation. The expense appeared in the chat as "...Workspace owes ($100.00)".
Create expense form with amount -100 entered
Expense created message showing workspace owes ($100.00)
✅
Opening the created expense shows the expense details pageDetails page showed Amount -$100.00, Merchant, Category, Tax, and Tax amount fields.
Expense details page
✅
Editing Tax to a non-default rate (5%) saves, and Tax amount shows negativeTax changed to "Tax Rate 1 (5%)". Tax amount updated to -$4.76.
Tax set to 5%, Tax amount shows -$4.76
✅
Editing Tax amount to a positive amount (2) savesInput read back as 2 before save. After save, Tax amount showed $2.00.
Tax amount field showing $2.00 after edit
✅
System message shows the new tax amount positive and the previous tax amount negativeObserved: "changed the tax amount to -$2.00 (previously $4.76)". Both signs are reversed, and the new value disagrees with the $2.00 shown on the details page.
Transaction thread showing the tax amount change system message
❌
No JS console errors related to this flowNo error UI appeared. All related API calls (UpdateMoneyRequestTaxRate, UpdateMoneyRequestTaxAmount, RequestMoney) returned 200. Direct console capture isn't supported on web, so this is based on network and UI only.
✅

view run · view recording

@MelvinBot

MelvinBot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Android test steps verification results: ❌ fail

The PR's Tests section is still a TODO, so I ran the reproduction steps from the linked issue. As on Web, the system message shows both signs reversed: "changed the tax amount to -$2.00 (previously $4.76)" instead of "changed the tax amount to $2.00 (previously -$4.76)". The text stayed the same after reopening the report, so the wrong sign comes from the saved data, not just the optimistic update.
Same inverted-sign system message after reopening the report

Step Status
Create a manual expense with a negative amount (-100) in the workspace chatThe Amount field accepted -100. The chat preview showed "Test Merchant, -$100.00".
Amount field showing -100 in the manual expense form
Workspace chat showing created expense -$100.00
✅
Opening the created expense shows the expense details pageThe details page showed Amount, Merchant, Date, Category, Tax, Tax amount, Reimbursable, and Report fields.
Expense details page for the -$100.00 expense
✅
Editing Tax to a non-default rate (5%) saves, and Tax amount shows negativeTax showed "Tax Rate 1 (5%)" and Tax amount showed -$4.76.
Tax amount showing -$4.76 after selecting the 5% tax rate
✅
Editing Tax amount to a positive amount (2) savesAfter saving 2, the Tax amount field showed $2.00.
✅
System message shows the new tax amount positive and the previous tax amount negativeObserved: "changed the tax amount to -$2.00 (previously $4.76)". Both signs are reversed. The text was the same right after saving and after reopening the report.
System message right after saving: changed the tax amount to -$2.00 (previously $4.76)
Same inverted-sign system message after reopening the report
❌
No JS errors or red boxes appear during the flowNo red box or error dialog appeared, and the app stayed in the foreground. Metro log streaming was off, so console warnings were not captured.
✅

view run · view recording

@grgia grgia assigned bernhardoj and unassigned grgia Oct 12, 2026
@grgia
grgia self-requested a review October 12, 2026 12:05
@grgia
grgia marked this pull request as ready for review October 12, 2026 12:05
@grgia
grgia requested a review from a team as a code owner October 12, 2026 12:05
@melvin-bot
melvin-bot Bot requested review from bernhardoj and trjExpensify and removed request for a team October 12, 2026 12:05
@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-12T12:12:30.946238Z 2752542 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.

@melvin-bot
melvin-bot Bot removed the request for review from a team October 12, 2026 12:05
@melvin-bot

melvin-bot Bot commented Oct 12, 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]

Comment thread src/libs/ModifiedExpenseMessage.ts Outdated
const oldTaxAmountValue = getTaxAmountAbsValue(reportActionOriginalMessage?.oldTaxAmount ?? 0);
const oldTaxAmount = convertToDisplayString(oldTaxAmountValue, currency);
const taxAmount = convertToDisplayString(reportActionOriginalMessage?.taxAmount ?? 0, currency);
const oldTaxAmount = convertToDisplayString(reportActionOriginalMessage?.oldTaxAmount ?? 0, 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.

@MelvinBot We need to use getTaxAmount here. Since tax is only available on an expense report, then we can always pass true for isFromExpenseReport.

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.

Done in b723726. The message now converts both tax amounts with getTaxAmount(..., true) (ModifiedExpenseMessage.ts:469-470). This matches the Web test above, where the server's values rendered as "to -$2.00 (previously $4.76)".

Two related changes:

  • Optimistic action: it now stores both values with the stored sign, like the server, so the message doesn't flip after the response (ReportUtils.ts:7030-7032).
  • getTaxAmount type: it now accepts Pick<Transaction, 'taxAmount'>, so we can pass the report action's values without a full transaction (TransactionUtils/index.ts:552). Existing callers are unchanged.

I updated the unit test to use stored-sign values and added a test for the optimistic action. Typecheck, lint, and the related Jest suites pass. I didn't re-run the Web test, and the PR description's Explanation section still describes the old approach.


view run

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 oh, can we use the normalizeTaxAmount instead?

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.

Done in 25c63d8. The message now calls normalizeTaxAmountSign(..., true) on both tax amounts directly (ModifiedExpenseMessage.ts:469-470).

To do this, I exported normalizeTaxAmountSign from TransactionUtils (index.ts:1843). I also reverted the Pick<Transaction, 'taxAmount'> change to getTaxAmount, since it's no longer needed. The output is the same, and the optimistic action change is unchanged.

Typecheck and the ModifiedExpenseMessage and TransactionUtils Jest suites pass. ESLint shows no new errors on the changed lines.


view run

…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>
@MelvinBot
MelvinBot requested a review from a team as a code owner October 12, 2026 13:27
@melvin-bot
melvin-bot Bot requested review from bernhardoj and removed request for a team October 12, 2026 13:27
@melvin-bot

melvin-bot Bot commented Oct 12, 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]

…e system message

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

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

Reviewer note: I couldn't check the backend's MODIFIED_EXPENSE originalMessage from App code. Please confirm the server sends oldTaxAmount/taxAmount with the display sign, as it does for oldAmount/amount. If it sends the stored (inverted) sign, the message will flip after the server response.

Did @grgia look into that for you to confirm?

@grgia

grgia commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

the server sends the stored (inverted) sign for both tax amounts and the latest version already handles it, so the message won't flip after the response.

@bernhardoj bernhardoj closed this Oct 19, 2026
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.

4 participants