Skip to content

fix: Clean-up some tax related bugs#94007

Open
dmkt9 wants to merge 9 commits into
Expensify:mainfrom
dmkt9:fix/94003-clean-up-some-tax-related-bugs
Open

fix: Clean-up some tax related bugs#94007
dmkt9 wants to merge 9 commits into
Expensify:mainfrom
dmkt9:fix/94003-clean-up-some-tax-related-bugs

Conversation

@dmkt9

@dmkt9 dmkt9 commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

This PR cleans up several tax display and editability issues by distinguishing between user-customized tax codes and platform/default tax identifiers.

A new isTaxCodeCustomized() helper was added to PolicyUtils. It treats a tax code as user-customized only when its tax rate has a non-empty previousTaxCode, which lets the UI avoid exposing internal platform default tax IDs.

Report table tax behavior was updated so Per Diem expenses no longer show tax name, tax code, or tax amount values. Tax code cells are now also hidden unless the tax code was actually customized by the user.

Search/report table column visibility was tightened so tax-related columns are not shown by default only because a transaction contains tax metadata. Tax rate, tax amount, and tax code columns now appear only when the user explicitly selects/customizes those columns.

Workspace tax editing was adjusted so default tax rates can still have their Name, Value, and Tax Code fields edited when the user has write access. The stricter canEditTaxRate permission remains used only for disabling or deleting tax rates, which preserves the existing restriction for protected/default rates while allowing field edits.

The workspace tax code editor now shows an empty input for non-customized/default tax codes instead of pre-filling internal platform IDs, and saving behavior was updated so users can replace those defaults with their own tax code.

Unit coverage was added for isTaxCodeCustomized() to verify that missing policies, missing tax codes, unknown tax rates, empty previousTaxCode, and customized tax codes are handled correctly.

Fixed Issues

$ #94003
PROPOSAL:

Tests

Same as QA steps

  • Verify that no errors appear in the JS console

Offline tests

Same as QA steps

QA Steps

Test 1:

  1. Create a workspace
  2. Enable Taxes
  3. Enable Per Diem > Add the per diem rates
  4. Create a normal expense with tax
  5. Create a per diem expense
  6. Go to the Spend > Expenses table. Enable the Tax rate and Tax column
  7. Verify that the Tax columns are empty
  8. Open the report
  9. Verify that the Tax columns are empty

Test 2:

  1. Create a workspace
  2. Enable Taxes
  3. Click on the default rate
  4. Verify that The Name, Value and Tax Code fields are editable

Test 3:

  1. Create a new account
  2. Create a workspace
  3. Enable taxes
  4. Create two expenses with tax
  5. Go to Spend > Expenses
  6. Observe no tax columns are in the table
  7. Open the expense report
  8. Verify that no tax columns are automatically added to the table

Test 4:

  1. Create a workspace.
  2. Enable Taxes and navigate to the Taxes page.
  3. Create two new tax rates (e.g., Tax A and Tax B).
  4. Open Tax A.
  5. Verify that the Tax Code field is empty.
  6. Click the Tax Code field, enter any value, and save the changes.
  7. Verify that the Tax Code field now contains a value.
  8. Create a couple of expenses using Tax A and Tax B.
  9. Navigate to Spend > Expenses.
  10. Enable the Tax Code column.
  11. Verify that the Tax Code column displays a value for expenses using Tax A, and is empty for expenses using Tax B.
  12. Open the report containing those expenses.
  13. Enable the Tax Code column.
  14. Verify that the Tax Code column displays a value for expenses using Tax A, and is empty for expenses using Tax B.
  • Verify that no errors appear in the JS console

PR Author Checklist

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

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
Test.1.mp4
Test.2.mp4
Test.3.mp4

@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/libs/PolicyUtils.ts 77.15% <100.00%> (-0.08%) ⬇️
src/libs/SearchUIUtils.ts 63.77% <100.00%> (+0.01%) ⬆️
...ents/TransactionItemRow/TransactionItemRowWide.tsx 94.87% <75.00%> (-0.82%) ⬇️
src/pages/workspace/taxes/WorkspaceTaxCodePage.tsx 0.00% <0.00%> (ø)
src/pages/workspace/taxes/WorkspaceEditTaxPage.tsx 0.00% <0.00%> (ø)
... and 15 files with indirect coverage changes

@dmkt9

dmkt9 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@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: 3469e8939f

ℹ️ 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".

Comment thread src/components/TransactionItemRow/TransactionItemRowWide.tsx
@dmkt9

dmkt9 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@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: c7106d2110

ℹ️ 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".

Comment thread src/libs/PolicyUtils.ts
@dmkt9

dmkt9 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@MelvinBot review

@MelvinBot

Copy link
Copy Markdown
Contributor

Review

The four fixes map cleanly to the four bugs in #94003, and I like how the canEditTaxRate split (WorkspaceEditTaxPage.tsx:50-51) cleanly separates "edit a field" from "disable/delete a protected default rate" — that's the right fix for bug 2. Per-diem guards (bug 1) and the customResult gating in SearchUIUtils (bug 3) also look correct.

My one real concern is the reliability of the previousTaxCode signal that isTaxCodeCustomized() depends on — this should be confirmed with the backend before merge.

previousTaxCode looks like a client-only optimistic marker

isTaxCodeCustomized() treats a tax code as user-customized only if its rate has a non-empty previousTaxCode (PolicyUtils.ts:2802-2809). But in the App codebase previousTaxCode is written in exactly one place — the optimistic branch of setPolicyTaxCode (TaxRate.ts:591). The UpdatePolicyTaxCode command doesn't send it, the successData handler doesn't re-derive it, and nothing populates it from an OpenApp/ReconnectApp/OpenPolicyTaxesPage response. It only survives locally because Onyx MERGE keeps unmentioned keys.

If the backend does not echo previousTaxCode in the taxRates payload, then a genuinely customized tax code will have no previousTaxCode after a fresh login, on another device, or for any other workspace member — so isTaxCodeCustomized() returns false and:

This would reproduce as: run PR Test 4, then hard-refresh / log in on a second device and re-check step 11-14 — the Tax A code likely disappears again.

⚠️ I couldn't verify the backend directly (no read access to the serializer that builds the taxRates object). Please confirm whether the backend persists and returns previousTaxCode. If it doesn't, this needs a persistent signal instead (e.g. a server-provided "code" vs auto-generated external-ID distinction) rather than the optimistic field.

Secondary question: integration / imported tax codes

previousTaxCode means "the user renamed this code," which is narrower than "this is a meaningful, non-platform-default code." Tax codes synced from an accounting integration (QBO/Xero/NetSuite) carry real external IDs but were never renamed in-app, so they'd have no previousTaxCode and would be treated as non-customized — hidden from the column and blanked on the edit page for Control policies. Worth confirming this doesn't regress connected workspaces, since the old taxCodeToShow showed the code for any Control policy.

Minor nits (non-blocking)
  • PolicyUtils.ts:2807: policy?.taxRates — the ?. on policy is redundant since !policy is already guarded on the line above; policy.taxRates reads cleaner.
  • TransactionItemRowWide.tsx:26: import {isTaxCodeCustomized, getTagGLCode} isn't alphabetized — lint may flag the import order.
  • The unit test only covers the three previousTaxCode states. Consider adding a case asserting behavior when the rate exists but taxRates.taxes is undefined, and (once the persistence question is settled) a comment documenting that previousTaxCode is expected to persist.

I confirmed empty codes can't be saved — validateTaxCode requires the field (TaxRate.ts:60) — so the new empty defaultValue for non-customized codes is safe.


🤖 Generated with MelvinBot · Reply with @MelvinBot <feedback> to refine this review.

@dmkt9

dmkt9 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@MelvinBot Yes. The backend persists and returns previousTaxCode.

@MelvinBot

Copy link
Copy Markdown
Contributor

Thanks for confirming — that clears my main concern. If the backend persists and returns previousTaxCode on OpenApp/ReconnectApp/OpenPolicyTaxesPage, then isTaxCodeCustomized() is reliable across reloads, devices, and other workspace members, and the whole approach holds. ✅

That leaves just the smaller items, none blocking:

  1. Integration-synced tax codes — a code imported from QBO/Xero/NetSuite carries a real external ID but was never renamed in-app, so it has no previousTaxCode and would be treated as non-customized (hidden from the column, blank on the edit page for Control policies). Worth a quick sanity check that connected workspaces still show their real tax codes — but if the backend seeds previousTaxCode for imported codes too, this is a non-issue.
  2. Nits (optional): redundant policy?. after the !policy guard in isTaxCodeCustomized, and the non-alphabetized {isTaxCodeCustomized, getTagGLCode} import in TransactionItemRowWide.tsx (lint may flag it).

Otherwise the PR looks good to me — the four fixes map cleanly to the four bugs. 👍

@dmkt9 dmkt9 marked this pull request as ready for review July 7, 2026 02:57
@dmkt9 dmkt9 requested review from a team as code owners July 7, 2026 02:57
@melvin-bot melvin-bot Bot requested review from trjExpensify and truph01 and removed request for a team July 7, 2026 02:57
@melvin-bot

melvin-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

@truph01 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 July 7, 2026 02:57
@dmkt9

dmkt9 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

While we're waiting for the backend fix (#94003 (comment)), I think it would be good for @truph01 to review this PR in parallel.

@dmkt9

dmkt9 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author
  • Integration-synced tax codes — a code imported from QBO/Xero/NetSuite carries a real external ID but was never renamed in-app, so it has no previousTaxCode and would be treated as non-customized (hidden from the column, blank on the edit page for Control policies). Worth a quick sanity check that connected workspaces still show their real tax codes — but if the backend seeds previousTaxCode for imported codes too, this is a non-issue.

Hi @dukenv0307, could you please check and confirm this backend behavior?

@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: c7106d2110

ℹ️ 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".

Comment thread src/components/TransactionItemRow/TransactionItemRowWide.tsx
@dukenv0307

Copy link
Copy Markdown
Contributor

@dmkt9

Hi @dukenv0307, could you please check and confirm this backend behavior?

My plate is full today, but I can check it tmr. I think we don't update previousTaxCode for the codes imported from QBO/Xero/NetSuite. Can you please confirm it on your side and propose a fix on BE?

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

I created the parent issue for this. Thanks for jumping on it. 👍

@truph01

truph01 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

@dmkt9 Could you help merge main?

@truph01

truph01 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

@dmkt9

Hi @dukenv0307, could you please check and confirm this backend behavior?

My plate is full today, but I can check it tmr. I think we don't update previousTaxCode for the codes imported from QBO/Xero/NetSuite. Can you please confirm it on your side and propose a fix on BE?

@dmkt9 Could you check this comment as well?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants