Skip to content
Closed
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
11 changes: 7 additions & 4 deletions src/libs/TransactionUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2167,11 +2167,14 @@ 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);
// Don't fall back to the default tax code when taxCode is empty/undefined.
// Expense creation explicitly sets taxCode to the default (MoneyRequest.ts),
// so a missing taxCode means tax was deleted or never existed — not "use default".
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 taxRate = Object.values(transformedTaxRates(policy, transaction)).find((rate) => rate.code === transaction.taxCode);

if (shouldFallbackToValue && transaction?.taxValue !== undefined && taxRate?.value !== transaction?.taxValue) {
return transaction?.taxValue;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/IOU/UpdateMoneyRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ function getUpdateMoneyRequestParams(params: GetUpdateMoneyRequestParamsType): U
apiParams.attendees = JSON.stringify(apiParams?.attendees);
}

// Clear out the error fields and loading states on success
// Clear out the error fields and loading states on success.
successData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
Expand Down
15 changes: 13 additions & 2 deletions tests/unit/TransactionUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1881,15 +1881,26 @@ 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 transaction has no taxCode (tax deleted or never set)', () => {
const transaction = generateTransaction({
taxCode: undefined,
taxValue: undefined,
});

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

expect(result).toBe('');
});

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