Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/libs/DistanceRequestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ function getTaxableAmount(policy: OnyxEntry<Policy>, customUnitRateID: string, d
const unit = distanceUnit?.attributes?.unit ?? CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES;
const rate = customUnitRate?.rate ?? CONST.DEFAULT_NUMBER_ID;
const amount = getDistanceRequestAmount(distance, unit, rate);
const taxClaimablePercentage = customUnitRate.attributes?.taxClaimablePercentage ?? 1;
const taxClaimablePercentage = customUnitRate.attributes?.taxClaimablePercentage ?? CONST.DEFAULT_NUMBER_ID;
return amount * taxClaimablePercentage;
}

Expand Down
8 changes: 4 additions & 4 deletions tests/ui/components/IOURequestStepConfirmationPageTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ describe('IOURequestStepConfirmationPageTest', () => {
expect(transaction?.taxAmount).toBe(909);
});

it('should not zero out tax when re-selecting distance rate without reclaimable configured', async () => {
it('should zero out tax when re-selecting distance rate without reclaimable configured', async () => {
const policy = createPolicyWithTaxAndDistance();
const waypoints = createWaypoints('New York', 'Boston');

Expand Down Expand Up @@ -751,12 +751,12 @@ describe('IOURequestStepConfirmationPageTest', () => {

await waitForBatchedUpdatesWithAct();

// Read tax amount - should NOT be zero even though taxClaimablePercentage is not configured
// Read tax amount - should be zero since taxClaimablePercentage is not configured
const transaction = await OnyxUtils.get(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${TRANSACTION_ID}`);

// With the fix, taxClaimablePercentage defaults to 1 (100%), so tax should calculate correctly
// taxClaimablePercentage defaults to 0, so tax should calculate correctly consistently with how it is calculated in the backend
expect(transaction?.taxAmount).toBeDefined();
expect(transaction?.taxAmount).toBeGreaterThan(0);
expect(transaction?.taxAmount).toBe(0);

// Tax code should be taxRate2 (from the distance rate configuration)
expect(transaction?.taxCode).toBe('taxRate2');
Expand Down
48 changes: 46 additions & 2 deletions tests/unit/DistanceRequestUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import type {Unit} from '@src/types/onyx/Policy';
import type Policy from '@src/types/onyx/Policy';
import {translateLocal} from '../utils/TestHelper';

const customUnitRateIDWithTaxClaimablePercentage = 'FG515011039A4';
const rateWithTaxClaimablePercentage = 100;
const totalDistance = 1000;
const taxClaimablePercentage = 0.5;
const distanceUnit: Unit = CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES;
const customUnitRateIDWithOutTaxClaimablePercentage = 'EB515052039A4';
const FAKE_POLICY: Policy = {
id: 'CEEEDB0EC660F71A',
name: 'Test',
Expand All @@ -15,8 +21,8 @@ const FAKE_POLICY: Policy = {
customUnits: {
C9031B6F4725D: {
attributes: {
taxEnabled: false,
unit: 'mi',
taxEnabled: true,
unit: distanceUnit,
},
customUnitID: 'C9031B6F4725D',
defaultCategory: '',
Expand Down Expand Up @@ -52,6 +58,31 @@ const FAKE_POLICY: Policy = {
subRates: [],
pendingFields: {},
},
[customUnitRateIDWithOutTaxClaimablePercentage]: {
currency: 'USD',
customUnitRateID: `${customUnitRateIDWithOutTaxClaimablePercentage}`,
enabled: true,
name: 'Default Rate',
rate: 72.5,
subRates: [],
attributes: {
taxRateExternalID: 'id_TAX_RATE_1',
},
pendingFields: {},
},
[customUnitRateIDWithTaxClaimablePercentage]: {
currency: 'USD',
customUnitRateID: `${customUnitRateIDWithTaxClaimablePercentage}`,
enabled: true,
name: 'Default Rate',
rate: rateWithTaxClaimablePercentage,
subRates: [],
attributes: {
taxRateExternalID: 'id_TAX_RATE_1',
taxClaimablePercentage,
},
pendingFields: {},
},
},
},
},
Expand Down Expand Up @@ -179,6 +210,19 @@ describe('DistanceRequestUtils', () => {
});
});

describe('getTaxableAmount', () => {
it('should return 0 if tax reclaimable percentage is undefined', () => {
const result = DistanceRequestUtils.getTaxableAmount(FAKE_POLICY, customUnitRateIDWithOutTaxClaimablePercentage, totalDistance);
expect(result).toBe(0);
});

it('should return taxable amount that is greater than 0 if tax reclaimable percentage is greater than 0', () => {
const result = DistanceRequestUtils.getTaxableAmount(FAKE_POLICY, customUnitRateIDWithTaxClaimablePercentage, totalDistance);
const expectedTaxableAmount = taxClaimablePercentage * DistanceRequestUtils.getDistanceRequestAmount(totalDistance, distanceUnit, rateWithTaxClaimablePercentage);
expect(result).toEqual(expectedTaxableAmount);
});
});

describe('getRateForExpenseDisplay', () => {
const toLocaleDigitMock = (dot: string): string => dot;
const getCurrencySymbolMock = (currency: string): string | undefined => {
Expand Down
Loading