Skip to content

Commit 0bdacd6

Browse files
authored
Merge pull request Expensify#88580 from Expensify/claude-fixTaxRateDefaultFallback
2 parents 62c8851 + 6d8714e commit 0bdacd6

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

src/libs/TransactionUtils/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,9 +2144,13 @@ function getWorkspaceTaxesSettingsName(policy: OnyxEntry<Policy>, taxCode: strin
21442144
function getTaxName(policy: OnyxEntry<Policy>, transaction: OnyxEntry<Transaction>, shouldFallbackToValue = false) {
21452145
const defaultTaxCode = getDefaultTaxCode(policy, transaction);
21462146

2147-
// transaction?.taxCode may be an empty string
2147+
// Only fall back to the default tax code when tax tracking is enabled on the policy.
2148+
// When taxes are disabled and the user deletes a tax, taxCode becomes undefined (the API returns null, which Onyx strips).
2149+
// Without this check, getTaxName would fall back to defaultTaxCode and display the default tax rate instead of showing empty.
2150+
// We use || instead of ?? because taxCode may be an empty string, which should also trigger the fallback.
21482151
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
2149-
const taxRate = Object.values(transformedTaxRates(policy, transaction)).find((rate) => rate.code === (transaction?.taxCode || defaultTaxCode));
2152+
const effectiveTaxCode = transaction?.taxCode || (policy?.tax?.trackingEnabled ? defaultTaxCode : undefined);
2153+
const taxRate = effectiveTaxCode ? Object.values(transformedTaxRates(policy, transaction)).find((rate) => rate.code === effectiveTaxCode) : undefined;
21502154

21512155
if (shouldFallbackToValue && transaction?.taxValue !== undefined && taxRate?.value !== transaction?.taxValue) {
21522156
return transaction?.taxValue;

tests/unit/TransactionUtilsTest.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,6 +1829,7 @@ describe('TransactionUtils', () => {
18291829
describe('getTaxRateTitle', () => {
18301830
const policy: Policy = {
18311831
...createRandomPolicy(0),
1832+
tax: {trackingEnabled: true},
18321833
taxRates: CONST.DEFAULT_TAX,
18331834
};
18341835

@@ -1892,6 +1893,22 @@ describe('TransactionUtils', () => {
18921893
expect(result).toBe('Tax exempt (0%) • Default');
18931894
});
18941895

1896+
it('should return empty string when trackingEnabled is false and transaction has no taxCode', () => {
1897+
const policyWithTrackingDisabled: Policy = {
1898+
...createRandomPolicy(0),
1899+
tax: {trackingEnabled: false},
1900+
taxRates: CONST.DEFAULT_TAX,
1901+
};
1902+
const transaction = generateTransaction({
1903+
taxCode: undefined,
1904+
taxValue: undefined,
1905+
});
1906+
1907+
const result = TransactionUtils.getTaxRateTitle(policyWithTrackingDisabled, transaction, false, undefined);
1908+
1909+
expect(result).toBe('');
1910+
});
1911+
18951912
it('should return empty string when policy is undefined', () => {
18961913
const transaction = generateTransaction({
18971914
taxCode: 'id_TAX_RATE_1',

0 commit comments

Comments
 (0)