From 6d720bf72cb002d14567dd0911839a5fc7187d5f Mon Sep 17 00:00:00 2001 From: "Eskalifer1 (via MelvinBot)" Date: Wed, 24 Jun 2026 19:33:04 +0000 Subject: [PATCH 01/22] Apply currency default tax rate when currency changes in create flow Co-authored-by: Eskalifer1 --- src/pages/iou/request/step/AmountSubmission.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/pages/iou/request/step/AmountSubmission.ts b/src/pages/iou/request/step/AmountSubmission.ts index f90a446aee11..2f26ac5c27fb 100644 --- a/src/pages/iou/request/step/AmountSubmission.ts +++ b/src/pages/iou/request/step/AmountSubmission.ts @@ -264,8 +264,16 @@ function submitAmount({ setMoneyRequestAmount(transactionID, amountInSmallestCurrencyUnits, selectedCurrency || CONST.CURRENCY.USD, shouldKeepUserInput, hasReceipt(transaction)); - if (isMovingTransactionFromTrackExpense(action)) { - const taxCode = selectedCurrency !== policy?.outputCurrency ? policy?.taxRates?.foreignTaxDefault : policy?.taxRates?.defaultExternalID; + // When the currency changes, re-apply the default tax rate for the new currency so the confirmation page and the + // created expense reflect the currency-appropriate default (e.g. the foreign default for a foreign currency). + // Only do this when the current tax code is still the auto-applied default for the previous currency, so a tax + // rate the user manually selected is preserved across the currency change. + const previousCurrency = getCurrency(transaction); + const previousDefaultTaxCode = getDefaultTaxCode(policy, transaction, previousCurrency); + const isCurrentTaxAutoDefault = !transaction?.taxCode || transaction?.taxCode === previousDefaultTaxCode; + + if (isMovingTransactionFromTrackExpense(action) || (selectedCurrency !== previousCurrency && isCurrentTaxAutoDefault)) { + const taxCode = getDefaultTaxCode(policy, transaction, selectedCurrency); if (taxCode) { setMoneyRequestTaxRate(transactionID, taxCode); const taxPercentage = getTaxValue(policy, transaction, taxCode) ?? ''; From 624bad3f586cec2c005b072a307895cf854f1c7d Mon Sep 17 00:00:00 2001 From: "Eskalifer1 (via MelvinBot)" Date: Wed, 24 Jun 2026 19:35:48 +0000 Subject: [PATCH 02/22] Add unit tests for currency-change tax recompute in create flow Co-authored-by: Eskalifer1 --- tests/unit/AmountSubmissionTest.ts | 79 ++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/tests/unit/AmountSubmissionTest.ts b/tests/unit/AmountSubmissionTest.ts index c0cefb245491..ee897ed3c75b 100644 --- a/tests/unit/AmountSubmissionTest.ts +++ b/tests/unit/AmountSubmissionTest.ts @@ -1,6 +1,7 @@ import Onyx from 'react-native-onyx'; import type {OnyxEntry} from 'react-native-onyx'; import {getIsP2PForAmount, getReportOrReportDraftForAmount, submitAmount} from '@pages/iou/request/step/AmountSubmission'; +import {setMoneyRequestTaxRate} from '@userActions/IOU/MoneyRequest'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {PersonalDetails, Policy, Report, Transaction} from '@src/types/onyx'; @@ -250,6 +251,84 @@ describe('AmountSubmission', () => { mockSetDraftSplitTransaction.mockClear(); mockUpdateMoneyRequestAmountAndCurrency.mockClear(); mockSetTransactionReport.mockClear(); + (setMoneyRequestTaxRate as jest.Mock).mockClear(); + }); + + const taxPolicy: OnyxEntry = { + id: 'policy-tax', + type: CONST.POLICY.TYPE.TEAM, + role: CONST.POLICY.ROLE.ADMIN, + name: 'Tax Workspace', + owner: 'me@test.com', + outputCurrency: CONST.CURRENCY.USD, + taxRates: { + name: 'Tax', + defaultExternalID: 'id_DEFAULT', + foreignTaxDefault: 'id_FOREIGN', + defaultValue: '5%', + taxes: { + id_DEFAULT: {name: 'Default', value: '5%'}, + id_FOREIGN: {name: 'Foreign', value: '10%'}, + id_MANUAL: {name: 'Manual', value: '7%'}, + }, + }, + } as Policy; + + const buildTaxTransaction = (taxCode: string): Transaction => + ({ + transactionID: 'tx-1', + amount: -1000, + currency: CONST.CURRENCY.USD, + created: '2024-01-01', + merchant: 'Test', + reportID: 'report-100', + comment: {}, + taxCode, + }) as Transaction; + + it('applies the new currency default tax rate on create when currency changes and tax is the auto-applied default', () => { + submitAmount( + buildBaseArgs({ + action: CONST.IOU.ACTION.CREATE, + iouType: CONST.IOU.TYPE.SUBMIT, + policy: taxPolicy, + transaction: buildTaxTransaction('id_DEFAULT'), + selectedCurrency: CONST.CURRENCY.EUR, + amount: '10', + }), + ); + + expect(setMoneyRequestTaxRate).toHaveBeenCalledWith('tx-1', 'id_FOREIGN'); + }); + + it('preserves a manually selected tax rate on create when currency changes', () => { + submitAmount( + buildBaseArgs({ + action: CONST.IOU.ACTION.CREATE, + iouType: CONST.IOU.TYPE.SUBMIT, + policy: taxPolicy, + transaction: buildTaxTransaction('id_MANUAL'), + selectedCurrency: CONST.CURRENCY.EUR, + amount: '10', + }), + ); + + expect(setMoneyRequestTaxRate).not.toHaveBeenCalled(); + }); + + it('does not change the tax rate on create when the currency is unchanged', () => { + submitAmount( + buildBaseArgs({ + action: CONST.IOU.ACTION.CREATE, + iouType: CONST.IOU.TYPE.SUBMIT, + policy: taxPolicy, + transaction: buildTaxTransaction('id_DEFAULT'), + selectedCurrency: CONST.CURRENCY.USD, + amount: '10', + }), + ); + + expect(setMoneyRequestTaxRate).not.toHaveBeenCalled(); }); it('calls sendMoneyElsewhere on non-edit + skip-confirm + PAY (non-wallet)', () => { From f9b8a9056150c7b0ad990a0470b15a57440ffc9c Mon Sep 17 00:00:00 2001 From: "Eskalifer1 (via MelvinBot)" Date: Wed, 24 Jun 2026 19:37:07 +0000 Subject: [PATCH 03/22] Fix lint in AmountSubmission tax tests Co-authored-by: Eskalifer1 --- tests/unit/AmountSubmissionTest.ts | 52 ++++++++++++++---------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/tests/unit/AmountSubmissionTest.ts b/tests/unit/AmountSubmissionTest.ts index ee897ed3c75b..99100d6615e0 100644 --- a/tests/unit/AmountSubmissionTest.ts +++ b/tests/unit/AmountSubmissionTest.ts @@ -5,6 +5,7 @@ import {setMoneyRequestTaxRate} from '@userActions/IOU/MoneyRequest'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {PersonalDetails, Policy, Report, Transaction} from '@src/types/onyx'; +import createRandomPolicy from '../utils/collections/policies'; import {createRandomReport} from '../utils/collections/reports'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; @@ -251,40 +252,35 @@ describe('AmountSubmission', () => { mockSetDraftSplitTransaction.mockClear(); mockUpdateMoneyRequestAmountAndCurrency.mockClear(); mockSetTransactionReport.mockClear(); - (setMoneyRequestTaxRate as jest.Mock).mockClear(); + jest.mocked(setMoneyRequestTaxRate).mockClear(); }); - const taxPolicy: OnyxEntry = { - id: 'policy-tax', - type: CONST.POLICY.TYPE.TEAM, - role: CONST.POLICY.ROLE.ADMIN, - name: 'Tax Workspace', - owner: 'me@test.com', + const taxPolicy: Policy = { + ...createRandomPolicy(200, CONST.POLICY.TYPE.TEAM, 'Tax Workspace'), outputCurrency: CONST.CURRENCY.USD, taxRates: { name: 'Tax', - defaultExternalID: 'id_DEFAULT', - foreignTaxDefault: 'id_FOREIGN', + defaultExternalID: 'idDefault', + foreignTaxDefault: 'idForeign', defaultValue: '5%', taxes: { - id_DEFAULT: {name: 'Default', value: '5%'}, - id_FOREIGN: {name: 'Foreign', value: '10%'}, - id_MANUAL: {name: 'Manual', value: '7%'}, + idDefault: {name: 'Default', value: '5%'}, + idForeign: {name: 'Foreign', value: '10%'}, + idManual: {name: 'Manual', value: '7%'}, }, }, - } as Policy; + }; - const buildTaxTransaction = (taxCode: string): Transaction => - ({ - transactionID: 'tx-1', - amount: -1000, - currency: CONST.CURRENCY.USD, - created: '2024-01-01', - merchant: 'Test', - reportID: 'report-100', - comment: {}, - taxCode, - }) as Transaction; + const buildTaxTransaction = (taxCode: string): Transaction => ({ + transactionID: 'tx-1', + amount: -1000, + currency: CONST.CURRENCY.USD, + created: '2024-01-01', + merchant: 'Test', + reportID: 'report-100', + comment: {}, + taxCode, + }); it('applies the new currency default tax rate on create when currency changes and tax is the auto-applied default', () => { submitAmount( @@ -292,13 +288,13 @@ describe('AmountSubmission', () => { action: CONST.IOU.ACTION.CREATE, iouType: CONST.IOU.TYPE.SUBMIT, policy: taxPolicy, - transaction: buildTaxTransaction('id_DEFAULT'), + transaction: buildTaxTransaction('idDefault'), selectedCurrency: CONST.CURRENCY.EUR, amount: '10', }), ); - expect(setMoneyRequestTaxRate).toHaveBeenCalledWith('tx-1', 'id_FOREIGN'); + expect(setMoneyRequestTaxRate).toHaveBeenCalledWith('tx-1', 'idForeign'); }); it('preserves a manually selected tax rate on create when currency changes', () => { @@ -307,7 +303,7 @@ describe('AmountSubmission', () => { action: CONST.IOU.ACTION.CREATE, iouType: CONST.IOU.TYPE.SUBMIT, policy: taxPolicy, - transaction: buildTaxTransaction('id_MANUAL'), + transaction: buildTaxTransaction('idManual'), selectedCurrency: CONST.CURRENCY.EUR, amount: '10', }), @@ -322,7 +318,7 @@ describe('AmountSubmission', () => { action: CONST.IOU.ACTION.CREATE, iouType: CONST.IOU.TYPE.SUBMIT, policy: taxPolicy, - transaction: buildTaxTransaction('id_DEFAULT'), + transaction: buildTaxTransaction('idDefault'), selectedCurrency: CONST.CURRENCY.USD, amount: '10', }), From 03379fdea900e08e4eb4e979cdcafb726878a1b6 Mon Sep 17 00:00:00 2001 From: "Eskalifer1 (via MelvinBot)" Date: Mon, 6 Jul 2026 10:22:01 +0000 Subject: [PATCH 04/22] Re-apply currency default tax on confirmation page for FAB flow Detect a stale auto-applied tax default (a policy default that no longer matches the transaction's current currency) in useTaxAmount so TaxController re-applies the correct currency default. This covers the global-create (FAB) flow where the amount step has no policy to recompute the tax code, while preserving genuinely manual (non-default) selections. Co-authored-by: Eskalifer1 --- .../hooks/useTaxAmount.ts | 19 ++++- tests/unit/hooks/useTaxAmount.test.ts | 82 ++++++++++++++++++- 2 files changed, 97 insertions(+), 4 deletions(-) diff --git a/src/components/MoneyRequestConfirmationList/hooks/useTaxAmount.ts b/src/components/MoneyRequestConfirmationList/hooks/useTaxAmount.ts index 234435bbfdcb..e54f6add20b8 100644 --- a/src/components/MoneyRequestConfirmationList/hooks/useTaxAmount.ts +++ b/src/components/MoneyRequestConfirmationList/hooks/useTaxAmount.ts @@ -53,10 +53,25 @@ function useTaxAmount({ const {getCurrencyDecimals} = useCurrencyListActions(); // Update the tax code when the default changes (for example, because the transaction currency changed) - const defaultTaxCode = getDefaultTaxCode(policy, transaction) ?? (isMovingTransactionFromTrackExpense ? (getDefaultTaxCode(policyForMovingExpenses, transaction) ?? '') : ''); + const currentDefaultTaxCode = getDefaultTaxCode(policy, transaction); + const defaultTaxCode = currentDefaultTaxCode ?? (isMovingTransactionFromTrackExpense ? (getDefaultTaxCode(policyForMovingExpenses, transaction) ?? '') : ''); const defaultTaxValue = getTaxValue(policy, transaction, defaultTaxCode) ?? null; const previousDefaultTaxCode = getDefaultTaxCode(policy, transaction, previousTransactionCurrency); - const shouldKeepCurrentTaxSelection = hasTaxRateWithMatchingValue(policy, transaction) && transaction?.taxCode !== previousDefaultTaxCode; + + // A tax code the user never manually chose: it matches one of the policy's two auto-applied defaults + // (the workspace-currency default `defaultExternalID` or the foreign-currency default `foreignTaxDefault`), + // but not the default for the transaction's *current* currency. This is stale state left over when the + // currency changed after a default was auto-applied and nothing re-applied the new currency's default — + // e.g. the global-create (FAB) flow, where the amount step has no policy in context to recompute the tax + // code. `hasTaxRateWithMatchingValue` still sees the stale code as a valid rate, so without this guard we + // would keep it and show the wrong tax rate. Detecting it here lets the correct currency default re-apply, + // while a genuinely manual (non-default) selection is preserved because it never matches a policy default. + const isStaleAutoDefault = + !!transaction?.taxCode && + (transaction.taxCode === policy?.taxRates?.defaultExternalID || transaction.taxCode === policy?.taxRates?.foreignTaxDefault) && + transaction.taxCode !== currentDefaultTaxCode; + + const shouldKeepCurrentTaxSelection = hasTaxRateWithMatchingValue(policy, transaction) && transaction?.taxCode !== previousDefaultTaxCode && !isStaleAutoDefault; // Calculate and set tax amount in transaction draft const taxableAmount = isDistanceRequest ? DistanceRequestUtils.getTaxableAmount(policy, customUnitRateID, distance) : Math.abs(transaction?.amount ?? 0); diff --git a/tests/unit/hooks/useTaxAmount.test.ts b/tests/unit/hooks/useTaxAmount.test.ts index cdd52f70771f..5e8e1b52721e 100644 --- a/tests/unit/hooks/useTaxAmount.test.ts +++ b/tests/unit/hooks/useTaxAmount.test.ts @@ -1,5 +1,6 @@ import {renderHook} from '@testing-library/react-native'; import useTaxAmount from '@components/MoneyRequestConfirmationList/hooks/useTaxAmount'; +import {getDefaultTaxCode as getDefaultTaxCodeMock, hasTaxRateWithMatchingValue as hasTaxRateWithMatchingValueMock} from '@libs/TransactionUtils'; import type * as OnyxTypes from '@src/types/onyx'; jest.mock('@hooks/useCurrencyList', () => ({ @@ -22,11 +23,14 @@ jest.mock('@libs/TransactionUtils', () => ({ const pct = Number.parseFloat(String(taxPercentage).replace('%', '')) || 0; return (taxableAmount * pct) / 100; }, - getDefaultTaxCode: () => 'tax_default', + getDefaultTaxCode: jest.fn(() => 'tax_default'), getTaxValue: () => '10%', - hasTaxRateWithMatchingValue: () => false, + hasTaxRateWithMatchingValue: jest.fn(() => false), })); +const mockGetDefaultTaxCode = getDefaultTaxCodeMock as jest.Mock; +const mockHasTaxRateWithMatchingValue = hasTaxRateWithMatchingValueMock as jest.Mock; + type Params = Parameters[0]; const baseParams: Params = { @@ -40,6 +44,20 @@ const baseParams: Params = { previousTransactionCurrency: 'USD', }; +// Mirrors the real getDefaultTaxCode for the non-distance path: workspace-currency default when the +// (optionally overridden) currency matches the policy output currency, otherwise the foreign default. +const currencyAwareDefaultTaxCode = (policy: OnyxTypes.Policy | undefined, transaction: OnyxTypes.Transaction | undefined, currency?: string) => { + const resolvedCurrency = currency ?? transaction?.currency; + return policy?.outputCurrency === resolvedCurrency ? policy?.taxRates?.defaultExternalID : policy?.taxRates?.foreignTaxDefault; +}; + +beforeEach(() => { + mockGetDefaultTaxCode.mockReset(); + mockGetDefaultTaxCode.mockReturnValue('tax_default'); + mockHasTaxRateWithMatchingValue.mockReset(); + mockHasTaxRateWithMatchingValue.mockReturnValue(false); +}); + describe('useTaxAmount', () => { it('returns the default tax code and value from policy resolution', () => { const {result} = renderHook(() => useTaxAmount(baseParams)); @@ -63,4 +81,64 @@ describe('useTaxAmount', () => { const {result} = renderHook(() => useTaxAmount(baseParams)); expect(result.current.shouldKeepCurrentTaxSelection).toBe(false); }); + + describe('stale auto-applied default after a currency change (e.g. FAB flow)', () => { + const policy = { + outputCurrency: 'USD', + taxRates: {defaultExternalID: 'CODE_DEFAULT', foreignTaxDefault: 'CODE_FOREIGN'}, + } as unknown as OnyxTypes.Policy; + + beforeEach(() => { + mockGetDefaultTaxCode.mockImplementation(currencyAwareDefaultTaxCode); + // The stale code still maps to a valid rate for the policy, so the old heuristic would keep it. + mockHasTaxRateWithMatchingValue.mockReturnValue(true); + }); + + it('does not keep the workspace-currency default once the currency is switched to a foreign one', () => { + const transaction = {transactionID: 'txn1', amount: 1000, currency: 'EUR', taxCode: 'CODE_DEFAULT'} as unknown as OnyxTypes.Transaction; + const {result} = renderHook(() => + useTaxAmount({ + ...baseParams, + transaction, + policy, + // A fresh confirmation-page mount seeds usePrevious with the already-updated currency. + previousTransactionCurrency: 'EUR', + }), + ); + + // Stale default detected → let TaxController re-apply the foreign-currency default. + expect(result.current.shouldKeepCurrentTaxSelection).toBe(false); + expect(result.current.defaultTaxCode).toBe('CODE_FOREIGN'); + }); + + it('preserves a manually selected non-default tax rate across a currency change', () => { + const transaction = {transactionID: 'txn1', amount: 1000, currency: 'EUR', taxCode: 'CODE_MANUAL'} as unknown as OnyxTypes.Transaction; + const {result} = renderHook(() => + useTaxAmount({ + ...baseParams, + transaction, + policy, + previousTransactionCurrency: 'EUR', + }), + ); + + // A non-default code is a real user choice → keep it. + expect(result.current.shouldKeepCurrentTaxSelection).toBe(true); + }); + + it('returns false (no-op) when taxCode already equals the current currency default', () => { + const transaction = {transactionID: 'txn1', amount: 1000, currency: 'EUR', taxCode: 'CODE_FOREIGN'} as unknown as OnyxTypes.Transaction; + const {result} = renderHook(() => + useTaxAmount({ + ...baseParams, + transaction, + policy, + previousTransactionCurrency: 'EUR', + }), + ); + + // taxCode already equals the current-currency default → not stale, nothing to re-apply. + expect(result.current.shouldKeepCurrentTaxSelection).toBe(false); + }); + }); }); From 58a7fad1b76d59220f701bdca2244533bf4dfa08 Mon Sep 17 00:00:00 2001 From: "Eskalifer1 (via MelvinBot)" Date: Mon, 6 Jul 2026 10:35:37 +0000 Subject: [PATCH 05/22] Revert "Re-apply currency default tax on confirmation page for FAB flow" This reverts commit 03379fdea900e08e4eb4e979cdcafb726878a1b6. --- .../hooks/useTaxAmount.ts | 19 +---- tests/unit/hooks/useTaxAmount.test.ts | 82 +------------------ 2 files changed, 4 insertions(+), 97 deletions(-) diff --git a/src/components/MoneyRequestConfirmationList/hooks/useTaxAmount.ts b/src/components/MoneyRequestConfirmationList/hooks/useTaxAmount.ts index e54f6add20b8..234435bbfdcb 100644 --- a/src/components/MoneyRequestConfirmationList/hooks/useTaxAmount.ts +++ b/src/components/MoneyRequestConfirmationList/hooks/useTaxAmount.ts @@ -53,25 +53,10 @@ function useTaxAmount({ const {getCurrencyDecimals} = useCurrencyListActions(); // Update the tax code when the default changes (for example, because the transaction currency changed) - const currentDefaultTaxCode = getDefaultTaxCode(policy, transaction); - const defaultTaxCode = currentDefaultTaxCode ?? (isMovingTransactionFromTrackExpense ? (getDefaultTaxCode(policyForMovingExpenses, transaction) ?? '') : ''); + const defaultTaxCode = getDefaultTaxCode(policy, transaction) ?? (isMovingTransactionFromTrackExpense ? (getDefaultTaxCode(policyForMovingExpenses, transaction) ?? '') : ''); const defaultTaxValue = getTaxValue(policy, transaction, defaultTaxCode) ?? null; const previousDefaultTaxCode = getDefaultTaxCode(policy, transaction, previousTransactionCurrency); - - // A tax code the user never manually chose: it matches one of the policy's two auto-applied defaults - // (the workspace-currency default `defaultExternalID` or the foreign-currency default `foreignTaxDefault`), - // but not the default for the transaction's *current* currency. This is stale state left over when the - // currency changed after a default was auto-applied and nothing re-applied the new currency's default — - // e.g. the global-create (FAB) flow, where the amount step has no policy in context to recompute the tax - // code. `hasTaxRateWithMatchingValue` still sees the stale code as a valid rate, so without this guard we - // would keep it and show the wrong tax rate. Detecting it here lets the correct currency default re-apply, - // while a genuinely manual (non-default) selection is preserved because it never matches a policy default. - const isStaleAutoDefault = - !!transaction?.taxCode && - (transaction.taxCode === policy?.taxRates?.defaultExternalID || transaction.taxCode === policy?.taxRates?.foreignTaxDefault) && - transaction.taxCode !== currentDefaultTaxCode; - - const shouldKeepCurrentTaxSelection = hasTaxRateWithMatchingValue(policy, transaction) && transaction?.taxCode !== previousDefaultTaxCode && !isStaleAutoDefault; + const shouldKeepCurrentTaxSelection = hasTaxRateWithMatchingValue(policy, transaction) && transaction?.taxCode !== previousDefaultTaxCode; // Calculate and set tax amount in transaction draft const taxableAmount = isDistanceRequest ? DistanceRequestUtils.getTaxableAmount(policy, customUnitRateID, distance) : Math.abs(transaction?.amount ?? 0); diff --git a/tests/unit/hooks/useTaxAmount.test.ts b/tests/unit/hooks/useTaxAmount.test.ts index 5e8e1b52721e..cdd52f70771f 100644 --- a/tests/unit/hooks/useTaxAmount.test.ts +++ b/tests/unit/hooks/useTaxAmount.test.ts @@ -1,6 +1,5 @@ import {renderHook} from '@testing-library/react-native'; import useTaxAmount from '@components/MoneyRequestConfirmationList/hooks/useTaxAmount'; -import {getDefaultTaxCode as getDefaultTaxCodeMock, hasTaxRateWithMatchingValue as hasTaxRateWithMatchingValueMock} from '@libs/TransactionUtils'; import type * as OnyxTypes from '@src/types/onyx'; jest.mock('@hooks/useCurrencyList', () => ({ @@ -23,14 +22,11 @@ jest.mock('@libs/TransactionUtils', () => ({ const pct = Number.parseFloat(String(taxPercentage).replace('%', '')) || 0; return (taxableAmount * pct) / 100; }, - getDefaultTaxCode: jest.fn(() => 'tax_default'), + getDefaultTaxCode: () => 'tax_default', getTaxValue: () => '10%', - hasTaxRateWithMatchingValue: jest.fn(() => false), + hasTaxRateWithMatchingValue: () => false, })); -const mockGetDefaultTaxCode = getDefaultTaxCodeMock as jest.Mock; -const mockHasTaxRateWithMatchingValue = hasTaxRateWithMatchingValueMock as jest.Mock; - type Params = Parameters[0]; const baseParams: Params = { @@ -44,20 +40,6 @@ const baseParams: Params = { previousTransactionCurrency: 'USD', }; -// Mirrors the real getDefaultTaxCode for the non-distance path: workspace-currency default when the -// (optionally overridden) currency matches the policy output currency, otherwise the foreign default. -const currencyAwareDefaultTaxCode = (policy: OnyxTypes.Policy | undefined, transaction: OnyxTypes.Transaction | undefined, currency?: string) => { - const resolvedCurrency = currency ?? transaction?.currency; - return policy?.outputCurrency === resolvedCurrency ? policy?.taxRates?.defaultExternalID : policy?.taxRates?.foreignTaxDefault; -}; - -beforeEach(() => { - mockGetDefaultTaxCode.mockReset(); - mockGetDefaultTaxCode.mockReturnValue('tax_default'); - mockHasTaxRateWithMatchingValue.mockReset(); - mockHasTaxRateWithMatchingValue.mockReturnValue(false); -}); - describe('useTaxAmount', () => { it('returns the default tax code and value from policy resolution', () => { const {result} = renderHook(() => useTaxAmount(baseParams)); @@ -81,64 +63,4 @@ describe('useTaxAmount', () => { const {result} = renderHook(() => useTaxAmount(baseParams)); expect(result.current.shouldKeepCurrentTaxSelection).toBe(false); }); - - describe('stale auto-applied default after a currency change (e.g. FAB flow)', () => { - const policy = { - outputCurrency: 'USD', - taxRates: {defaultExternalID: 'CODE_DEFAULT', foreignTaxDefault: 'CODE_FOREIGN'}, - } as unknown as OnyxTypes.Policy; - - beforeEach(() => { - mockGetDefaultTaxCode.mockImplementation(currencyAwareDefaultTaxCode); - // The stale code still maps to a valid rate for the policy, so the old heuristic would keep it. - mockHasTaxRateWithMatchingValue.mockReturnValue(true); - }); - - it('does not keep the workspace-currency default once the currency is switched to a foreign one', () => { - const transaction = {transactionID: 'txn1', amount: 1000, currency: 'EUR', taxCode: 'CODE_DEFAULT'} as unknown as OnyxTypes.Transaction; - const {result} = renderHook(() => - useTaxAmount({ - ...baseParams, - transaction, - policy, - // A fresh confirmation-page mount seeds usePrevious with the already-updated currency. - previousTransactionCurrency: 'EUR', - }), - ); - - // Stale default detected → let TaxController re-apply the foreign-currency default. - expect(result.current.shouldKeepCurrentTaxSelection).toBe(false); - expect(result.current.defaultTaxCode).toBe('CODE_FOREIGN'); - }); - - it('preserves a manually selected non-default tax rate across a currency change', () => { - const transaction = {transactionID: 'txn1', amount: 1000, currency: 'EUR', taxCode: 'CODE_MANUAL'} as unknown as OnyxTypes.Transaction; - const {result} = renderHook(() => - useTaxAmount({ - ...baseParams, - transaction, - policy, - previousTransactionCurrency: 'EUR', - }), - ); - - // A non-default code is a real user choice → keep it. - expect(result.current.shouldKeepCurrentTaxSelection).toBe(true); - }); - - it('returns false (no-op) when taxCode already equals the current currency default', () => { - const transaction = {transactionID: 'txn1', amount: 1000, currency: 'EUR', taxCode: 'CODE_FOREIGN'} as unknown as OnyxTypes.Transaction; - const {result} = renderHook(() => - useTaxAmount({ - ...baseParams, - transaction, - policy, - previousTransactionCurrency: 'EUR', - }), - ); - - // taxCode already equals the current-currency default → not stale, nothing to re-apply. - expect(result.current.shouldKeepCurrentTaxSelection).toBe(false); - }); - }); }); From cbb2c74510663c622ed11fb0b1bf1b7a35dc00f8 Mon Sep 17 00:00:00 2001 From: "Eskalifer1 (via MelvinBot)" Date: Mon, 6 Jul 2026 10:38:21 +0000 Subject: [PATCH 06/22] Resolve participant workspace policy on amount step for FAB flow In the global-create (FAB) flow there is no report context, so report?.policyID is undefined and the amount-step tax recompute in submitAmount had no policy to work with. Fall back to the policy of an already-selected workspace participant so the currency-change tax recompute applies in the FAB flow too, keying policy and policyCategories off the same resolved policyID. Co-authored-by: Eskalifer1 --- src/pages/iou/request/step/IOURequestStepAmount.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepAmount.tsx b/src/pages/iou/request/step/IOURequestStepAmount.tsx index 099fab54250d..a67a003670b6 100644 --- a/src/pages/iou/request/step/IOURequestStepAmount.tsx +++ b/src/pages/iou/request/step/IOURequestStepAmount.tsx @@ -64,7 +64,11 @@ function IOURequestStepAmount({ const iouRequestType = getRequestType(transaction); const isTrackExpense = iouType === CONST.IOU.TYPE.TRACK; const {policyForMovingExpensesID} = usePolicyForMovingExpenses(); - const policyID = isTrackExpense ? policyForMovingExpensesID : report?.policyID; + // In the global-create (FAB) flow there is no report context, so `report?.policyID` is undefined. Fall back to + // the policy of an already-selected workspace participant so the tax-rate recompute in `submitAmount` has a policy + // when the user returns to this step to change the currency after picking a workspace on the confirmation page. + const participantPolicyID = transaction?.participants?.find((participant) => participant.isPolicyExpenseChat)?.policyID; + const policyID = (isTrackExpense ? policyForMovingExpensesID : report?.policyID) ?? participantPolicyID; const selfDMReport = useSelfDMReport(); const isReportArchived = useReportIsArchived(report?.reportID); From a1b56ecaae30b650ed0469e4db4ae7333f1f42e0 Mon Sep 17 00:00:00 2001 From: "Eskalifer1 (via MelvinBot)" Date: Mon, 6 Jul 2026 11:25:39 +0000 Subject: [PATCH 07/22] Fix Oxfmt: sort imports in AmountSubmissionTest Co-authored-by: Eskalifer1 --- tests/unit/AmountSubmissionTest.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/AmountSubmissionTest.ts b/tests/unit/AmountSubmissionTest.ts index 8a72ea71c06e..3206020895c8 100644 --- a/tests/unit/AmountSubmissionTest.ts +++ b/tests/unit/AmountSubmissionTest.ts @@ -1,11 +1,11 @@ import {getIsP2PForAmount, getReportOrReportDraftForAmount, submitAmount} from '@pages/iou/request/step/AmountSubmission'; +import {setMoneyRequestTaxRate} from '@userActions/IOU/MoneyRequest'; + import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {PersonalDetails, Policy, Report, Transaction} from '@src/types/onyx'; -import {setMoneyRequestTaxRate} from '@userActions/IOU/MoneyRequest'; - import type {OnyxEntry} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; From 1e6c3b1f42bb75a2e8c93e686d509eaf3cd12f89 Mon Sep 17 00:00:00 2001 From: "Eskalifer1 (via MelvinBot)" Date: Mon, 6 Jul 2026 11:45:20 +0000 Subject: [PATCH 08/22] Preserve manually selected tax rate on edit-flow currency change Apply the same isCurrentTaxAutoDefault guard used in the create flow so the edit flow only re-applies the currency default tax rate when the current rate is still the auto-applied default. A manually chosen rate is preserved. Co-authored-by: Eskalifer1 --- .../iou/request/step/AmountSubmission.ts | 8 +++-- tests/unit/AmountSubmissionTest.ts | 30 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/pages/iou/request/step/AmountSubmission.ts b/src/pages/iou/request/step/AmountSubmission.ts index 9ff5a8942d87..66c22d081a4e 100644 --- a/src/pages/iou/request/step/AmountSubmission.ts +++ b/src/pages/iou/request/step/AmountSubmission.ts @@ -531,10 +531,14 @@ function submitAmount({ return; } - // If currency has changed, then we get the default tax rate based on currency, otherwise we use the current tax rate selected in transaction, if we have it. + // When the currency changes we re-apply the new currency's default tax rate, but only when the current tax rate is + // still the auto-applied default for the previous currency. A tax rate the user picked manually is preserved across + // the currency change (mirrors the create-flow guard in `navigateToNextPage`). const transactionTaxCode = getTransactionDetails(currentTransaction)?.taxCode; const defaultTaxCode = getDefaultTaxCode(policy, currentTransaction, selectedCurrency) ?? ''; - const taxCode = (selectedCurrency !== transactionCurrency ? defaultTaxCode : transactionTaxCode) ?? defaultTaxCode; + const previousDefaultTaxCode = getDefaultTaxCode(policy, currentTransaction, transactionCurrency); + const isCurrentTaxAutoDefault = !transactionTaxCode || transactionTaxCode === previousDefaultTaxCode; + const taxCode = (selectedCurrency !== transactionCurrency && isCurrentTaxAutoDefault ? defaultTaxCode : transactionTaxCode) ?? defaultTaxCode; const taxPercentage = getTaxValue(policy, currentTransaction, taxCode) ?? ''; const taxAmount = convertToBackendAmount(calculateTaxAmount(taxPercentage, newAmount, decimals)); diff --git a/tests/unit/AmountSubmissionTest.ts b/tests/unit/AmountSubmissionTest.ts index 3206020895c8..78584723d564 100644 --- a/tests/unit/AmountSubmissionTest.ts +++ b/tests/unit/AmountSubmissionTest.ts @@ -332,6 +332,36 @@ describe('AmountSubmission', () => { expect(setMoneyRequestTaxRate).not.toHaveBeenCalled(); }); + it('applies the new currency default tax rate on edit when currency changes and tax is the auto-applied default', () => { + submitAmount( + buildBaseArgs({ + action: CONST.IOU.ACTION.EDIT, + iouType: CONST.IOU.TYPE.SUBMIT, + policy: taxPolicy, + transaction: buildTaxTransaction('idDefault'), + selectedCurrency: CONST.CURRENCY.EUR, + amount: '10', + }), + ); + + expect(mockUpdateMoneyRequestAmountAndCurrency).toHaveBeenCalledWith(expect.objectContaining({taxCode: 'idForeign'})); + }); + + it('preserves a manually selected tax rate on edit when currency changes', () => { + submitAmount( + buildBaseArgs({ + action: CONST.IOU.ACTION.EDIT, + iouType: CONST.IOU.TYPE.SUBMIT, + policy: taxPolicy, + transaction: buildTaxTransaction('idManual'), + selectedCurrency: CONST.CURRENCY.EUR, + amount: '10', + }), + ); + + expect(mockUpdateMoneyRequestAmountAndCurrency).toHaveBeenCalledWith(expect.objectContaining({taxCode: 'idManual'})); + }); + it('calls sendMoneyElsewhere on non-edit + skip-confirm + PAY (non-wallet)', () => { submitAmount( buildBaseArgs({ From 29ce74d0f7fbd7215c8ce5f69e91fc1eb2ebe98b Mon Sep 17 00:00:00 2001 From: "Eskalifer1 (via MelvinBot)" Date: Mon, 6 Jul 2026 13:42:20 +0000 Subject: [PATCH 09/22] Gate create-flow tax recompute on tax tracking and heal invalid tax code on edit Co-authored-by: Eskalifer1 --- .../iou/request/step/AmountSubmission.ts | 16 +++++-- tests/unit/AmountSubmissionTest.ts | 48 ++++++++++++++++++- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/src/pages/iou/request/step/AmountSubmission.ts b/src/pages/iou/request/step/AmountSubmission.ts index 66c22d081a4e..f4e0b8d7091b 100644 --- a/src/pages/iou/request/step/AmountSubmission.ts +++ b/src/pages/iou/request/step/AmountSubmission.ts @@ -15,9 +15,10 @@ import Navigation from '@libs/Navigation/Navigation'; import {rand64} from '@libs/NumberUtils'; import {getParticipantsOption, getReportOption} from '@libs/OptionsListUtils'; import Permissions from '@libs/Permissions'; -import {getPolicyExpenseChat, getTransactionDetails, isMoneyRequestReport, isSelfDM, shouldEnableNegative} from '@libs/ReportUtils'; +import {isTaxTrackingEnabled} from '@libs/PolicyUtils'; +import {getPolicyExpenseChat, getTransactionDetails, isMoneyRequestReport, isPolicyExpenseChat, isSelfDM, shouldEnableNegative} from '@libs/ReportUtils'; import shouldUseDefaultExpensePolicy from '@libs/shouldUseDefaultExpensePolicy'; -import {calculateTaxAmount, getAmount, getCurrency, getDefaultTaxCode, getIsFromGlobalCreate, getTaxValue, hasReceipt} from '@libs/TransactionUtils'; +import {calculateTaxAmount, getAmount, getCurrency, getDefaultTaxCode, getIsFromGlobalCreate, getTaxValue, hasReceipt, hasTaxRateWithMatchingValue} from '@libs/TransactionUtils'; import { getMoneyRequestParticipantsFromReport, @@ -275,8 +276,12 @@ function submitAmount({ const previousCurrency = getCurrency(transaction); const previousDefaultTaxCode = getDefaultTaxCode(policy, transaction, previousCurrency); const isCurrentTaxAutoDefault = !transaction?.taxCode || transaction?.taxCode === previousDefaultTaxCode; + // Only re-apply a currency default when the workspace actually tracks tax (mirrors the confirmation page's + // `shouldShowTax` gate). Without this, a currency change would persist a tax code and amount on a workspace + // that has tax tracking disabled. The amount step is always a manual expense, so distance is `false` here. + const isTaxEnabled = isTaxTrackingEnabled(isPolicyExpenseChat(report), policy, false); - if (isMovingTransactionFromTrackExpense(action) || (selectedCurrency !== previousCurrency && isCurrentTaxAutoDefault)) { + if (isMovingTransactionFromTrackExpense(action) || (isTaxEnabled && selectedCurrency !== previousCurrency && isCurrentTaxAutoDefault)) { const taxCode = getDefaultTaxCode(policy, transaction, selectedCurrency); if (taxCode) { setMoneyRequestTaxRate(transactionID, taxCode); @@ -538,7 +543,10 @@ function submitAmount({ const defaultTaxCode = getDefaultTaxCode(policy, currentTransaction, selectedCurrency) ?? ''; const previousDefaultTaxCode = getDefaultTaxCode(policy, currentTransaction, transactionCurrency); const isCurrentTaxAutoDefault = !transactionTaxCode || transactionTaxCode === previousDefaultTaxCode; - const taxCode = (selectedCurrency !== transactionCurrency && isCurrentTaxAutoDefault ? defaultTaxCode : transactionTaxCode) ?? defaultTaxCode; + // The edit path has no confirmation-page safety net, so heal a tax code that is no longer a valid rate on the + // policy (e.g. the rate was deleted or the expense moved workspaces) by falling back to the currency default. + const isTransactionTaxCodeValid = hasTaxRateWithMatchingValue(policy, currentTransaction); + const taxCode = ((selectedCurrency !== transactionCurrency && isCurrentTaxAutoDefault) || !isTransactionTaxCodeValid ? defaultTaxCode : transactionTaxCode) ?? defaultTaxCode; const taxPercentage = getTaxValue(policy, currentTransaction, taxCode) ?? ''; const taxAmount = convertToBackendAmount(calculateTaxAmount(taxPercentage, newAmount, decimals)); diff --git a/tests/unit/AmountSubmissionTest.ts b/tests/unit/AmountSubmissionTest.ts index 78584723d564..e6de22a73cc8 100644 --- a/tests/unit/AmountSubmissionTest.ts +++ b/tests/unit/AmountSubmissionTest.ts @@ -1,6 +1,6 @@ import {getIsP2PForAmount, getReportOrReportDraftForAmount, submitAmount} from '@pages/iou/request/step/AmountSubmission'; -import {setMoneyRequestTaxRate} from '@userActions/IOU/MoneyRequest'; +import {setMoneyRequestTaxAmount, setMoneyRequestTaxRate} from '@userActions/IOU/MoneyRequest'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -258,11 +258,13 @@ describe('AmountSubmission', () => { mockUpdateMoneyRequestAmountAndCurrency.mockClear(); mockSetTransactionReport.mockClear(); jest.mocked(setMoneyRequestTaxRate).mockClear(); + jest.mocked(setMoneyRequestTaxAmount).mockClear(); }); const taxPolicy: Policy = { ...createRandomPolicy(200, CONST.POLICY.TYPE.TEAM, 'Tax Workspace'), outputCurrency: CONST.CURRENCY.USD, + tax: {trackingEnabled: true}, taxRates: { name: 'Tax', defaultExternalID: 'idDefault', @@ -276,6 +278,15 @@ describe('AmountSubmission', () => { }, }; + // The create-flow tax recompute only runs on a policy expense chat with tax tracking enabled, so tax tests + // start from a workspace chat report (mirrors continuing an expense from a tax-enabled workspace chat). + const taxReport: Report = { + ...createRandomReport(100, undefined), + reportID: 'report-100', + chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, + policyID: '200', + }; + const buildTaxTransaction = (taxCode: string): Transaction => ({ transactionID: 'tx-1', amount: -1000, @@ -290,6 +301,7 @@ describe('AmountSubmission', () => { it('applies the new currency default tax rate on create when currency changes and tax is the auto-applied default', () => { submitAmount( buildBaseArgs({ + report: taxReport, action: CONST.IOU.ACTION.CREATE, iouType: CONST.IOU.TYPE.SUBMIT, policy: taxPolicy, @@ -305,6 +317,7 @@ describe('AmountSubmission', () => { it('preserves a manually selected tax rate on create when currency changes', () => { submitAmount( buildBaseArgs({ + report: taxReport, action: CONST.IOU.ACTION.CREATE, iouType: CONST.IOU.TYPE.SUBMIT, policy: taxPolicy, @@ -320,6 +333,7 @@ describe('AmountSubmission', () => { it('does not change the tax rate on create when the currency is unchanged', () => { submitAmount( buildBaseArgs({ + report: taxReport, action: CONST.IOU.ACTION.CREATE, iouType: CONST.IOU.TYPE.SUBMIT, policy: taxPolicy, @@ -332,6 +346,23 @@ describe('AmountSubmission', () => { expect(setMoneyRequestTaxRate).not.toHaveBeenCalled(); }); + it('does not write a tax code or amount on create when the workspace has tax tracking disabled', () => { + submitAmount( + buildBaseArgs({ + report: taxReport, + action: CONST.IOU.ACTION.CREATE, + iouType: CONST.IOU.TYPE.SUBMIT, + policy: {...taxPolicy, tax: {trackingEnabled: false}}, + transaction: buildTaxTransaction('idDefault'), + selectedCurrency: CONST.CURRENCY.EUR, + amount: '10', + }), + ); + + expect(setMoneyRequestTaxRate).not.toHaveBeenCalled(); + expect(setMoneyRequestTaxAmount).not.toHaveBeenCalled(); + }); + it('applies the new currency default tax rate on edit when currency changes and tax is the auto-applied default', () => { submitAmount( buildBaseArgs({ @@ -362,6 +393,21 @@ describe('AmountSubmission', () => { expect(mockUpdateMoneyRequestAmountAndCurrency).toHaveBeenCalledWith(expect.objectContaining({taxCode: 'idManual'})); }); + it('heals a tax code that is not a valid policy rate to the currency default on edit', () => { + submitAmount( + buildBaseArgs({ + action: CONST.IOU.ACTION.EDIT, + iouType: CONST.IOU.TYPE.SUBMIT, + policy: taxPolicy, + transaction: buildTaxTransaction('idNoLongerExists'), + selectedCurrency: CONST.CURRENCY.EUR, + amount: '10', + }), + ); + + expect(mockUpdateMoneyRequestAmountAndCurrency).toHaveBeenCalledWith(expect.objectContaining({taxCode: 'idForeign'})); + }); + it('calls sendMoneyElsewhere on non-edit + skip-confirm + PAY (non-wallet)', () => { submitAmount( buildBaseArgs({ From 6bd27a3aedc6b11bd8d04b25ab3a5a1ab4143db2 Mon Sep 17 00:00:00 2001 From: "Eskalifer1 (via MelvinBot)" Date: Mon, 6 Jul 2026 14:15:29 +0000 Subject: [PATCH 10/22] Recognize FAB-flow workspace via participant in tax recompute gate The create-flow tax recompute gate used isPolicyExpenseChat(report), which is false in the global-create (FAB) flow where there is no report context, so the currency-change tax recompute was skipped even though the policy resolves via the selected participant. Derive the policy-expense signal from the transaction's participant too, mirroring how policyID is resolved on this step. Co-authored-by: Eskalifer1 --- src/pages/iou/request/step/AmountSubmission.ts | 5 ++++- tests/unit/AmountSubmissionTest.ts | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/pages/iou/request/step/AmountSubmission.ts b/src/pages/iou/request/step/AmountSubmission.ts index f4e0b8d7091b..d62a4e8b1d61 100644 --- a/src/pages/iou/request/step/AmountSubmission.ts +++ b/src/pages/iou/request/step/AmountSubmission.ts @@ -279,7 +279,10 @@ function submitAmount({ // Only re-apply a currency default when the workspace actually tracks tax (mirrors the confirmation page's // `shouldShowTax` gate). Without this, a currency change would persist a tax code and amount on a workspace // that has tax tracking disabled. The amount step is always a manual expense, so distance is `false` here. - const isTaxEnabled = isTaxTrackingEnabled(isPolicyExpenseChat(report), policy, false); + // In the global-create (FAB) flow there is no `report`, so recognize the workspace via the transaction's + // selected participant too — mirroring how `policyID` is resolved on this step. + const isPolicyExpenseChatParticipant = transaction?.participants?.some((participant) => participant.isPolicyExpenseChat) ?? false; + const isTaxEnabled = isTaxTrackingEnabled(isPolicyExpenseChat(report) || isPolicyExpenseChatParticipant, policy, false); if (isMovingTransactionFromTrackExpense(action) || (isTaxEnabled && selectedCurrency !== previousCurrency && isCurrentTaxAutoDefault)) { const taxCode = getDefaultTaxCode(policy, transaction, selectedCurrency); diff --git a/tests/unit/AmountSubmissionTest.ts b/tests/unit/AmountSubmissionTest.ts index e6de22a73cc8..dc281f69c433 100644 --- a/tests/unit/AmountSubmissionTest.ts +++ b/tests/unit/AmountSubmissionTest.ts @@ -363,6 +363,24 @@ describe('AmountSubmission', () => { expect(setMoneyRequestTaxAmount).not.toHaveBeenCalled(); }); + it('applies the new currency default tax rate on create from the FAB flow (no report) when the workspace is resolved from the participant', () => { + // Global-create (FAB) flow: there is no report context, so the workspace/tax tracking must be recognized + // from the transaction's selected policy-expense-chat participant instead of from `report`. + submitAmount( + buildBaseArgs({ + report: undefined, + action: CONST.IOU.ACTION.CREATE, + iouType: CONST.IOU.TYPE.SUBMIT, + policy: taxPolicy, + transaction: {...buildTaxTransaction('idDefault'), participants: [{isPolicyExpenseChat: true, policyID: '200'}]}, + selectedCurrency: CONST.CURRENCY.EUR, + amount: '10', + }), + ); + + expect(setMoneyRequestTaxRate).toHaveBeenCalledWith('tx-1', 'idForeign'); + }); + it('applies the new currency default tax rate on edit when currency changes and tax is the auto-applied default', () => { submitAmount( buildBaseArgs({ From 56d8dbcca0049a91c1dfaaa44e7346dc59736ae7 Mon Sep 17 00:00:00 2001 From: "Eskalifer1 (via MelvinBot)" Date: Mon, 6 Jul 2026 16:03:49 +0000 Subject: [PATCH 11/22] Re-apply currency default tax rate on confirmation page for the FAB create flow The amount-step tax recompute cannot run in the global-create (FAB) flow because no policy is resolvable there, leaving the confirmation page to keep the stale workspace-currency default after a currency change. Treat a tax code that equals a policy auto-default but not the current currency's default as stale in useTaxAmount so TaxController re-applies the correct currency default, while preserving manual selections. Co-authored-by: Eskalifer1 --- .../hooks/useTaxAmount.ts | 12 ++++- tests/unit/hooks/useTaxAmount.test.ts | 52 +++++++++++++++++-- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/src/components/MoneyRequestConfirmationList/hooks/useTaxAmount.ts b/src/components/MoneyRequestConfirmationList/hooks/useTaxAmount.ts index 6c3b000fab8f..4e88796e7340 100644 --- a/src/components/MoneyRequestConfirmationList/hooks/useTaxAmount.ts +++ b/src/components/MoneyRequestConfirmationList/hooks/useTaxAmount.ts @@ -59,7 +59,17 @@ function useTaxAmount({ const defaultTaxCode = getDefaultTaxCode(policy, transaction) ?? (isMovingTransactionFromTrackExpense ? (getDefaultTaxCode(policyForMovingExpenses, transaction) ?? '') : ''); const defaultTaxValue = getTaxValue(policy, transaction, defaultTaxCode) ?? null; const previousDefaultTaxCode = getDefaultTaxCode(policy, transaction, previousTransactionCurrency); - const shouldKeepCurrentTaxSelection = hasTaxRateWithMatchingValue(policy, transaction) && transaction?.taxCode !== previousDefaultTaxCode; + + // A tax code the user never manually chose: it is one of the policy's auto-defaults (workspace-currency or + // foreign-currency default), but not the default for the *current* currency. This happens when the currency + // changed after the default was auto-applied and the amount step had no policy to recompute it (e.g. the create + // flow started from the FAB, where the amount step has no report/policy context). Treat it as stale so the current + // currency's default is re-applied instead of being preserved as if it were a deliberate selection. + const isStaleAutoDefault = + !!transaction?.taxCode && + (transaction.taxCode === policy?.taxRates?.defaultExternalID || transaction.taxCode === policy?.taxRates?.foreignTaxDefault) && + transaction.taxCode !== defaultTaxCode; + const shouldKeepCurrentTaxSelection = hasTaxRateWithMatchingValue(policy, transaction) && transaction?.taxCode !== previousDefaultTaxCode && !isStaleAutoDefault; // Calculate and set tax amount in transaction draft const taxableAmount = isDistanceRequest ? DistanceRequestUtils.getTaxableAmount(policy, customUnitRateID, distance) : Math.abs(transaction?.amount ?? 0); diff --git a/tests/unit/hooks/useTaxAmount.test.ts b/tests/unit/hooks/useTaxAmount.test.ts index f0b7b8ea23e0..f3132fd245dc 100644 --- a/tests/unit/hooks/useTaxAmount.test.ts +++ b/tests/unit/hooks/useTaxAmount.test.ts @@ -19,14 +19,18 @@ jest.mock('@libs/DistanceRequestUtils', () => ({ }, })); +const mockGetDefaultTaxCode = jest.fn(); +const mockGetTaxValue = jest.fn(); +const mockHasTaxRateWithMatchingValue = jest.fn(); + jest.mock('@libs/TransactionUtils', () => ({ calculateTaxAmount: (taxPercentage: string, taxableAmount: number) => { const pct = Number.parseFloat(String(taxPercentage).replace('%', '')) || 0; return (taxableAmount * pct) / 100; }, - getDefaultTaxCode: () => 'tax_default', - getTaxValue: () => '10%', - hasTaxRateWithMatchingValue: () => false, + getDefaultTaxCode: (...args: unknown[]) => mockGetDefaultTaxCode(...args), + getTaxValue: (...args: unknown[]) => mockGetTaxValue(...args), + hasTaxRateWithMatchingValue: (...args: unknown[]) => mockHasTaxRateWithMatchingValue(...args), })); type Params = Parameters[0]; @@ -43,6 +47,16 @@ const baseParams: Params = { }; describe('useTaxAmount', () => { + beforeEach(() => { + mockGetDefaultTaxCode.mockReturnValue('tax_default'); + mockGetTaxValue.mockReturnValue('10%'); + mockHasTaxRateWithMatchingValue.mockReturnValue(false); + }); + + afterEach(() => { + jest.clearAllMocks(); + }); + it('returns the default tax code and value from policy resolution', () => { const {result} = renderHook(() => useTaxAmount(baseParams)); expect(result.current.defaultTaxCode).toBe('tax_default'); @@ -65,4 +79,36 @@ describe('useTaxAmount', () => { const {result} = renderHook(() => useTaxAmount(baseParams)); expect(result.current.shouldKeepCurrentTaxSelection).toBe(false); }); + + it('shouldKeepCurrentTaxSelection is false when the current tax code is a stale policy default from before a currency change (FAB flow)', () => { + // The current currency default is the foreign default, but the draft still carries the workspace-currency + // default that was auto-applied before the currency was switched (the amount step had no policy to recompute it). + mockGetDefaultTaxCode.mockReturnValue('tax_foreign'); + mockHasTaxRateWithMatchingValue.mockReturnValue(true); + const policy = {taxRates: {defaultExternalID: 'tax_workspace', foreignTaxDefault: 'tax_foreign'}} as unknown as OnyxTypes.Policy; + const {result} = renderHook(() => + useTaxAmount({ + ...baseParams, + policy, + transaction: {transactionID: 'txn1', amount: 1000, currency: 'EUR', taxCode: 'tax_workspace'} as unknown as OnyxTypes.Transaction, + previousTransactionCurrency: 'EUR', + }), + ); + expect(result.current.shouldKeepCurrentTaxSelection).toBe(false); + }); + + it('shouldKeepCurrentTaxSelection stays true for a manually selected non-default tax code', () => { + mockGetDefaultTaxCode.mockReturnValue('tax_foreign'); + mockHasTaxRateWithMatchingValue.mockReturnValue(true); + const policy = {taxRates: {defaultExternalID: 'tax_workspace', foreignTaxDefault: 'tax_foreign'}} as unknown as OnyxTypes.Policy; + const {result} = renderHook(() => + useTaxAmount({ + ...baseParams, + policy, + transaction: {transactionID: 'txn1', amount: 1000, currency: 'EUR', taxCode: 'tax_custom'} as unknown as OnyxTypes.Transaction, + previousTransactionCurrency: 'USD', + }), + ); + expect(result.current.shouldKeepCurrentTaxSelection).toBe(true); + }); }); From 0060acc974f72d18ed055e8fc28227bcd6d8b022 Mon Sep 17 00:00:00 2001 From: "Eskalifer1 (via MelvinBot)" Date: Mon, 6 Jul 2026 16:35:08 +0000 Subject: [PATCH 12/22] Revert "Re-apply currency default tax rate on confirmation page for the FAB create flow" This reverts commit 56d8dbcca0049a91c1dfaaa44e7346dc59736ae7. --- .../hooks/useTaxAmount.ts | 12 +---- tests/unit/hooks/useTaxAmount.test.ts | 52 ++----------------- 2 files changed, 4 insertions(+), 60 deletions(-) diff --git a/src/components/MoneyRequestConfirmationList/hooks/useTaxAmount.ts b/src/components/MoneyRequestConfirmationList/hooks/useTaxAmount.ts index 4e88796e7340..6c3b000fab8f 100644 --- a/src/components/MoneyRequestConfirmationList/hooks/useTaxAmount.ts +++ b/src/components/MoneyRequestConfirmationList/hooks/useTaxAmount.ts @@ -59,17 +59,7 @@ function useTaxAmount({ const defaultTaxCode = getDefaultTaxCode(policy, transaction) ?? (isMovingTransactionFromTrackExpense ? (getDefaultTaxCode(policyForMovingExpenses, transaction) ?? '') : ''); const defaultTaxValue = getTaxValue(policy, transaction, defaultTaxCode) ?? null; const previousDefaultTaxCode = getDefaultTaxCode(policy, transaction, previousTransactionCurrency); - - // A tax code the user never manually chose: it is one of the policy's auto-defaults (workspace-currency or - // foreign-currency default), but not the default for the *current* currency. This happens when the currency - // changed after the default was auto-applied and the amount step had no policy to recompute it (e.g. the create - // flow started from the FAB, where the amount step has no report/policy context). Treat it as stale so the current - // currency's default is re-applied instead of being preserved as if it were a deliberate selection. - const isStaleAutoDefault = - !!transaction?.taxCode && - (transaction.taxCode === policy?.taxRates?.defaultExternalID || transaction.taxCode === policy?.taxRates?.foreignTaxDefault) && - transaction.taxCode !== defaultTaxCode; - const shouldKeepCurrentTaxSelection = hasTaxRateWithMatchingValue(policy, transaction) && transaction?.taxCode !== previousDefaultTaxCode && !isStaleAutoDefault; + const shouldKeepCurrentTaxSelection = hasTaxRateWithMatchingValue(policy, transaction) && transaction?.taxCode !== previousDefaultTaxCode; // Calculate and set tax amount in transaction draft const taxableAmount = isDistanceRequest ? DistanceRequestUtils.getTaxableAmount(policy, customUnitRateID, distance) : Math.abs(transaction?.amount ?? 0); diff --git a/tests/unit/hooks/useTaxAmount.test.ts b/tests/unit/hooks/useTaxAmount.test.ts index f3132fd245dc..f0b7b8ea23e0 100644 --- a/tests/unit/hooks/useTaxAmount.test.ts +++ b/tests/unit/hooks/useTaxAmount.test.ts @@ -19,18 +19,14 @@ jest.mock('@libs/DistanceRequestUtils', () => ({ }, })); -const mockGetDefaultTaxCode = jest.fn(); -const mockGetTaxValue = jest.fn(); -const mockHasTaxRateWithMatchingValue = jest.fn(); - jest.mock('@libs/TransactionUtils', () => ({ calculateTaxAmount: (taxPercentage: string, taxableAmount: number) => { const pct = Number.parseFloat(String(taxPercentage).replace('%', '')) || 0; return (taxableAmount * pct) / 100; }, - getDefaultTaxCode: (...args: unknown[]) => mockGetDefaultTaxCode(...args), - getTaxValue: (...args: unknown[]) => mockGetTaxValue(...args), - hasTaxRateWithMatchingValue: (...args: unknown[]) => mockHasTaxRateWithMatchingValue(...args), + getDefaultTaxCode: () => 'tax_default', + getTaxValue: () => '10%', + hasTaxRateWithMatchingValue: () => false, })); type Params = Parameters[0]; @@ -47,16 +43,6 @@ const baseParams: Params = { }; describe('useTaxAmount', () => { - beforeEach(() => { - mockGetDefaultTaxCode.mockReturnValue('tax_default'); - mockGetTaxValue.mockReturnValue('10%'); - mockHasTaxRateWithMatchingValue.mockReturnValue(false); - }); - - afterEach(() => { - jest.clearAllMocks(); - }); - it('returns the default tax code and value from policy resolution', () => { const {result} = renderHook(() => useTaxAmount(baseParams)); expect(result.current.defaultTaxCode).toBe('tax_default'); @@ -79,36 +65,4 @@ describe('useTaxAmount', () => { const {result} = renderHook(() => useTaxAmount(baseParams)); expect(result.current.shouldKeepCurrentTaxSelection).toBe(false); }); - - it('shouldKeepCurrentTaxSelection is false when the current tax code is a stale policy default from before a currency change (FAB flow)', () => { - // The current currency default is the foreign default, but the draft still carries the workspace-currency - // default that was auto-applied before the currency was switched (the amount step had no policy to recompute it). - mockGetDefaultTaxCode.mockReturnValue('tax_foreign'); - mockHasTaxRateWithMatchingValue.mockReturnValue(true); - const policy = {taxRates: {defaultExternalID: 'tax_workspace', foreignTaxDefault: 'tax_foreign'}} as unknown as OnyxTypes.Policy; - const {result} = renderHook(() => - useTaxAmount({ - ...baseParams, - policy, - transaction: {transactionID: 'txn1', amount: 1000, currency: 'EUR', taxCode: 'tax_workspace'} as unknown as OnyxTypes.Transaction, - previousTransactionCurrency: 'EUR', - }), - ); - expect(result.current.shouldKeepCurrentTaxSelection).toBe(false); - }); - - it('shouldKeepCurrentTaxSelection stays true for a manually selected non-default tax code', () => { - mockGetDefaultTaxCode.mockReturnValue('tax_foreign'); - mockHasTaxRateWithMatchingValue.mockReturnValue(true); - const policy = {taxRates: {defaultExternalID: 'tax_workspace', foreignTaxDefault: 'tax_foreign'}} as unknown as OnyxTypes.Policy; - const {result} = renderHook(() => - useTaxAmount({ - ...baseParams, - policy, - transaction: {transactionID: 'txn1', amount: 1000, currency: 'EUR', taxCode: 'tax_custom'} as unknown as OnyxTypes.Transaction, - previousTransactionCurrency: 'USD', - }), - ); - expect(result.current.shouldKeepCurrentTaxSelection).toBe(true); - }); }); From f82d957c81cc66a3efdbae085ac3f710c9a8768c Mon Sep 17 00:00:00 2001 From: "Eskalifer1 (via MelvinBot)" Date: Mon, 6 Jul 2026 16:42:45 +0000 Subject: [PATCH 13/22] Extract isTaxCodeAutoDefaultForCurrency helper to dedupe tax-default logic Co-authored-by: Eskalifer1 --- .../iou/request/step/AmountSubmission.ts | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/pages/iou/request/step/AmountSubmission.ts b/src/pages/iou/request/step/AmountSubmission.ts index d62a4e8b1d61..9d365068e777 100644 --- a/src/pages/iou/request/step/AmountSubmission.ts +++ b/src/pages/iou/request/step/AmountSubmission.ts @@ -205,6 +205,21 @@ function getIsP2PForAmount({chatReportForP2P, currentUserAccountID}: GetIsP2PFor return isParticipantP2P(firstParticipant); } +/** + * Determines whether a transaction's current tax code is still the auto-applied default for the given currency + * (i.e. the user has not manually picked a different rate). Used by both the create and edit submit paths to + * decide whether a currency change should re-apply the new currency's default tax rate. + */ +function isTaxCodeAutoDefaultForCurrency( + policy: OnyxEntry, + transaction: OnyxEntry, + currency: string | undefined, + taxCode: string | undefined, +): boolean { + const defaultTaxCodeForCurrency = getDefaultTaxCode(policy, transaction, currency); + return !taxCode || taxCode === defaultTaxCodeForCurrency; +} + /** * Submission orchestration for `IOURequestStepAmount`. Verbatim port of the previous inline * `saveAmountAndCurrency` + `navigateToNextPage` handlers. All submit-only Onyx values are read @@ -274,8 +289,7 @@ function submitAmount({ // Only do this when the current tax code is still the auto-applied default for the previous currency, so a tax // rate the user manually selected is preserved across the currency change. const previousCurrency = getCurrency(transaction); - const previousDefaultTaxCode = getDefaultTaxCode(policy, transaction, previousCurrency); - const isCurrentTaxAutoDefault = !transaction?.taxCode || transaction?.taxCode === previousDefaultTaxCode; + const isCurrentTaxAutoDefault = isTaxCodeAutoDefaultForCurrency(policy, transaction, previousCurrency, transaction?.taxCode); // Only re-apply a currency default when the workspace actually tracks tax (mirrors the confirmation page's // `shouldShowTax` gate). Without this, a currency change would persist a tax code and amount on a workspace // that has tax tracking disabled. The amount step is always a manual expense, so distance is `false` here. @@ -544,8 +558,7 @@ function submitAmount({ // the currency change (mirrors the create-flow guard in `navigateToNextPage`). const transactionTaxCode = getTransactionDetails(currentTransaction)?.taxCode; const defaultTaxCode = getDefaultTaxCode(policy, currentTransaction, selectedCurrency) ?? ''; - const previousDefaultTaxCode = getDefaultTaxCode(policy, currentTransaction, transactionCurrency); - const isCurrentTaxAutoDefault = !transactionTaxCode || transactionTaxCode === previousDefaultTaxCode; + const isCurrentTaxAutoDefault = isTaxCodeAutoDefaultForCurrency(policy, currentTransaction, transactionCurrency, transactionTaxCode); // The edit path has no confirmation-page safety net, so heal a tax code that is no longer a valid rate on the // policy (e.g. the rate was deleted or the expense moved workspaces) by falling back to the currency default. const isTransactionTaxCodeValid = hasTaxRateWithMatchingValue(policy, currentTransaction); From a01f421386af0ff7e78faf6ee4ec8d005c83d9f6 Mon Sep 17 00:00:00 2001 From: "Eskalifer1 (via MelvinBot)" Date: Mon, 6 Jul 2026 17:19:12 +0000 Subject: [PATCH 14/22] Heal only missing tax codes on edit, preserving codes with drifted values Co-authored-by: Eskalifer1 --- src/pages/iou/request/step/AmountSubmission.ts | 11 +++++++---- tests/unit/AmountSubmissionTest.ts | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/pages/iou/request/step/AmountSubmission.ts b/src/pages/iou/request/step/AmountSubmission.ts index 9d365068e777..01e638952f67 100644 --- a/src/pages/iou/request/step/AmountSubmission.ts +++ b/src/pages/iou/request/step/AmountSubmission.ts @@ -18,7 +18,7 @@ import Permissions from '@libs/Permissions'; import {isTaxTrackingEnabled} from '@libs/PolicyUtils'; import {getPolicyExpenseChat, getTransactionDetails, isMoneyRequestReport, isPolicyExpenseChat, isSelfDM, shouldEnableNegative} from '@libs/ReportUtils'; import shouldUseDefaultExpensePolicy from '@libs/shouldUseDefaultExpensePolicy'; -import {calculateTaxAmount, getAmount, getCurrency, getDefaultTaxCode, getIsFromGlobalCreate, getTaxValue, hasReceipt, hasTaxRateWithMatchingValue} from '@libs/TransactionUtils'; +import {calculateTaxAmount, getAmount, getCurrency, getDefaultTaxCode, getIsFromGlobalCreate, getTaxValue, hasReceipt} from '@libs/TransactionUtils'; import { getMoneyRequestParticipantsFromReport, @@ -559,9 +559,12 @@ function submitAmount({ const transactionTaxCode = getTransactionDetails(currentTransaction)?.taxCode; const defaultTaxCode = getDefaultTaxCode(policy, currentTransaction, selectedCurrency) ?? ''; const isCurrentTaxAutoDefault = isTaxCodeAutoDefaultForCurrency(policy, currentTransaction, transactionCurrency, transactionTaxCode); - // The edit path has no confirmation-page safety net, so heal a tax code that is no longer a valid rate on the - // policy (e.g. the rate was deleted or the expense moved workspaces) by falling back to the currency default. - const isTransactionTaxCodeValid = hasTaxRateWithMatchingValue(policy, currentTransaction); + // The edit path has no confirmation-page safety net, so heal a tax code that no longer exists on the policy + // (e.g. the rate was deleted or the expense moved workspaces) by falling back to the currency default. We only + // check that the code still resolves to a rate — not that its value matches — so a code whose value drifted + // (e.g. an admin edited the rate's percentage) keeps the user's selection and self-heals its `taxPercentage` + // from the policy on the next line. + const isTransactionTaxCodeValid = getTaxValue(policy, currentTransaction, transactionTaxCode ?? '') !== undefined; const taxCode = ((selectedCurrency !== transactionCurrency && isCurrentTaxAutoDefault) || !isTransactionTaxCodeValid ? defaultTaxCode : transactionTaxCode) ?? defaultTaxCode; const taxPercentage = getTaxValue(policy, currentTransaction, taxCode) ?? ''; const taxAmount = convertToBackendAmount(calculateTaxAmount(taxPercentage, newAmount, decimals)); diff --git a/tests/unit/AmountSubmissionTest.ts b/tests/unit/AmountSubmissionTest.ts index dc281f69c433..32b25b63c622 100644 --- a/tests/unit/AmountSubmissionTest.ts +++ b/tests/unit/AmountSubmissionTest.ts @@ -426,6 +426,24 @@ describe('AmountSubmission', () => { expect(mockUpdateMoneyRequestAmountAndCurrency).toHaveBeenCalledWith(expect.objectContaining({taxCode: 'idForeign'})); }); + it('preserves a tax code whose stored value drifted from the policy on edit (heals only missing codes)', () => { + submitAmount( + buildBaseArgs({ + action: CONST.IOU.ACTION.EDIT, + iouType: CONST.IOU.TYPE.SUBMIT, + policy: taxPolicy, + // The code still exists on the policy, but its stored value is stale (e.g. an admin edited the + // rate's percentage after this expense was created). The currency is unchanged, so the only reason + // to swap the code would be an invalid one — but a drifted value is not invalid, so it is preserved. + transaction: {...buildTaxTransaction('idManual'), taxValue: '3%'}, + selectedCurrency: CONST.CURRENCY.USD, + amount: '20', + }), + ); + + expect(mockUpdateMoneyRequestAmountAndCurrency).toHaveBeenCalledWith(expect.objectContaining({taxCode: 'idManual'})); + }); + it('calls sendMoneyElsewhere on non-edit + skip-confirm + PAY (non-wallet)', () => { submitAmount( buildBaseArgs({ From 37106dd947974a90395f9b712c15992ce992c981 Mon Sep 17 00:00:00 2001 From: "Eskalifer1 (via MelvinBot)" Date: Mon, 6 Jul 2026 17:41:40 +0000 Subject: [PATCH 15/22] Preserve intentionally-cleared tax on amount edit An empty tax code ('') is a legitimate persisted 'no tax' selection, but the edit-path heal treated it as invalid and re-applied the workspace default when only the amount changed. Treat '' as valid so it is preserved. Co-authored-by: Eskalifer1 --- src/pages/iou/request/step/AmountSubmission.ts | 5 +++-- tests/unit/AmountSubmissionTest.ts | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/pages/iou/request/step/AmountSubmission.ts b/src/pages/iou/request/step/AmountSubmission.ts index 01e638952f67..de8537808a02 100644 --- a/src/pages/iou/request/step/AmountSubmission.ts +++ b/src/pages/iou/request/step/AmountSubmission.ts @@ -563,8 +563,9 @@ function submitAmount({ // (e.g. the rate was deleted or the expense moved workspaces) by falling back to the currency default. We only // check that the code still resolves to a rate — not that its value matches — so a code whose value drifted // (e.g. an admin edited the rate's percentage) keeps the user's selection and self-heals its `taxPercentage` - // from the policy on the next line. - const isTransactionTaxCodeValid = getTaxValue(policy, currentTransaction, transactionTaxCode ?? '') !== undefined; + // from the policy on the next line. An empty code (`''`) is an intentionally-cleared tax, a legitimate + // persisted selection, so we treat it as valid and never heal it back to the default. + const isTransactionTaxCodeValid = transactionTaxCode === '' || getTaxValue(policy, currentTransaction, transactionTaxCode ?? '') !== undefined; const taxCode = ((selectedCurrency !== transactionCurrency && isCurrentTaxAutoDefault) || !isTransactionTaxCodeValid ? defaultTaxCode : transactionTaxCode) ?? defaultTaxCode; const taxPercentage = getTaxValue(policy, currentTransaction, taxCode) ?? ''; const taxAmount = convertToBackendAmount(calculateTaxAmount(taxPercentage, newAmount, decimals)); diff --git a/tests/unit/AmountSubmissionTest.ts b/tests/unit/AmountSubmissionTest.ts index 32b25b63c622..377f1aa36774 100644 --- a/tests/unit/AmountSubmissionTest.ts +++ b/tests/unit/AmountSubmissionTest.ts @@ -444,6 +444,23 @@ describe('AmountSubmission', () => { expect(mockUpdateMoneyRequestAmountAndCurrency).toHaveBeenCalledWith(expect.objectContaining({taxCode: 'idManual'})); }); + it('preserves an intentionally-cleared tax (empty code) on edit when only the amount changes', () => { + submitAmount( + buildBaseArgs({ + action: CONST.IOU.ACTION.EDIT, + iouType: CONST.IOU.TYPE.SUBMIT, + policy: taxPolicy, + // The user deliberately cleared the tax (`taxCode === ''`). Editing only the amount (same currency) + // must not re-add the workspace default tax — an empty code is a legitimate persisted selection. + transaction: buildTaxTransaction(''), + selectedCurrency: CONST.CURRENCY.USD, + amount: '20', + }), + ); + + expect(mockUpdateMoneyRequestAmountAndCurrency).toHaveBeenCalledWith(expect.objectContaining({taxCode: ''})); + }); + it('calls sendMoneyElsewhere on non-edit + skip-confirm + PAY (non-wallet)', () => { submitAmount( buildBaseArgs({ From 7ab258e16b1c84c7c7c4d6c40696995f66958d7d Mon Sep 17 00:00:00 2001 From: "Eskalifer1 (via MelvinBot)" Date: Tue, 7 Jul 2026 08:24:06 +0000 Subject: [PATCH 16/22] Preserve intentionally-cleared tax on currency change in shared heal taxCode === '' is how the create flow persists an intentionally cleared 'no tax' selection. isTaxCodeAutoDefaultForCurrency previously treated '' as auto-default (via the falsy !taxCode check), so a currency change re-applied the new currency's default and wiped the user's cleared selection. Return false for '' so the cleared tax is preserved on currency change, matching how the edit path already treats '' as a legitimate cleared tax. Co-authored-by: Eskalifer1 --- src/pages/iou/request/step/AmountSubmission.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pages/iou/request/step/AmountSubmission.ts b/src/pages/iou/request/step/AmountSubmission.ts index de8537808a02..49cd805735ca 100644 --- a/src/pages/iou/request/step/AmountSubmission.ts +++ b/src/pages/iou/request/step/AmountSubmission.ts @@ -216,6 +216,9 @@ function isTaxCodeAutoDefaultForCurrency( currency: string | undefined, taxCode: string | undefined, ): boolean { + if (taxCode === '') { + return false; + } const defaultTaxCodeForCurrency = getDefaultTaxCode(policy, transaction, currency); return !taxCode || taxCode === defaultTaxCodeForCurrency; } From cd71be871709dba88406bd3769a92adeaf4c985f Mon Sep 17 00:00:00 2001 From: "Eskalifer1 (via MelvinBot)" Date: Tue, 7 Jul 2026 08:31:41 +0000 Subject: [PATCH 17/22] Trim helper JSDoc to explain the why, not where it is used Co-authored-by: Eskalifer1 --- src/pages/iou/request/step/AmountSubmission.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/iou/request/step/AmountSubmission.ts b/src/pages/iou/request/step/AmountSubmission.ts index 49cd805735ca..3994d0f54ba6 100644 --- a/src/pages/iou/request/step/AmountSubmission.ts +++ b/src/pages/iou/request/step/AmountSubmission.ts @@ -207,8 +207,7 @@ function getIsP2PForAmount({chatReportForP2P, currentUserAccountID}: GetIsP2PFor /** * Determines whether a transaction's current tax code is still the auto-applied default for the given currency - * (i.e. the user has not manually picked a different rate). Used by both the create and edit submit paths to - * decide whether a currency change should re-apply the new currency's default tax rate. + * (i.e. the user has not manually picked a different rate). */ function isTaxCodeAutoDefaultForCurrency( policy: OnyxEntry, From edd77b09a3b58e52da6467f0f2d890f0f9bd42cf Mon Sep 17 00:00:00 2001 From: "Eskalifer1 (via MelvinBot)" Date: Tue, 7 Jul 2026 09:03:32 +0000 Subject: [PATCH 18/22] Remove verbose tax-tracking gate comment per review Co-authored-by: Eskalifer1 --- src/pages/iou/request/step/AmountSubmission.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/pages/iou/request/step/AmountSubmission.ts b/src/pages/iou/request/step/AmountSubmission.ts index 3994d0f54ba6..36147bc24940 100644 --- a/src/pages/iou/request/step/AmountSubmission.ts +++ b/src/pages/iou/request/step/AmountSubmission.ts @@ -292,11 +292,6 @@ function submitAmount({ // rate the user manually selected is preserved across the currency change. const previousCurrency = getCurrency(transaction); const isCurrentTaxAutoDefault = isTaxCodeAutoDefaultForCurrency(policy, transaction, previousCurrency, transaction?.taxCode); - // Only re-apply a currency default when the workspace actually tracks tax (mirrors the confirmation page's - // `shouldShowTax` gate). Without this, a currency change would persist a tax code and amount on a workspace - // that has tax tracking disabled. The amount step is always a manual expense, so distance is `false` here. - // In the global-create (FAB) flow there is no `report`, so recognize the workspace via the transaction's - // selected participant too — mirroring how `policyID` is resolved on this step. const isPolicyExpenseChatParticipant = transaction?.participants?.some((participant) => participant.isPolicyExpenseChat) ?? false; const isTaxEnabled = isTaxTrackingEnabled(isPolicyExpenseChat(report) || isPolicyExpenseChatParticipant, policy, false); From 2aa7c6cdb989c3578e20237a6baf707f9f494a1d Mon Sep 17 00:00:00 2001 From: "Eskalifer1 (via MelvinBot)" Date: Tue, 7 Jul 2026 09:09:44 +0000 Subject: [PATCH 19/22] Remove verbose comment on create-path tax recompute Co-authored-by: Eskalifer1 --- src/pages/iou/request/step/AmountSubmission.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/pages/iou/request/step/AmountSubmission.ts b/src/pages/iou/request/step/AmountSubmission.ts index 36147bc24940..e0bd4af1be19 100644 --- a/src/pages/iou/request/step/AmountSubmission.ts +++ b/src/pages/iou/request/step/AmountSubmission.ts @@ -286,10 +286,6 @@ function submitAmount({ setMoneyRequestAmount(transactionID, amountInSmallestCurrencyUnits, selectedCurrency || CONST.CURRENCY.USD, shouldKeepUserInput, hasReceipt(transaction)); - // When the currency changes, re-apply the default tax rate for the new currency so the confirmation page and the - // created expense reflect the currency-appropriate default (e.g. the foreign default for a foreign currency). - // Only do this when the current tax code is still the auto-applied default for the previous currency, so a tax - // rate the user manually selected is preserved across the currency change. const previousCurrency = getCurrency(transaction); const isCurrentTaxAutoDefault = isTaxCodeAutoDefaultForCurrency(policy, transaction, previousCurrency, transaction?.taxCode); const isPolicyExpenseChatParticipant = transaction?.participants?.some((participant) => participant.isPolicyExpenseChat) ?? false; From 7117f3d369ee4c25dc7d137720e30aaf731d5488 Mon Sep 17 00:00:00 2001 From: "Eskalifer1 (via MelvinBot)" Date: Tue, 7 Jul 2026 09:19:15 +0000 Subject: [PATCH 20/22] Remove verbose edit-path and policyID comments per review Co-authored-by: Eskalifer1 --- src/pages/iou/request/step/AmountSubmission.ts | 9 --------- src/pages/iou/request/step/IOURequestStepAmount.tsx | 3 --- 2 files changed, 12 deletions(-) diff --git a/src/pages/iou/request/step/AmountSubmission.ts b/src/pages/iou/request/step/AmountSubmission.ts index e0bd4af1be19..a352f15b4138 100644 --- a/src/pages/iou/request/step/AmountSubmission.ts +++ b/src/pages/iou/request/step/AmountSubmission.ts @@ -546,18 +546,9 @@ function submitAmount({ return; } - // When the currency changes we re-apply the new currency's default tax rate, but only when the current tax rate is - // still the auto-applied default for the previous currency. A tax rate the user picked manually is preserved across - // the currency change (mirrors the create-flow guard in `navigateToNextPage`). const transactionTaxCode = getTransactionDetails(currentTransaction)?.taxCode; const defaultTaxCode = getDefaultTaxCode(policy, currentTransaction, selectedCurrency) ?? ''; const isCurrentTaxAutoDefault = isTaxCodeAutoDefaultForCurrency(policy, currentTransaction, transactionCurrency, transactionTaxCode); - // The edit path has no confirmation-page safety net, so heal a tax code that no longer exists on the policy - // (e.g. the rate was deleted or the expense moved workspaces) by falling back to the currency default. We only - // check that the code still resolves to a rate — not that its value matches — so a code whose value drifted - // (e.g. an admin edited the rate's percentage) keeps the user's selection and self-heals its `taxPercentage` - // from the policy on the next line. An empty code (`''`) is an intentionally-cleared tax, a legitimate - // persisted selection, so we treat it as valid and never heal it back to the default. const isTransactionTaxCodeValid = transactionTaxCode === '' || getTaxValue(policy, currentTransaction, transactionTaxCode ?? '') !== undefined; const taxCode = ((selectedCurrency !== transactionCurrency && isCurrentTaxAutoDefault) || !isTransactionTaxCodeValid ? defaultTaxCode : transactionTaxCode) ?? defaultTaxCode; const taxPercentage = getTaxValue(policy, currentTransaction, taxCode) ?? ''; diff --git a/src/pages/iou/request/step/IOURequestStepAmount.tsx b/src/pages/iou/request/step/IOURequestStepAmount.tsx index 9b381bb8575a..a7b2ac79e704 100644 --- a/src/pages/iou/request/step/IOURequestStepAmount.tsx +++ b/src/pages/iou/request/step/IOURequestStepAmount.tsx @@ -77,9 +77,6 @@ function IOURequestStepAmount({ const iouRequestType = getRequestType(transaction); const isTrackExpense = iouType === CONST.IOU.TYPE.TRACK; const {policyForMovingExpensesID} = usePolicyForMovingExpenses(); - // In the global-create (FAB) flow there is no report context, so `report?.policyID` is undefined. Fall back to - // the policy of an already-selected workspace participant so the tax-rate recompute in `submitAmount` has a policy - // when the user returns to this step to change the currency after picking a workspace on the confirmation page. const participantPolicyID = transaction?.participants?.find((participant) => participant.isPolicyExpenseChat)?.policyID; const policyID = (isTrackExpense ? policyForMovingExpensesID : report?.policyID) ?? participantPolicyID; From 927d46323919523627ca1be5ecd0c57ad71081ab Mon Sep 17 00:00:00 2001 From: "{\"message\":\"Not Found\",\"documentation_url\":\"https://docs.github.com/rest/issues/comments#get-an-issue-comment\",\"status\":\"404\"} (via MelvinBot)" Date: Mon, 20 Jul 2026 07:51:35 +0000 Subject: [PATCH 21/22] Include track-expense tax contexts in the currency-change tax recompute guard Co-authored-by: {"message":"Not Found","documentation_url":"https://docs.github.com/rest/issues/comments#get-an-issue-comment","status":"404"} <{"message":"Not Found","documentation_url":"https://docs.github.com/rest/issues/comments#get-an-issue-comment","status":"404"}@users.noreply.github.com> --- src/libs/IOUAmountSubmission.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libs/IOUAmountSubmission.ts b/src/libs/IOUAmountSubmission.ts index 8825ccd056d4..c6b3b462c2b0 100644 --- a/src/libs/IOUAmountSubmission.ts +++ b/src/libs/IOUAmountSubmission.ts @@ -48,7 +48,7 @@ import {getLoginByAccountID} from './PersonalDetailsUtils'; import {isTaxTrackingEnabled} from './PolicyUtils'; import {getPolicyExpenseChat, getTransactionDetails, isMoneyRequestReport, isPolicyExpenseChat, isSelfDM, shouldEnableNegative} from './ReportUtils'; import shouldUseDefaultExpensePolicy from './shouldUseDefaultExpensePolicy'; -import {calculateTaxAmount, getAmount, getCurrency, getDefaultTaxCode, getIsFromGlobalCreate, getTaxValue, hasReceipt} from './TransactionUtils'; +import {calculateTaxAmount, getAmount, getCurrency, getDefaultTaxCode, getIsFromGlobalCreate, getTaxValue, hasReceipt, isExpenseUnreported} from './TransactionUtils'; type SubmitAmountArgs = { report: OnyxEntry; @@ -516,7 +516,15 @@ function submitCreateAmount(args: SubmitAmountArgs, ctx: SubmitAmountContext): v const previousCurrency = getCurrency(transaction); const isCurrentTaxAutoDefault = isTaxCodeAutoDefaultForCurrency(policy, transaction, previousCurrency, transaction?.taxCode); const isPolicyExpenseChatParticipant = transaction?.participants?.some((participant) => participant.isPolicyExpenseChat) ?? false; - const isTaxEnabled = isTaxTrackingEnabled(isPolicyExpenseChat(report) || isPolicyExpenseChatParticipant, policy, false); + // Mirror the tax contexts the confirmation list uses (see MoneyRequestConfirmationList's shouldShowTax): a Track + // expense from a self-DM/default workspace isn't a policy expense chat, but the confirmation page still shows tax + // for the track flow, so the currency recompute must run for it too. Otherwise Back → change currency → Next would + // leave the stale previous-currency default tax on the draft. + const isTaxEnabled = isTaxTrackingEnabled( + isPolicyExpenseChat(report) || isPolicyExpenseChatParticipant || iouType === CONST.IOU.TYPE.TRACK || isExpenseUnreported(transaction), + policy, + false, + ); if (isMovingTransactionFromTrackExpense(action) || (isTaxEnabled && selectedCurrency !== previousCurrency && isCurrentTaxAutoDefault)) { const taxCode = getDefaultTaxCode(policy, transaction, selectedCurrency); From 5696f8b4460d0a9a1aa63dc2ece14c356f3edafc Mon Sep 17 00:00:00 2001 From: "{\"message\":\"Not Found\",\"documentation_url\":\"https://docs.github.com/rest/issues/comments#get-an-issue-comment\",\"status\":\"404\"} (via MelvinBot)" Date: Tue, 21 Jul 2026 12:31:10 +0000 Subject: [PATCH 22/22] Add empty line before tax contexts comment per review feedback Co-authored-by: {"message":"Not Found","documentation_url":"https://docs.github.com/rest/issues/comments#get-an-issue-comment","status":"404"} <{"message":"Not Found","documentation_url":"https://docs.github.com/rest/issues/comments#get-an-issue-comment","status":"404"}@users.noreply.github.com> --- src/libs/IOUAmountSubmission.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/IOUAmountSubmission.ts b/src/libs/IOUAmountSubmission.ts index c6b3b462c2b0..353e78d97da2 100644 --- a/src/libs/IOUAmountSubmission.ts +++ b/src/libs/IOUAmountSubmission.ts @@ -516,6 +516,7 @@ function submitCreateAmount(args: SubmitAmountArgs, ctx: SubmitAmountContext): v const previousCurrency = getCurrency(transaction); const isCurrentTaxAutoDefault = isTaxCodeAutoDefaultForCurrency(policy, transaction, previousCurrency, transaction?.taxCode); const isPolicyExpenseChatParticipant = transaction?.participants?.some((participant) => participant.isPolicyExpenseChat) ?? false; + // Mirror the tax contexts the confirmation list uses (see MoneyRequestConfirmationList's shouldShowTax): a Track // expense from a self-DM/default workspace isn't a policy expense chat, but the confirmation page still shows tax // for the track flow, so the currency recompute must run for it too. Otherwise Back → change currency → Next would