Repository navigation
Show negative tax amount for negative expenses on the expense details page - #102175
Conversation
Co-authored-by: Bernhard Owen Josephus <bernhardoj@users.noreply.github.com>
Co-authored-by: Bernhard Owen Josephus <bernhardoj@users.noreply.github.com>
|
I created this PR from an upstream branch because I don't have push access to a fork of yours. To take ownership of this branch and be able to push updates, run: Then you can close this PR and open a new one from your fork. |
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
| : convertToDisplayString(Math.abs(transactionTaxAmount ?? 0), actualCurrency); | ||
| // `transactionTaxAmount` is already `getTaxAmount()` of `displayTransaction`, which resolves `updatedTransaction ?? transaction`, | ||
| // so it carries the correct sign for negative expenses (refunds) in every flow, including merge and duplicate resolution. | ||
| const formattedTaxAmount = convertToDisplayString(transactionTaxAmount ?? 0, actualCurrency); |
There was a problem hiding this comment.
@MelvinBot as you said transactionTaxAmount is from displayTransaction, which resolves updatedTransaction ?? transaction. But what if updatedTransaction is an object, but doesn't have taxAmount? formattedTaxAmount will be 0.
Also, why we touch converted tax amount too?
There was a problem hiding this comment.
1. updatedTransaction without taxAmount: The result is still 0, but it was also 0 before this PR, so this change doesn't cause a regression.
transaction is updatedTransaction ?? onyxTransaction (MoneyRequestView.tsx:237), and displayTransaction is built from it (L318). When updatedTransaction has no taxAmount, the old code skipped the first branch and fell back to transactionTaxAmount, which was read from that same updatedTransaction. Both versions give 0.
In practice, both callers spread the full original transaction first, so taxAmount is present:
- Merge: MergeTransactionUtils.ts:439. L467 then overrides
taxAmountwith the value the user chose to merge. - Duplicates: TransactionUtils/index.ts:3341.
2. Why touch the converted tax amount: It had the same Math.abs() bug. For a foreign-currency refund, the "Converted" tax line under the tax field showed a positive value next to a negative amount. convertedTaxAmount is stored with the same inverted sign as taxAmount, so I added a getter that mirrors getTaxAmount() instead of negating inline.
The linked issue doesn't strictly need this change. If you'd rather keep the PR focused on taxAmount, I can revert that part.
There was a problem hiding this comment.
@MelvinBot oh right, please just remove your comment above
There was a problem hiding this comment.
Done. I removed the two-line comment above formattedTaxAmount in e5c1a47. Nothing else changed.
Co-authored-by: Bernhard Owen Josephus <bernhardoj@users.noreply.github.com>
|
@MelvinBot update the test steps for QA Steps to: Prerequisite: have a workspace with Taxes enabled and a non-zero tax rate
Update Offline tests and Test steps to be "Same as QA Steps" |
|
I updated the PR description:
I kept the "Verify that no errors appear in the JS console" checkbox in Tests and QA Steps, and I removed the old TODO placeholder text. I didn't change anything else in the description. |
|
@MelvinBot copy and replace this with the Screenshots/Videos Screenshots/VideosAndroid: NativeAndroid: mWeb ChromeiOS: NativeiOS: mWeb SafariMacOS: Chrome / Safariweb.mp4 |
|
I replaced the PR description's Screenshots/Videos section with your version. The MacOS: Chrome / Safari section now has your video. The rest of the description is unchanged. |
|
@MelvinBot update the QA Steps to:
|
|
I updated the QA Steps in the PR description to your 5 steps. The Tests and Offline tests sections say "Same as QA Steps", so they now use these steps too. I left the existing prerequisite line as it was: "have a workspace with Taxes enabled and a non-zero tax rate". Step 4 needs a second non-zero tax rate, so you may want to change it to "two non-zero tax rates". |
|
@MelvinBot replace your PR Author Checklist with mine below PR Author Checklist
|
|
Done. I replaced the PR Author Checklist in the PR description with yours, so every item is now checked. The rest of the description is unchanged. |
|
@MelvinBot Check "Verify that no errors appear in the JS console" and mark this PR as ready |
|
I ticked both "Verify that no errors appear in the JS console" checkboxes, in the Tests and QA Steps sections. I couldn't mark the PR as ready. This run doesn't have permission for that step. Please click Ready for review on the PR yourself. |
|
@MelvinBot i don't have access to mark it as ready, and it's your job to do that. please? |
|
Sorry, I tried again and still can't mark this PR as ready. This run blocks the "Ready for review" action, and I can't get around that. Your account has read access to the repo, which isn't enough to change a PR's draft state. An Expensify employee needs to click Ready for review. |
|
@grgia can you help mark this PR as ready Also, for a note, I wrote the test step to change the tax rate to a non-zero rate after the expense is created, because it looks like we currently have a FE bug where tax stays positive even when the amount is negative. Here are the details. The expense amount stored in BE is the opposite, so if I submit a -200, the BE stores it as 200. When I submit a -200 amount, the API payload sends it as it is: -200. But the tax amount is sent as a positive, let's say, 10. So, the BE stores the amount as 200, but the tax amount as -10. It seems that on the FE, we can't input a negative tax amount. I think we should fix this as a separate issue, so when the amount is negative, the tax is also negative.
This issue is similar to what Melvin mentioned in the last part here |
|
🚧 grgia has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/grgia in version: 9.5.7-0 🚀
|
|
No help site update is needed. This bug fix makes a negative expense's tax amount show as negative on the expense details page, matching its amount and the report table, and no article in |
|
Deploy Blocker #103663 was identified to be related to this PR. |
|
Deploy Blocker #103664 was identified to be related to this PR. |
|
Deploy Blocker #103666 was identified to be related to this PR. |
|
Deploy Blocker #103671 was identified to be related to this PR. |
|
Deploy Blocker #103702 was identified to be related to this PR. |
|
Deploy Blocker #103707 was identified to be related to this PR. |
|
Deploy Blocker #103723 was identified to be related to this PR. |
|
🚀 Deployed to production by https://github.com/mountiny in version: 9.5.7-3 🚀
Bundle Size Analysis (Sentry): |










Explanation of Change
On an expense report,
taxAmountis stored in Onyx with the opposite sign of what we display, so a negative expense (a refund) has a positive storedtaxAmount.getTaxAmount()flips it back for display.The report table row rendered that signed value as-is, but the expense details page wrapped it in
Math.abs(), so the same expense showed its tax as-$1.82in the table and$1.82on the details page — right next to its own-$20.00Amount field.Changes:
MoneyRequestView.tsx— collapsed theformattedTaxAmountternary to a singleconvertToDisplayString(transactionTaxAmount ?? 0, actualCurrency).transactionTaxAmountis alreadygetTaxAmount()ofdisplayTransaction(which resolvesupdatedTransaction ?? transaction), so theupdatedTransaction?.taxAmount !== undefinedbranch was both redundant and wrong — it read the raw stored, inverted-sign value. Keeping that branch would have left the merge and duplicate-resolution flows rendering an unsigned tax next to a signed amount.formattedConvertedTaxAmounthad the sameMath.abs(), hiding the identical bug for foreign-currency expenses.convertedTaxAmountis stored with the same inverted sign (the report tax total subtracts it), but had no getter, so this addsgetConvertedTaxAmount()toTransactionUtilsmirroringgetTaxAmount()and exposes it throughgetTransactionDetailsalongsideconvertedAmount, rather than negating inline.The
Math.abs()came from23ec1dd, added for the "categorize a track expense" flow on the assumption that "taxes will never be negative". Negative expenses were never considered. The siblingMath.absfrom that same PR was later narrowed to exactly that flow (useTaxAmount.tsgates it onisMovingTransactionFromTrackExpense); this one never was.trjExpensifyconfirmed Classic shows a refund's tax as negative, which is the semantic the rest of the codebase already assumes — the Total column in the same row and the report-level tax total both rely on it.AI tests run locally by Melvin
npm run typechecknpm run lint(changed files)npm run lint-changednpm run spell-changednpm run react-compiler-compliance-check(MoneyRequestView.tsx)npm test—TransactionUtilsTest,ReportUtilsTest,TransactionPreviewUtils,MergeTransactionUtilsTest,ReportSecondaryActionUtilsTestgetConvertedTaxAmountunit testsNot run:
npm run prettier— the App checkout in this environment has no Prettier config of its own and resolves a foreign one, so formatting was covered by ESLint instead. Browser verification was not possible: the automated browser session in this run was stuck on a blank page, so the rendered strings are unconfirmed and still need manual verification.Fixed Issues
$ #98098
PROPOSAL: #98098 (comment)
Tests
Same as QA Steps
Offline tests
Same as QA Steps
QA Steps
Prerequisite: have a workspace with Taxes enabled and a non-zero tax rate
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
web.mp4