[$175] Distance request: "Invalid tax rate" error after switching to a non-default workspace, with no way to change the tax rate
If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.
Version Number: 9.5.55-4 Reproducible in staging?: Y Reproducible in production?: Y If this was caught during regression testing, add the test name, ID and link from BrowserStack: Email or phone of affected tester (no customers): Logs: https://stackoverflow.com/c/expensify/questions/4856 Expensify/Expensify Issue URL: Issue reported by: @FitseTLT Slack conversation (hyperlinked to channel name): #Expensify Bugs
Action Performed:
Preconditions: Two workspaces (A and B) with distance rate tax tracking enabled. A and B have different default tax rates. Workspace A is set as the default workspace.
Steps:
- In the self DM, create a distance request.
- Choose Submit to Employer and select workspace B, the non-default one.
- Try to confirm the request.
Expected Result:
The tax rate resets to B's default distance tax rate, or the user can pick a valid rate on the confirmation screen, and the request is submitted.
Actual Result:
The confirmation screen shows "tax rate is invalid", but the tax field can't be edited, so the user can't submit.
Workaround:
Unknown
Platforms:
Select the officially supported platforms where the issue was reproduced:
- [ ] Android: App
- [ ] Android: mWeb Chrome
- [ ] iOS: App
- [ ] iOS: mWeb Safari
- [ ] iOS: mWeb Chrome
- [x] Windows: Chrome
- [x] MacOS: Chrome / Safari
Screenshots/Videos
https://github.com/user-attachments/assets/2687d95c-df00-4df7-8ab3-dcfe7b402b50
https://github.com/user-attachments/assets/8d2a7db1-142d-4f4f-aaec-efc36d433c56
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022126735137485812304
- Upwork Job ID: 2126735137485812304
- Last Price Increase: 2026-11-28
Triggered auto assignment to Contributor-plus team member for initial proposal review - @eVoloshchak (External)
Job added to Upwork: https://www.upwork.com/jobs/~022126735137485812304
Proposal
What is the root cause of that problem?
Confidence: Medium — supported by code; not independently reproduced in the browser.
Submitting a tracked self-DM distance expense preserves its original workspace’s tax, even after selecting another workspace’s mileage rate. Confirmation rejects that tax if it is invalid in the destination workspace, but distance tax fields are intentionally read-only, leaving the user blocked.
Code evidence and scope
- Employer submission copies the existing transaction into a draft, retaining its tax.
- Selecting the destination updates the mileage rate, but
setCustomUnitRateIDupdates only custom-unit fields. - Without an applicable category tax rule, moved-expense tax preservation prevents the confirmation controller from applying the destination’s tax.
- Confirmation validates the retained tax against the destination policy, while distance requests cannot edit tax fields.
Different defaults alone are insufficient: the retained tax code must be absent from B, or its stored percentage must disagree with B’s corresponding rate. The issue provides no transaction state to distinguish those cases.
What changes do you think we should make in order to solve the problem?
For moved distance expenses, derive the tax code, percentage, and amount from the destination’s selected mileage rate and applicable fallback/category rules. Do not preserve or restore the source workspace’s distance tax.
Update the preservation and “keep current selection” logic together, while retaining existing preservation behavior for ordinary, non-distance tracked expenses.
Regression coverage should verify:
- A’s tax code is absent from B.
- The same code has different percentages across workspaces.
- A’s tax remains valid in B but differs from B’s selected distance-rate tax.
- Submission succeeds, with the recalculated amount, while non-distance tax preservation remains unchanged.
What alternative solutions did you explore? (Optional)
Enabling manual tax editing or bypassing validation would mask the synchronization problem rather than fix it.
Possibly related: Distance — Can’t delete Tax RBR after moving to another workspace. It involves a separate existing-expense detail-view path; this proposal should not be assumed to resolve it.
Next Steps for Contributor+ team:
To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/108264) to create a draft PR.
To refine: @MelvinBot <your feedback>
To reject: Explain why you are rejecting Melvin's proposal.
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a user creates a distance expense in the self DM (which resolves to the default workspace A and stores workspace A's distance tax rate) and then chooses Submit to Employer and selects a non-default workspace B with a different distance tax rate, the confirmation screen fails validation with "Tax rate no longer valid" (violations.taxOutOfPolicy). Because tax fields are read-only for distance requests, the user has no way to change the tax rate and cannot submit the expense.
What is the root cause of that problem?
In src/libs/actions/IOU/StartExpenseFlows.ts, createDraftTransactionAndNavigateToParticipantSelector copies the tracked self-DM distance transaction into TRANSACTION_DRAFT, carrying over workspace A's taxCode, taxValue, and taxAmount. When workspace B is selected in src/hooks/useParticipantSubmission.ts, setCustomUnitRateID (src/libs/actions/IOU/MoneyRequest.ts) only updates comment.customUnit fields, and setMoneyRequestCategory (src/libs/actions/IOU/MoneyRequest.ts) returns early when isMovingFromTrackExpense is true.
Tax synchronization on the confirmation screen is owned by TaxController and useTaxAmount. For a moved distance expense (isMovingTransactionFromTrackExpense && isDistanceRequest), useTaxAmount treats the expense the same as a manual/scan tracked expense whose tax rate could have been chosen by the user:
- Arrived-tax preservation blocks syncing the destination's distance tax (
useTaxAmount.ts,L171-L176):isKeepingArrivedTax = isMovingTransactionFromTrackExpense && !categoryTaxCodeevaluates totruewhen workspace B has no category tax rule, makingshouldHoldBackDefault = true.- Both
useEffecthooks inTaxController.tsxreturn early onshouldHoldBackDefault, leaving workspace A's staletaxCode,taxValue, andtaxAmounton the draft. - Even if a category tax rule on workspace B applies first and the user later switches to a category without a rule,
shouldRestoreArrivedTaxrestores workspace A's stalearrivedTaxback onto the draft.
shouldKeepCurrentTaxSelectioncan still retain workspace A's tax rate on distance requests (useTaxAmount.ts):- If workspace A's
taxCode+taxValuehappen to exist as a non-default tax rate in workspace B,hasTaxRateWithMatchingValue(policy, transaction)istrueandtransaction?.taxCode !== previousDefaultTaxCodeistrue(sincepreviousDefaultTaxCoderesolves against workspace B), soTaxControllerskips writing workspace B's mileage-rate tax. - Similarly, on first render (
previousTransactionCurrency === undefined),isFollowingWorkspaceDefault(useTaxAmount.ts) can suppresscategoryTaxCodeif workspace A's code ID matches workspace B's default code ID, even though distance tax defaults do not depend on currency.
- If workspace A's
- Fallback lookups to
policyForMovingExpenses(workspace A) and staletransaction.taxCode(useTaxAmount.ts,L165-L167):workspaceDefaultTaxCodefalls back togetDefaultTaxCode(policyForMovingExpenses, transaction)whengetDefaultTaxCode(policy, transaction)returnsundefined(for example, if workspace B's default tax rate is disabled), re-introducing workspace A's invalid tax code.taxPercentageresolvestransaction?.taxCode ?? defaultTaxCode(with fallback topolicyForMovingExpenses), so on the first render beforeTaxController's rate update settles,taxAmountInSmallestCurrencyUnitsis calculated using workspace A's stale tax code/percentage instead of workspace B'sdefaultTaxCode.
On confirm, useConfirmationValidation.ts rejects the retained tax via hasTaxRateWithMatchingValue(policy, transaction) with violations.taxOutOfPolicy, while useFooterDerivedFlags.ts sets canModifyTaxFields = !isReadOnly && !isDistanceRequest && !isPerDiemRequest, leaving the tax field non-editable and blocking submission.
What changes do you think we should make in order to solve the problem?
Update src/components/MoneyRequestConfirmationList/hooks/useTaxAmount.ts so distance requests always derive their tax code, percentage, and tax amount from the destination policy's mileage rate (and applicable destination category tax rule) instead of preserving or falling back to the source workspace's tax, while keeping existing arrived-tax preservation untouched for non-distance tracked expenses:
--- a/src/components/MoneyRequestConfirmationList/hooks/useTaxAmount.ts
+++ b/src/components/MoneyRequestConfirmationList/hooks/useTaxAmount.ts
@@ -75,7 +75,8 @@ function useTaxAmount({
const {areRulesLoading} = useRulesPrefetch(arePolicyRulesEnabled(policy, policyCategories));
// Update the tax code when the default changes (for example, because the transaction currency changed)
- const workspaceDefaultTaxCode = getDefaultTaxCode(policy, transaction) ?? (isMovingTransactionFromTrackExpense ? (getDefaultTaxCode(policyForMovingExpenses, transaction) ?? '') : '');
+ const workspaceDefaultTaxCode =
+ getDefaultTaxCode(policy, transaction) ?? (isMovingTransactionFromTrackExpense && !isDistanceRequest ? (getDefaultTaxCode(policyForMovingExpenses, transaction) ?? '') : '');
const previousWorkspaceDefaultTaxCode = getDefaultTaxCode(policy, transaction, previousTransactionCurrency);
const hasCurrencyChanged = transaction?.currency !== previousTransactionCurrency;
// The distance rate's default category is written by CategoryDefaultsSetter after this runs, so the rule is
@@ -105,7 +106,7 @@ function useTaxAmount({
: (getCategoryTaxCode(previousCategory, transaction, policy, rules, previousTransactionCurrency) ?? previousWorkspaceDefaultTaxCode);
// A tax that was the old currency's workspace default keeps following that default, so it moves to the new
// currency's one instead of being taken over by the category rule.
- const isFollowingWorkspaceDefault = hasCurrencyChanged && !!transaction?.taxCode && transaction.taxCode === previousWorkspaceDefaultTaxCode;
+ const isFollowingWorkspaceDefault = !isDistanceRequest && hasCurrencyChanged && !!transaction?.taxCode && transaction.taxCode === previousWorkspaceDefaultTaxCode;
// A category tax rule outranks the workspace default, so resolve it here as well. Otherwise this default overwrites
// the rule's tax rate on the first render of the confirmation page.
const categoryTaxCode = isFollowingWorkspaceDefault ? undefined : getCategoryTaxCode(category, transaction, policy, rules);
@@ -114,12 +115,12 @@ function useTaxAmount({
const [arrivedTax, setArrivedTax] = useState<Pick<OnyxTypes.Transaction, 'taxCode' | 'taxValue' | 'taxAmount'>>();
const [hasCategoryRuleApplied, setHasCategoryRuleApplied] = useState(false);
useEffect(() => {
- if (!isMovingTransactionFromTrackExpense || !!arrivedTax || !transaction) {
+ if (!isMovingTransactionFromTrackExpense || isDistanceRequest || !!arrivedTax || !transaction) {
return;
}
// eslint-disable-next-line react-hooks/set-state-in-effect -- the rate has to be read before the render that writes a rule's rate over it, which is not knowable during that render
setArrivedTax({taxCode: transaction.taxCode, taxValue: transaction.taxValue, taxAmount: transaction.taxAmount});
- }, [arrivedTax, isMovingTransactionFromTrackExpense, transaction]);
+ }, [arrivedTax, isDistanceRequest, isMovingTransactionFromTrackExpense, transaction]);
useEffect(() => {
if (hasCategoryRuleApplied || !categoryTaxCode) {
return;
@@ -131,7 +132,7 @@ function useTaxAmount({
// which is a rate nobody chose for it. A category rule is a rate the destination's admin chose, so it still
// applies. Dropping that category puts the arrived rate back, since the rule's rate belonged to the category
// the expense has just left.
- const isKeepingArrivedTax = isMovingTransactionFromTrackExpense && !categoryTaxCode;
+ const isKeepingArrivedTax = isMovingTransactionFromTrackExpense && !isDistanceRequest && !categoryTaxCode;
const shouldRestoreArrivedTax = isKeepingArrivedTax && hasCategoryRuleApplied;
const shouldHoldBackDefault = isKeepingArrivedTax && !hasCategoryRuleApplied;
const defaultTaxCode = categoryTaxCode ?? (shouldRestoreArrivedTax ? (arrivedTax?.taxCode ?? '') : workspaceDefaultTaxCode);
@@ -142,7 +143,8 @@ function useTaxAmount({
// hook has since moved on from counts, so a rate the user picked that happens to match is still left alone.
const [appliedDefaultTaxCode, setAppliedDefaultTaxCode] = useState<string>();
const isCarryingSupersededDefault = !!appliedDefaultTaxCode && transaction?.taxCode === appliedDefaultTaxCode && defaultTaxCode !== appliedDefaultTaxCode;
- const shouldKeepCurrentTaxSelection = hasTaxRateWithMatchingValue(policy, transaction) && transaction?.taxCode !== previousDefaultTaxCode && !isCarryingSupersededDefault;
+ const shouldKeepCurrentTaxSelection =
+ !isDistanceRequest && hasTaxRateWithMatchingValue(policy, transaction) && transaction?.taxCode !== previousDefaultTaxCode && !isCarryingSupersededDefault;
useEffect(() => {
if (areRulesLoading || shouldHoldBackDefault || !defaultTaxCode || defaultTaxCode === appliedDefaultTaxCode) {
@@ -162,9 +164,10 @@ function useTaxAmount({
// Calculate and set tax amount in transaction draft
const taxableAmount = isDistanceRequest ? DistanceRequestUtils.getTaxableAmount(policy, customUnitRateID, taxableDistance) : Math.abs(transaction?.amount ?? 0);
// First we'll try to get the tax value from the chosen policy and if not found, we'll try to get it from the policy for moving expenses (only if the transaction is moving from track expense)
+ const taxCodeForPercentage = isDistanceRequest ? defaultTaxCode : (transaction?.taxCode ?? defaultTaxCode);
const taxPercentage =
- getTaxValue(policy, transaction, transaction?.taxCode ?? defaultTaxCode) ??
- (isMovingTransactionFromTrackExpense ? getTaxValue(policyForMovingExpenses, transaction, transaction?.taxCode ?? defaultTaxCode) : '');
+ getTaxValue(policy, transaction, taxCodeForPercentage) ??
+ (isMovingTransactionFromTrackExpense && !isDistanceRequest ? getTaxValue(policyForMovingExpenses, transaction, taxCodeForPercentage) : '');
const taxDecimals = getCurrencyDecimals(transaction?.currency ?? CONST.CURRENCY.USD);
// A moved track expense keeps the tax amount it arrived with, since it keeps the rate that amount was charged at.
// A category rule on the destination workspace replaces that rate, so the amount has to be charged again.
Because TaxController already consumes defaultTaxCode, defaultTaxValue, shouldHoldBackDefault, shouldKeepCurrentTaxSelection, and taxAmountInSmallestCurrencyUnits from useTaxAmount and re-runs on policyID, defaultTaxCode, and defaultTaxValue changes, this covers all move entry paths (participant picker, single-workspace / restrictedPreferredPolicy skip-picker, confirmation "To" workspace switching, and DistanceRequestController fallback rate selection) without changing TaxController or non-distance behavior.
Unit tests
Add unit tests in tests/unit/hooks/useTaxAmount.test.ts verifying:
- A moved distance expense does not hold back the destination workspace's default tax (
shouldHoldBackDefault === false) and recalculatestaxAmountInSmallestCurrencyUnitsfrom the destination's taxable distance amount anddefaultTaxCoderather than keeping the arrivedtaxAmount. - A moved distance expense sets
shouldKeepCurrentTaxSelection === falseeven when workspace A's tax code and percentage also exist as a non-default rate on workspace B. - Dropping a destination category tax rule on a moved distance expense falls back to workspace B's distance tax default rather than restoring workspace A's arrived tax.
- When workspace B has no selectable default distance tax code,
defaultTaxCoderesolves to''instead of falling back topolicyForMovingExpenses(workspace A). - Existing non-distance moved track expense preservation tests remain passing without modification.
What alternative solutions did you explore? (Optional)
- Updating tax inside
setCustomUnitRateIDoruseParticipantSubmission: Rejected becauseuseParticipantSubmission'spolicyMapperintentionally omitstaxRatesand does not subscribe toONYXKEYS.COLLECTION.RULE/useRulesPrefetch, andsetCustomUnitRateIDis skipped on fast paths that bypass the participant picker (single-workspace andrestrictedPreferredPolicyflows) as well as when the mileage rate stays unchanged while a category rule changes. KeepingTaxController+useTaxAmountas the single confirmation-screen tax writer handles all entry points consistently. - Making tax fields editable on distance requests (
canModifyTaxFields): Rejected because distance tax is intentionally determined by the workspace's distance rate / category rule configuration rather than manual user selection; exposing an editable field would mask the sync bug instead of fixing it.
Proposal
Please re-state the problem that we are trying to solve in this issue.
A distance expense created in the self DM gets its tax from the default workspace (A). When it is submitted to a different workspace (B), the confirmation page keeps A's tax. The page shows "tax rate is invalid", and because distance tax fields are read-only, the user has no way to fix it and can't submit.
What is the root cause of that problem?
For a distance expense, the correct tax is the one attached to the selected mileage rate. getDefaultTaxCode already returns it, using the rate's taxRateExternalID:
https://github.com/Expensify/App/blob/b122e8d514f8d4684479715cfb61b8c9c0067269/src/libs/TransactionUtils/tax.ts#L103-L116
That default is never written. When a tracked expense is moved to a workspace, useTaxAmount deliberately keeps the tax the expense arrived with instead of applying the destination's default:
https://github.com/Expensify/App/blob/b122e8d514f8d4684479715cfb61b8c9c0067269/src/components/MoneyRequestConfirmationList/hooks/useTaxAmount.ts#L130-L137
isKeepingArrivedTax is true for every moved expense without a category tax rule, so shouldHoldBackDefault is true and TaxController returns early without writing B's rate tax:
https://github.com/Expensify/App/blob/b122e8d514f8d4684479715cfb61b8c9c0067269/src/components/MoneyRequestConfirmationList/TaxController.tsx#L82-L101
Keeping the arrived tax works for normal expenses, because the user can change it. A distance expense's tax isn't something the user chooses, though: it follows the rate, and the field is locked (canModifyTaxFields = !isReadOnly && !isDistanceRequest && !isPerDiemRequest in useFooterDerivedFlags.ts). A's tax code therefore stays on the expense, hasTaxRateWithMatchingValue(B, transaction) fails in useConfirmationValidation, and violations.taxOutOfPolicy blocks submission with no way out.
There is a second, quieter path on line 145. If A's tax code also exists in B, shouldKeepCurrentTaxSelection treats it as a user's choice and keeps it, even though it isn't the tax on B's selected rate. Submission then succeeds, but the tax is wrong:
https://github.com/Expensify/App/blob/b122e8d514f8d4684479715cfb61b8c9c0067269/src/components/MoneyRequestConfirmationList/hooks/useTaxAmount.ts#L145
What changes do you think we should make in order to solve the problem?
In useTaxAmount, never keep an arrived or "current" tax on a distance expense. Its tax always comes from the selected rate, or from a category rule, which already takes precedence through categoryTaxCode. Concretely:
- Add
!isDistanceRequestto theisKeepingArrivedTaxcondition, so a moved distance expense is no longer held on the tax it arrived with. - Only let
shouldKeepCurrentTaxSelectionbe true for a distance expense when its current tax code already equals the selected rate's tax (defaultTaxCode). A code that merely exists in the new workspace isn't something the user picked, so it shouldn't be kept.
With these two changes:
shouldHoldBackDefaultbecomesfalsefor distance expenses, soTaxControllerwrites B's rate tax (defaultTaxCode/defaultTaxValue).shouldKeepMovedTaxAmountbecomesfalse, so the tax amount is recalculated from B's rate (taxableAmountalready usescustomUnitRateIDand the distance).- Validation passes and the expense can be submitted.
- Normal, non-distance moved expenses keep today's behavior.
What specific scenarios should we cover in automated tests?
Unit tests for useTaxAmount, with isMovingTransactionFromTrackExpense: true, isDistanceRequest: true, and B's selected rate carrying taxRateExternalID: 'id_B':
- The expense arrives with A's code, which doesn't exist in B. Expect
defaultTaxCode === 'id_B',shouldHoldBackDefault === false, and a tax amount calculated from B's percentage. - The expense arrives with a code that exists in B but isn't on B's selected rate. Expect
shouldKeepCurrentTaxSelection === false, so B's rate tax is applied. - A category tax rule exists in B. The category rule still wins, unchanged.
- Regression check for a non-distance moved expense. It still keeps the arrived tax and amount, so existing tests stay green.
I'd also add a MoneyRequestConfirmationList test confirming that a distance expense moved to B shows no taxOutOfPolicy error.
What alternative solutions did you explore? (Optional)
- Make the tax field editable for distance expenses: this goes against the design, since distance tax is meant to follow the rate, and the user could still submit the wrong tax.
- Skip
taxOutOfPolicyvalidation for distance expenses: this would submit A's tax code to B and hide the problem. - Clear the tax when the participant changes: this only fixes the case where the code is missing from B, not the wrong-but-valid case on line 145.
Proposal
Please re-state the problem that we are trying to solve in this issue.
A self-DM distance expense keeps the default workspace's (A) tax when it's submitted to another workspace (B). The tax field is read-only for distance expenses, so the user sees "tax rate is invalid" and can't submit.
What is the root cause of that problem?
I agree with the direction in MelvinBot's proposal. Here are the exact code locations, plus a second case it doesn't call out.
-
In
useTaxAmount.ts(line 134),isKeepingArrivedTaxis true for every expense moved from track, distance ones included. This setsshouldHoldBackDefault, soTaxControllernever writes B's rate tax (getDefaultTaxCodealready returns it from the rate'staxRateExternalID). A's code stays, andtaxOutOfPolicyblocks submission. -
Second case, wrong tax with no error: if A's tax code also exists in B,
shouldKeepCurrentTaxSelection(line 145) treats it as the user's choice and keeps it. The expense then submits without any error, but with A's tax instead of the tax on B's selected rate.
What changes do you think we should make in order to solve the problem?
A distance expense's tax always follows its rate (or a category rule), so in useTaxAmount:
- don't keep the arrived tax for distance expenses (add
!isDistanceRequesttoisKeepingArrivedTax); - for distance expenses, only treat the current tax as "kept" if it already equals the selected rate's tax.
B's rate tax is then written, the tax amount is recalculated from B's rate, and validation passes. Non-distance moved expenses keep today's behavior.
Tests: A's code missing in B; A's code present in B but not on B's rate (the second case); category rule still wins; a non-distance moved expense is unchanged.
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~019e2bf7bf5bf050ac
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Hi team — I’m looking at the desktop distance-expense workspace switch described here. Before I prepare a proposal, is this still open to new external contributors, and are AI-assisted contributions accepted under your current process? I’m a freelancer based in Taiwan. A short text summary of any restrictions would help.
📣 @RogerYeh1990! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:
- Make sure you've read and understood the contributing guidelines.
- Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
- Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
- Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>
Proposal.
Please re-state the problem that we are trying to solve in this issue
When the user try to create a distance expense from the self DMand submits it to a workspace that is not their default workspace, the confirmation screen shows an "Invalid Tax Rate" error. The tax rate from the default workspace is still on the expense, and it does not exist in the selected workspace. On distance expenses the tax rate field cannot be edited, so the user has no way to fix the tax rate and cannot submit the expens. am i correct @MelvinBot
What is the root cause of that problem? I think This bug actually arises from the convergence of gaps in two separate areas.
The tax rate field has been intentionally disabled on the distance expense confirmation screen.
In src/components/MoneyRequestConfirmationListFooter/hooks/useFooterDerivedFlags.ts.
Since isDistanceRequest is always true for distance expenses, canModifyTaxFields always becomes false. Consequently, the onPress handler for the tax row in sections/TaxFields.tsx becomes undefined. This is generally fine, because the tax rate for distance should be automatically derived from the selected mileage rate. it is not something that the user should be able to change. When switching workspaces, two separate controllers come into play, and this is where the core issue lies:
DistanceRequestController.tsx — Upon a workspace change, this controller re-selects a valid mileage rate for the new workspace (B) by calling setCustomUnitRateID.
TaxController.tsx — This controller independently resets the tax code via setMoneyRequestTaxRateValues.
The DistanceRequestController only resets the rate; it does not reset the tax code. Resetting the tax code is the responsibility of the TaxController, but this process is blocked by the shouldKeepCurrentTaxSelection check (found in useTaxAmount.ts at line 145). The problem is one of timing/ordering: when workspace B is selected, getDefaultTaxCode (located in src/libs/TransactionUtils/tax.ts, within the distance branch) attempts to derive the default tax code based on the transaction's customUnitRateID. However, at that moment, the rateID still corresponds to workspace A (or, alternatively, the custom unit for workspace B has not yet been loaded into Onyx). Consequently, the old tax code from workspace A persists before a valid tax code for workspace B can be applied.
Then, upon attempting to submit, this check in src/components/MoneyRequestConfirmationList/hooks/useConfirmationValidation.ts fails: if (shouldShowTax && !!transaction?.taxCode && !hasTaxRateWithMatchingValue(policy, transaction)).
In other words, if a tax code from 'A' does not exist in 'B', the system returns hasTaxRateWithMatchingValue: false, which blocks the submission. Furthermore, since the tax field is disabled for 'distance' expenses (the first issue), the user cannot correct it manually. This is how the user ends up stuck.
What changes do you think we should make in order to solve the problem? I believe the issue comes from setCustomUnitRateID in MoneyRequest.ts. When the workspace changes, this function updates the mileage rate but never updates the tax code, so the old workspace's tax code stays on the expense. To fix it, I'll compute the new rate's default tax code and tax value right before the Onyx.merge call and save them in that same merge, so the tax always changes together with the rate. what do you think @MelvinBot ?
Proposal
Please re-state the problem that we are trying to solve in this issue? Two workspaces (A and B) have distance-rate tax tracking enabled with different default tax rates. Workspace A is the default. In the self DM, a user creates a distance request, chooses "Submit to Employer" and selects workspace B (the non-default one), then tries to confirm. The confirmation screen shows "tax rate is invalid", but the tax field cannot be edited, so the request can never be submitted. What is the root cause of that problem? I verified the diagnosis in the issue against the code on main. The defect is that a moved distance expense keeps the source workspace's tax, even though every other part of the expense is re-derived from the destination workspace — and distance tax fields are read-only, so the user has no way to repair the stale value.
- Employer submission copies the tracked transaction into a draft, retaining its tax. createDraftTransaction in src/libs/actions/IOU/StartExpenseFlows.ts:298-319 spreads the original transaction and overrides amount/currency/comment/merchant, but never clears taxCode/taxValue/taxAmount — so the draft arrives carrying A's tax.
- Selecting the destination mileage rate updates only the custom-unit fields, never tax. setCustomUnitRateID (src/libs/actions/IOU/MoneyRequest.ts:855+) merges only comment.customUnit (customUnitRateID, distanceUnit, quantity, rateAutoUpdated). The rate's taxClaimablePercentage (src/libs/DistanceRequestUtils.ts:820-830, getTaxableAmount) drives the taxable amount, but no tax code is written here.
- The moved-expense tax preservation then holds back the destination's default. In src/components/MoneyRequestConfirmationList/hooks/useTaxAmount.ts:133-139: // A moved track expense keeps the tax it arrived with rather than taking the destination workspace's default, // which is a rate nobody chose for it. A category rule is a rate the destination's admin chose, so it still // applies. Dropping that category puts the arrived rate back, since the rule's rate belonged to the category // the expense has just left. const isKeepingArrivedTax = isMovingTransactionFromTrackExpense && !categoryTaxCode; const shouldRestoreArrivedTax = isKeepingArrivedTax && hasCategoryRuleApplied; const shouldHoldBackDefault = isKeepingArrivedTax && !hasCategoryRuleApplied; When no category rule applies on B, shouldHoldBackDefault is true, so TaxController (src/components/MoneyRequestConfirmationList/TaxController.tsx:82-107) returns early and never writes B's default tax (workspaceDefaultTaxCode, from getDefaultTaxCode(policy, transaction) — which for distance requests resolves through the selected rate, src/libs/TransactionUtils/tax.ts:103-115). The kept amount is also preserved: shouldKeepMovedTaxAmount = isKeepingArrivedTax && !!keptTaxAmount (useTaxAmount.ts:172).
- Confirmation validation rejects the stale tax, and the user cannot fix it. src/components/MoneyRequestConfirmationList/hooks/useConfirmationValidation.ts:261-263: if (shouldShowTax && !!transaction?.taxCode && !hasTaxRateWithMatchingValue(policy, transaction)) { return {errorKey: 'violations.taxOutOfPolicy'}; } hasTaxRateWithMatchingValue (src/libs/TransactionUtils/tax.ts:235-249) requires the retained code to exist in B and its stored percentage to equal B's rate value (taxRate?.value === transaction?.taxValue). So the error fires whenever A's tax code is absent from B, or the same code carries a different percentage in B. And the user cannot repair it by hand: canModifyTaxFields = !isReadOnly && !isDistanceRequest && !isPerDiemRequest (src/components/MoneyRequestConfirmationListFooter/hooks/useFooterDerivedFlags.ts:87-90) — distance requests cannot edit tax fields. The preservation this breaks is designed for ordinary tracked expenses, where the arrived tax is a rate the user actually chose. For distance expenses the tax was never chosen — it is derived from the workspace's distance rate — so keeping it across workspaces is wrong. What changes do you think we should make in order to solve the problem? In src/components/MoneyRequestConfirmationList/hooks/useTaxAmount.ts, carve distance requests out of the arrived-tax preservation, so a moved distance expense is taxed like any other distance expense on the destination workspace: // Distance tax is derived from the destination workspace's selected mileage rate, // never chosen by the user — so keeping the source workspace's tax across a move // leaves a code the destination cannot validate, and distance tax fields are // read-only, so the user cannot repair it. Non-distance moved expenses keep the // arrived tax as before. const isKeepingArrivedTax = isMovingTransactionFromTrackExpense && !categoryTaxCode && !isDistanceRequest; With that one condition changed: • shouldHoldBackDefault becomes false for moved distance expenses, so the TaxController effect writes the destination default (defaultTaxCode, resolved through the selected mileage rate via getDefaultTaxCode, falling back to the destination workspace default; a destination category rule still outranks it, as today). • shouldKeepMovedTaxAmount becomes false, so the tax amount is freshly calculated from getTaxableAmount(policy, customUnitRateID, taxableDistance) — the destination rate's taxClaimablePercentage — instead of keeping A's amount. • shouldKeepCurrentTaxSelection already requires hasTaxRateWithMatchingValue(policy, transaction), so an invalid retained tax cannot be held in place; after re-derivation the code matches by construction. No change to setCustomUnitRateID, the validation, or the read-only tax fields: the confirmation screen then shows B's valid tax, the amount is recalculated, and submission succeeds. Ordinary (non-distance) moved tracked expenses keep the current preservation behavior untouched. Add regression coverage in tests/unit/hooks/useTaxAmount.test.ts and tests/unit/TaxControllerTest.tsx: • Move a distance expense from A to B where A's tax code is absent from B → the confirmation carries B's default distance tax, and submission is not blocked. • Same tax code with a different percentage in A and B → the tax is re-derived to B's value and amount. • A's tax remains valid in B but differs from B's selected distance-rate tax → the destination default is applied. • A moved non-distance tracked expense still keeps its arrived tax (existing behavior unchanged). What alternative solutions did you explore? (Optional) • Enabling manual tax editing for distance requests: rejected — it would let the user paper over a wrong derived tax instead of fixing the derivation, and the read-only fields are intentional (distance tax follows the mileage rate). • Bypassing validation for moved distance expenses: rejected — it would submit a request carrying a tax code/amount the destination workspace cannot account for. • Clearing the tax in createDraftTransaction for all moved expenses: rejected — ordinary tracked expenses should keep the tax the user chose; the carve-out belongs in the tax derivation, scoped to distance requests. Possibly related: #107360 "Distance — Can't delete Tax RBR after moving to another workspace" involves a separate existing-expense detail-view path; this proposal does not claim to resolve it. What are the regression risks? (Optional) Low. The change is a single condition in useTaxAmount.ts scoped to distance requests moved from a tracked expense. Non-distance moved expenses, ordinary distance requests created directly in a workspace, and category-rule tax resolution are all unaffected. The main risk is a distance expense whose destination has no selectable default tax at all (getDefaultTaxCode returns undefined for distance when the rate has no selectable tax code and the policy default is not selectable) — in that case the confirmation keeps today's behavior and validation still guards submission. What specific scenarios should we test?
- Two workspaces A (default) and B with distance tax tracking and different default tax rates. In the self DM, create a distance request, choose "Submit to Employer", select workspace B, and confirm: no "tax rate is invalid" error, the tax shown is B's default distance tax, the amount is recalculated from B's mileage rate, and the request submits.
- Same flow where the tax code exists in both workspaces but with different percentages: the submitted tax value matches B's rate.
- Same flow where A's tax code is valid in B but differs from B's selected distance-rate tax: B's default is applied.
- Move a non-distance tracked expense to another workspace: its arrived tax is still preserved (no behavior change).
- Create a distance request directly in workspace B (no move): tax behavior unchanged.
Addendum — two gaps in the fix above, found on re-reading useTaxAmount.ts:
- shouldKeepCurrentTaxSelection (line 145) must also exclude distance requests: !isDistanceRequest && hasTaxRateWithMatchingValue(...). Otherwise, when A's tax code also exists in B, TaxController.tsx:90 keeps A's tax even though it differs from B's selected mileage-rate tax — the scenario 3 test above would fail under the single-line fix alone.
- Pass customUnitRateID to getDefaultTaxCode (line 78) so the destination default resolves through the selected mileage rate, and gate the policyForMovingExpenses fallback (lines 78, 165-167) with !isDistanceRequest, so neither the default code nor the first-render taxPercentage can fall back to A's tax. Extra regression test: A's tax code exists in B but differs from B's selected mileage-rate tax → B's rate tax is applied (this is scenario 3, now actually covered).
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a user creates a distance expense in their self DM (which resolves tax from default workspace A) and then chooses Submit to Employer to a non-default workspace B that has a different distance tax rate, the confirmation screen keeps workspace A's stale taxCode / taxValue / taxAmount. Validation fails with an invalid tax rate error, and because distance tax fields are intentionally read-only on the confirmation screen, the user has no way to fix the tax rate and cannot submit the expense.
What is the root cause of that problem?
For distance requests, tax is not user-editable (canModifyTaxFields is false) — it must always be derived from the destination workspace's selected mileage rate (or an applicable distance category tax rule via getDistanceCategoryTaxCode). However, four places in src/components/MoneyRequestConfirmationList/hooks/useTaxAmount.ts treat moved distance expenses like manual expenses whose arrived tax should be preserved:
-
Moved-expense tax preservation holds back destination defaults (
useTaxAmount.ts:134-136):isKeepingArrivedTax = isMovingTransactionFromTrackExpense && !categoryTaxCodedoes not excludeisDistanceRequest. BecauseshouldHoldBackDefaultevaluates totruewhenever there is no category rule on workspace B, both effects inTaxController.tsx:85,103return early and leave workspace A's stale tax untouched. -
Silent wrong-tax preservation when a matching tax code/value exists (
useTaxAmount.ts:145):shouldKeepCurrentTaxSelection = hasTaxRateWithMatchingValue(policy, transaction) && transaction?.taxCode !== previousDefaultTaxCode && !isCarryingSupersededDefaultdoes not excludeisDistanceRequest. If workspace A's tax code/value also exists in workspace B (even when workspace B's selected mileage rate uses a different tax rate),TaxController.tsx:90returns early and silently submits workspace A's tax instead of workspace B's distance rate tax. -
workspaceDefaultTaxCodeomitscustomUnitRateIDand can fall back topolicyForMovingExpenses(useTaxAmount.ts:78):getDefaultTaxCode(policy, transaction)is called without passingcustomUnitRateIDas the 4th argument (seesrc/libs/TransactionUtils/tax.ts:103-116). For distance requests, falling back topolicyForMovingExpenseswhen destinationpolicyreturnsundefinedcan also re-inject the source workspace's tax code. -
First-render
taxPercentagelookup reads staletransaction.taxCodeand falls back topolicyForMovingExpenses(useTaxAmount.ts:165-167): BeforeTaxControllerwritesdefaultTaxCode,transaction.taxCodestill holds workspace A's code, sogetTaxValue(policy, ...)misses and falls back topolicyForMovingExpenses, calculatingtaxAmountInSmallestCurrencyUnitsat workspace A's tax percentage.
What changes do you think we should make in order to solve the problem?
In src/components/MoneyRequestConfirmationList/hooks/useTaxAmount.ts:
- Pass
customUnitRateIDtogetDefaultTaxCodeand avoid falling back topolicyForMovingExpensesfor distance requests:const workspaceDefaultTaxCode = getDefaultTaxCode(policy, transaction, undefined, isDistanceRequest ? customUnitRateID : undefined) ?? (isMovingTransactionFromTrackExpense && !isDistanceRequest ? (getDefaultTaxCode(policyForMovingExpenses, transaction) ?? '') : ''); - Exclude distance requests from moved-expense arrived-tax preservation (
line 134):const isKeepingArrivedTax = isMovingTransactionFromTrackExpense && !isDistanceRequest && !categoryTaxCode; - Exclude distance requests from keeping an arbitrary prior tax selection (
line 145):const shouldKeepCurrentTaxSelection = !isDistanceRequest && hasTaxRateWithMatchingValue(policy, transaction) && transaction?.taxCode !== previousDefaultTaxCode && !isCarryingSupersededDefault; - Compute
taxPercentagefromdefaultTaxCodedirectly for distance requests and gate thepolicyForMovingExpensesfallback with!isDistanceRequest(lines 165-167):const taxCodeForPercentage = isDistanceRequest ? defaultTaxCode : (transaction?.taxCode ?? defaultTaxCode); const taxPercentage = getTaxValue(policy, transaction, taxCodeForPercentage) ?? (isMovingTransactionFromTrackExpense && !isDistanceRequest ? getTaxValue(policyForMovingExpenses, transaction, taxCodeForPercentage) : '');
Unit tests to add:
- Moving a self-DM distance expense from workspace A (tax rate X) to workspace B (tax rate Y) resets
taxCode,taxValue, andtaxAmountto workspace B's distance rate tax so confirmation succeeds. - Moving a self-DM distance expense when workspace A's tax code also exists in workspace B (but differs from workspace B's selected mileage rate tax) updates to workspace B's mileage rate tax.
- Non-distance moved track expenses continue to preserve arrived tax when no category rule applies.
What alternative solutions did you explore? (Optional)
Clearing taxCode/taxValue/taxAmount in StartExpenseFlows.ts (createDraftTransaction) would break non-distance track expenses that intentionally preserve arrived tax, and updating tax in MoneyRequest.ts (setCustomUnitRateID) would still conflict with useTaxAmount / TaxController (shouldHoldBackDefault and shouldKeepCurrentTaxSelection) or duplicate distance category-rule resolution. Fixing useTaxAmount keeps a single source of truth across initial workspace selection and subsequent workspace/rate switches.
📣 @PQHOP! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:
- Make sure you've read and understood the contributing guidelines.
- Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
- Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
- Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>