Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/libs/TransactionUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2148,11 +2148,13 @@ function getWorkspaceTaxesSettingsName(policy: OnyxEntry<Policy>, taxCode: strin
* Gets the name corresponding to the taxCode that is displayed to the user
*/
function getTaxName(policy: OnyxEntry<Policy>, transaction: OnyxEntry<Transaction>, shouldFallbackToValue = false) {
const defaultTaxCode = getDefaultTaxCode(policy, transaction);
// An empty string taxCode means tax was explicitly cleared (e.g. via "Delete tax"), so return undefined
if (transaction?.taxCode === '') {
return undefined;
}

// transaction?.taxCode may be an empty string
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const taxRate = Object.values(transformedTaxRates(policy, transaction)).find((rate) => rate.code === (transaction?.taxCode || defaultTaxCode));
const defaultTaxCode = getDefaultTaxCode(policy, transaction);
const taxRate = Object.values(transformedTaxRates(policy, transaction)).find((rate) => rate.code === (transaction?.taxCode ?? defaultTaxCode));

if (shouldFallbackToValue && transaction?.taxValue !== undefined && taxRate?.value !== transaction?.taxValue) {
return transaction?.taxValue;
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/TransactionUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1854,15 +1854,15 @@ describe('TransactionUtils', () => {
expect(result).toBe('Tax Rate 1 (5%)');
});

it('should return default tax name when transaction has empty taxCode', () => {
it('should return empty string when transaction has empty taxCode (tax was deleted)', () => {
const transaction = generateTransaction({
taxCode: '',
taxValue: undefined,
});

const result = TransactionUtils.getTaxRateTitle(policy, transaction, false, undefined);

expect(result).toBe('Tax exempt (0%) • Default');
expect(result).toBe('');
});

it('should return empty string when policy is undefined', () => {
Expand Down
Loading