Skip to content

Commit ac2fafa

Browse files
MelvinBothoangzinh
andcommitted
Only fall back to default tax in getTaxName when tax tracking is enabled
When a user deletes tax from an expense (with taxes disabled), the API returns taxCode: null which Onyx strips to undefined. getTaxName then falls back to defaultTaxCode via the || operator and displays the default tax rate instead of showing empty. This uses policy.tax.trackingEnabled to decide the fallback: if taxes are enabled and taxCode is falsy, fall back to the default (fixing issue 85729). If taxes are disabled and taxCode is falsy, return undefined so the display shows empty (fixing issue 87667). Co-authored-by: Vinh Hoang <hoangzinh@users.noreply.github.com>
1 parent cd199f8 commit ac2fafa

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/libs/TransactionUtils/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,9 +2141,12 @@ function getWorkspaceTaxesSettingsName(policy: OnyxEntry<Policy>, taxCode: strin
21412141
function getTaxName(policy: OnyxEntry<Policy>, transaction: OnyxEntry<Transaction>, shouldFallbackToValue = false) {
21422142
const defaultTaxCode = getDefaultTaxCode(policy, transaction);
21432143

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

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

tests/unit/TransactionUtilsTest.ts

Lines changed: 1 addition & 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

0 commit comments

Comments
 (0)