[$175] Tax amount is shown 0 even if the tax rate is not 0
If you havenβt already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.
Version Number: v9.5.26-0 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://github.com/Expensify/App/pull/101674 Email or phone of affected tester (no customers): [email protected] Issue reported by: Applause Internal Team Bug source: Pull Request QA execution Device used: Windows 11 pro /Chrome , IPhone 15 pro/ IOS 27.0.1 App Component: Money Requests
Action Performed:
Prerequisites:
- Use an Expensifail account with a workspace that has Taxes, Distance rates, and Rules enabled.
- Under Taxes, create a non-default rate TaxA at 10%. Leave the workspace default as Tax exempt (0%).
- Under Distance rates, enable Track tax and create a rate Rate-NoTax, leaving its tax rate unset.
- Under Rules > Add rule > Apply expense defaults, add a rule with Category Car and Tax TaxA. Save.
Steps:
- Navigate to staging.new.expensify.com
- Open the workspace chat and start a distance expense.
- Set a route and continue to the confirm page.
- Set Rate to Rate-NoTax.
- Set Category to Car.
Expected Result:
The Tax field should show TaxA (10%) and Tax amount is 10% of the expense amount, not 0
Actual Result:
Tax amount is zero
Workaround:
Unknown
Platforms:
- [ ] Android: App
- [ ] Android: mWeb Chrome
- [x] iOS: App
- [ ] iOS: mWeb Safari
- [ ] iOS: mWeb Chrome
- [x] Windows: Chrome
- [ ] MacOS: Chrome Safari
Screenshots/Videos
https://github.com/user-attachments/assets/17eb19b3-5bc1-442c-b87a-c229df77fde2
Applause Internal Information Exported by: Rizky Gunawan Bug ID: 7300056
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022116020332749301136
- Upwork Job ID: 2116020332749301136
- Last Price Increase: 2026-10-30
Issue Owner
Current Issue Owner: @getusha
While Applause doesn't embed attachments for this bug, here are the links for quick view: https://platform.applause.com/services/links/v1/external/f3eee2bbb69e59e309e73527201cdac88126cc225529a49b6651ea7cb3d059da
Proposal
What is the root cause of that problem?
The tax rate is now correct, but the amount it is applied to is 0.
For distance expenses, tax is only charged on the rate's "Tax reclaimable on" share. getTaxableAmount multiplies the distance amount by the rate's taxClaimablePercentage. It falls back to 0 when that field is unset.
Rate-NoTax has no tax rate. The workspace page only shows "Tax reclaimable on" after a rate has a tax rate (PolicyDistanceRateDetailsPage.tsx:273). So on this rate the field can never be set, and the taxable amount is always 0.
Apply category tax rules to distance expenses without a rate tax (deployed in 9.5.26-0) made the category rule pick TaxA for these rates. It still runs the amount through getTaxableAmount in useTaxAmount.ts:94 and tax.ts:158. The result is 10% Γ 0 = 0. That PR's unit tests only check the tax code and value, not the amount.
What changes do you think we should make in order to solve the problem?
When a distance rate has no selectable tax rate of its own, tax the full distance amount instead of 0.
- In
DistanceRequestUtils.getTaxableAmount, use1as the claimable share when the rate has no selectabletaxRateExternalID. Keep the current behavior for rates that do have a tax rate. - Apply the same rule in the split flow.
SplitExpenseItems.ts:327copies the sametaxClaimablePercentage ?? 0logic. - Add unit tests that check
taxAmountfor a category-rule tax on a rate with no tax: 10% of the distance amount.
What alternative solutions did you explore? (Optional)
Default taxClaimablePercentage to 1 for every rate. This also changes rates that have a tax rate but no reclaimable amount. Today those produce 0 tax, and changing that is outside this bug's scope.
Open question and confidence
- Confidence: medium. The code path is clear, but I did not reproduce it in the app.
- Product should confirm that a rule-applied tax on a rate with no tax rate covers the full amount. The issue's expected result and the PR's test steps both say so.
- The backend may recalculate distance tax when the expense is created. If it uses the same reclaimable share, it may also need a change outside App.
Related issue
- Expense - Tax selected on created rule is not displayed on confirm page of distance expense: the original issue the PR above fixed. This bug is the tax amount part that it missed.
Next Steps for Contributor+ team:
To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/105451) to create a draft PR.
To refine: @MelvinBot <your feedback>
To reject: Explain why you are rejecting Melvin's proposal.
Triggered auto assignment to Contributor-plus team member for initial proposal review - @aimane-chnaif (External)
Job added to Upwork: https://www.upwork.com/jobs/~022116020332749301136
Please re-state the problem that we are trying to solve in this issue.
When creating a distance expense using a distance rate that does not have its own tax rate configured (Rate-NoTax), a category-based expense rule correctly applies TaxA (10%). However, the calculated tax amount remains 0 instead of being calculated against the full distance expense amount.
The expected behaviour is that when a tax is applied through a category rule and the selected distance rate has no active rate-level tax, the tax should be calculated on 100% of the distance expense amount.
What is the root cause of that problem?
In src/libs/DistanceRequestUtils.ts, the getTaxableAmount function calculates the taxable amount by multiplying the distance expense amount by the rate's taxClaimablePercentage.
When taxClaimablePercentage is undefined, the calculation falls back to CONST.DEFAULT_NUMBER_ID (0).
For distance rates without a rate-level tax, the workspace settings do not expose the "Tax reclaimable on" field, so this percentage remains undefined. Consequently, the taxable amount becomes zero even when a category-based tax has been applied correctly.
There is also a related issue in src/libs/actions/IOU/SplitExpenseItems.ts, where the same fallback calculation is duplicated.
Simply changing the fallback to 1 would introduce a regression for distance rates that have an active rate-level tax but an undefined reclaimable percentage. Additionally, checking only whether taxRateExternalID exists would not handle stale tax IDs pointing to disabled or deleted tax rates.
What changes do you think we should make in order to solve the problem?
-
Introduce a reusable
getTaxClaimablePercentagehelper insrc/libs/DistanceRequestUtils.ts. -
Determine whether the distance rate has an active, selectable rate-level tax using the existing
isSelectableTaxCodeutility. -
Return
1(100%) when the distance rate has no active rate-level tax, including when its tax ID is missing or no longer selectable. -
When an active rate-level tax exists, preserve the existing
taxClaimablePercentagevalue and its current fallback toCONST.DEFAULT_NUMBER_ID. This ensures that existing reclaimability behaviour remains unchanged. -
Reuse this helper in both
getTaxableAmountandsrc/libs/actions/IOU/SplitExpenseItems.tsso regular and split distance expenses follow the same calculation logic. -
Add regression tests covering:
- Distance rates without a rate-level tax.
- Distance rates with disabled or unavailable rate-level tax IDs.
- Active rate-level taxes with a configured reclaimable percentage.
- Active rate-level taxes with an undefined reclaimable percentage.
- Split distance expenses with category-based taxes.
-
Verify that the calculated tax remains correct after saving and reopening a distance expense, and investigate whether any backend recalculation requires a corresponding change.
What alternative solutions did you explore?
Changing the fallback directly from CONST.DEFAULT_NUMBER_ID to 1 was considered, but it would incorrectly change the behaviour of existing distance rates with active rate-level taxes and an undefined reclaimable percentage.
Checking only whether taxRateExternalID is present was also considered, but this would not handle stale tax IDs associated with disabled or deleted tax rates.
Centralizing the decision in a reusable helper provides a consistent calculation across the regular distance expense, tax update, and split expense flows without changing the existing getTaxableAmount function signature.
π£ @Aswathypalakkal! π£ Hey, it seems we donβt have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:
- Make sure you've read and understood the contributing guidelines.
- Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
- Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
- Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>
Proposal
Please re-state the problem that we are trying to solve in this issue.
When creating a distance expense using a distance rate that has no rate-level tax rate configured (Rate-NoTax) and selecting a category (Car) that has an expense default rule applying TaxA (10%), the Tax field displays TaxA (10%) as expected, but the calculated Tax amount displays 0 instead of 10% of the distance expense amount.
What is the root cause of that problem?
- In
src/libs/DistanceRequestUtils.ts(getTaxableAmount, lines 810β821), the taxable amount for a distance expense is calculated by multiplying the reimbursable distance amount bycustomUnitRate.attributes?.taxClaimablePercentage, falling back toCONST.DEFAULT_NUMBER_ID(0):const taxClaimablePercentage = customUnitRate.attributes?.taxClaimablePercentage ?? CONST.DEFAULT_NUMBER_ID; return amount * taxClaimablePercentage; - In the workspace distance rate settings (
PolicyDistanceRateDetailsPage.tsx:273), the "Tax reclaimable on" (taxClaimablePercentage) field is only shown and editable when the distance rate has its own rate-level tax configured (!!taxRate). On a rate where tax is unset (Rate-NoTax),taxClaimablePercentageis never configured and remainsundefined. - In PR #101674 ("Apply category tax rules to distance expenses without a rate tax"),
getDistanceCategoryTaxCode/getDistanceRateTaxUpdatesinsrc/libs/TransactionUtils/tax.tsanduseTaxAmount.tswere updated so that a category tax rule correctly appliesTaxA (10%)when the distance rate has no selectable rate-level tax rate (!hasSelectableRateTaxCode(policy, customUnitRateID)). - However, both
useTaxAmount.ts(line 77) andgetDistanceRateTaxUpdates(tax.ts, line 118) pass the distance throughDistanceRequestUtils.getTaxableAmount(policy, customUnitRateID, taxableDistance). BecausetaxClaimablePercentageisundefined,getTaxableAmountmultiplies the amount by0, causingcalculateTaxAmount('10%', 0, decimals)to evaluate to0. - PR #101674's tests in
tests/unit/TransactionUtilsTest.tsonly assertedcategoryTaxCodeandcategoryTaxValue, whiletests/unit/hooks/useTaxAmount.test.tsmockedgetTaxableAmountreturning100, which masked the regression. - In addition,
src/libs/actions/IOU/SplitExpenseItems.ts(line 327) duplicatessplitAmount * (splitCustomUnitRate?.attributes?.taxClaimablePercentage ?? CONST.DEFAULT_NUMBER_ID), which produces the same0tax amount when splitting distance expenses.
Key Distinction / Flaw in Prior Proposals:
- Simply falling back to
1unconditionally breaks existing testtests/unit/DistanceRequestUtilsTest.ts:911(andIOURequestStepConfirmationPageTest.tsx:1076), where a distance rate explicitly has a rate-level tax configured but "Tax reclaimable on" was omitted / left at 0.- Checking
if (!hasActiveRateTaxCode) return 1;before checkingtaxClaimablePercentage(as proposed in earlier comments) creates a critical regression intests/actions/IOU/SplitExpenseItemsTest.ts:264(applies the distance rate's claimable percentage to the fallback tax). In that test, a distance rate has a configuredtaxClaimablePercentage: 0.5whose rate-level tax was disabled; overwriting the configured percentage with1breaks the test expectation (expected 455, received 909).- The configured
taxClaimablePercentagemust always be respected first when defined (customUnitRate?.attributes?.taxClaimablePercentage ?? ...). Only whentaxClaimablePercentageisundefinedshould the fallback check whether the rate has an active selectable rate-level tax (0) or not (1).
What changes do you think we should make in order to solve the problem?
1. Centralize hasSelectableRateTaxCode in src/libs/PolicyUtils/tax.ts & export via PolicyUtils
In src/libs/PolicyUtils/tax.ts, export hasSelectableRateTaxCode so it can be shared across TransactionUtils, DistanceRequestUtils, and SplitExpenseItems:
/**
* Whether a distance rate carries a tax rate the user can still pick. Disabling a tax rate leaves the rate pointing at
* it, so a rate the user can no longer pick is treated the same as a rate that never had one.
*/
function hasSelectableRateTaxCode(policy: OnyxEntry<Policy>, customUnitRateID: string): boolean {
const rateTaxCode = getDistanceRateCustomUnitRate(policy, customUnitRateID)?.attributes?.taxRateExternalID;
if (!rateTaxCode) {
return false;
}
return !policy?.taxRates?.taxes || isSelectableTaxCode(policy, rateTaxCode);
}
(Export hasSelectableRateTaxCode from src/libs/PolicyUtils/index.ts and replace the local private helper in src/libs/TransactionUtils/tax.ts with this import).
2. Introduce getTaxClaimablePercentage in src/libs/DistanceRequestUtils.ts and update getTaxableAmount
In src/libs/DistanceRequestUtils.ts:
/**
* Get the tax claimable percentage for a distance rate.
* When a distance rate has no selectable rate-level tax rate (e.g. Rate-NoTax or a disabled tax rate),
* taxes applied via category rules, workspace defaults, or manual selection tax 100% (1) of the distance amount.
* When a rate has an active selectable rate-level tax, use the configured taxClaimablePercentage, falling back to 0.
*/
function getTaxClaimablePercentage(policy: OnyxEntry<Policy>, customUnitRateID: string): number {
const customUnitRate = getDistanceRateCustomUnitRate(policy, customUnitRateID);
return customUnitRate?.attributes?.taxClaimablePercentage ?? (hasSelectableRateTaxCode(policy, customUnitRateID) ? CONST.DEFAULT_NUMBER_ID : 1);
}
function getTaxableAmount(policy: OnyxEntry<Policy>, customUnitRateID: string, distance: number) {
const distanceUnit = getDistanceRateCustomUnit(policy);
const customUnitRate = getDistanceRateCustomUnitRate(policy, customUnitRateID);
if (!distanceUnit?.customUnitID || !customUnitRate) {
return 0;
}
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 = getTaxClaimablePercentage(policy, customUnitRateID);
return amount * taxClaimablePercentage;
}
Export getTaxClaimablePercentage on DistanceRequestUtils.
3. Reuse getTaxClaimablePercentage in src/libs/actions/IOU/SplitExpenseItems.ts
In src/libs/actions/IOU/SplitExpenseItems.ts (lines 326β328):
const taxableAmount = isDistanceRequestTransactionUtils(transaction) && splitCustomUnitRateID
? splitAmount * DistanceRequestUtils.getTaxClaimablePercentage(policy, splitCustomUnitRateID)
: splitAmount;
This ensures split distance expenses, regular distance expenses, and rate updates share identical calculation rules without code duplication.
What alternative solutions did you explore? (Optional)
- Passing a boolean flag (e.g.
isCategoryTax) intogetTaxableAmount: Rejected because manual tax selections and workspace default taxes on distance rates without a rate-level tax also need 100% taxable amount, and changinggetTaxableAmount's signature breaks multiple callers and hooks. - Hardcoding
taxClaimablePercentage ?? 1: Rejected because it regresses distance rates configured with active rate-level taxes where the admin intentionally left "Tax reclaimable on" unset (tested inDistanceRequestUtilsTest.ts:911). - Checking
!hasActiveRateTaxCodebeforetaxClaimablePercentage: Rejected because it regressestests/actions/IOU/SplitExpenseItemsTest.ts:264, overwriting explicit0.5percentages with1whenever the rate tax is disabled.
Automated Tests
1. In tests/unit/DistanceRequestUtilsTest.ts
Add test cases in describe('getTaxableAmount'):
it('should return 100% of distance amount when distance rate has no rate-level tax configured', () => {
// Given a policy distance rate without a rate-level tax (Rate-NoTax)
const rateWithoutTaxID = 'B593F3FBBB0BD'; // attributes: {}
const expectedAmount = DistanceRequestUtils.getDistanceRequestAmount(totalDistance, distanceUnit, 900);
// When computing the taxable amount
const result = DistanceRequestUtils.getTaxableAmount(FAKE_POLICY, rateWithoutTaxID, totalDistance);
// Then the full distance expense amount is taxable (factor 1)
expect(result).toBe(expectedAmount);
});
it('should return 100% of distance amount when distance rate tax rate is disabled and reclaimable percentage is undefined', () => {
// Given a policy distance rate whose tax rate is disabled and reclaimable percentage is undefined
const policyWithDisabledTaxRate: Policy = {
...FAKE_POLICY,
taxRates: {
...CONST.DEFAULT_TAX,
taxes: {
...CONST.DEFAULT_TAX.taxes,
id_TAX_RATE_1: {name: 'Tax Rate 1', value: '10%', isDisabled: true},
},
},
};
const expectedAmount = DistanceRequestUtils.getDistanceRequestAmount(totalDistance, distanceUnit, 72.5);
// When computing the taxable amount
const result = DistanceRequestUtils.getTaxableAmount(policyWithDisabledTaxRate, customUnitRateIDWithOutTaxClaimablePercentage, totalDistance);
// Then the fallback is 1 because the rate has no active selectable rate tax
expect(result).toBe(expectedAmount);
});
2. In tests/unit/TransactionUtilsTest.ts
In describe('distance expenses'), update the test case to assert categoryTaxAmount:
it('should apply the category rule when distance tax tracking is on and the rate has no tax rate of its own', () => {
// Given a policy whose distance rates track tax, where the selected rate has no tax rate of its own
const category = 'Advertising';
const fakePolicy = buildDistancePolicy(category, true);
// When retrieving the tax from the associated category
const {categoryTaxCode, categoryTaxAmount, categoryTaxValue} = TransactionUtils.getCategoryTaxDetails(
category,
buildDistanceTransaction(),
fakePolicy,
getCurrencyDecimalsLocal,
);
// Then the category rule fills the slot the rate left empty, and tax amount is calculated on 100% of the distance amount
expect(categoryTaxCode).toBe('id_TAX_RATE_1');
expect(categoryTaxValue).toBe('5%');
expect(categoryTaxAmount).toBeGreaterThan(0);
});
Contributor details
Your Expensify account email: [email protected]
Upwork Profile Link: https://www.upwork.com/freelancers/~014bb7d4c250a1fe03
β οΈ Missing/invalid email or upwork profile link. Please make sure you add both your Expensify email and Upwork profile link in the format specified.
π£ @jashory! π£ Hey, it seems we donβt have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:
- Make sure you've read and understood the contributing guidelines.
- Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
- Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
- Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>
Proposal
Please re-state the problem that we are trying to solve in this issue.
When creating or editing a distance expense in a workspace where:
- Taxes and Distance rates are enabled,
- A distance rate (
Rate-NoTax) has no rate-level tax configured (attributes.taxRateExternalIDis undefined), - A category (
Car) with an expense default tax rule (e.g.TaxA (10%)) is selected, The Tax rate correctly displaysTaxA (10%), but the calculated Tax amount is displayed as0instead of10%of the distance expense amount.
What is the root cause of that problem?
- In
src/libs/DistanceRequestUtils.ts(getTaxableAmount):function getTaxableAmount(policy: OnyxEntry<Policy>, customUnitRateID: string, distance: number) { ... const amount = getDistanceRequestAmount(distance, unit, rate); const taxClaimablePercentage = customUnitRate.attributes?.taxClaimablePercentage ?? CONST.DEFAULT_NUMBER_ID; return amount * taxClaimablePercentage; } - When a distance rate does not have a rate-level tax configured (
Rate-NoTax), the workspace distance rate settings do not show or settaxClaimablePercentage(PolicyDistanceRateDetailsPage.tsx:273only renders the claimable percentage input when!!taxRate). As a result,customUnitRate.attributes?.taxClaimablePercentageisundefined. - Because
taxClaimablePercentage ?? CONST.DEFAULT_NUMBER_IDdefaultsundefinedto0,getTaxableAmountreturnsamount * 0 = 0. - In
useTaxAmount.ts(line 77) andgetDistanceRateTaxUpdates(tax.ts, line 118), the taxable distance amount returned fromgetTaxableAmountis0, socalculateTaxAmount(taxPercentage, 0, decimals)evaluates to0. - For distance rates without a rate-level tax, taxes applied via category rules, workspace defaults, or manual tax selections apply to 100% of the distance amount. Defaulting
taxClaimablePercentageto0when there is no rate-level tax causes the tax amount to zero out.
What changes do you think we should make in order to solve the problem?
-
In
src/libs/DistanceRequestUtils.ts: IngetTaxableAmount, check whether the custom unit rate has an active selectable rate-level tax (reusinghasSelectableRateTaxCodefromsrc/libs/PolicyUtils/tax.ts):- When the rate has an active selectable rate-level tax, fall back to
CONST.DEFAULT_NUMBER_ID(0) iftaxClaimablePercentageis undefined (preserving existing rate-level tax behavior and passingDistanceRequestUtilsTest.ts:911). - When the rate has no selectable rate-level tax (such as
Rate-NoTaxor disabled rate taxes), fall back to1(100% taxable amount):
function getTaxableAmount(policy: OnyxEntry<Policy>, customUnitRateID: string, distance: number) { const distanceUnit = getDistanceRateCustomUnit(policy); const customUnitRate = getDistanceRateCustomUnitRate(policy, customUnitRateID); if (!distanceUnit?.customUnitID || !customUnitRate) { return 0; } 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 hasRateTax = hasSelectableRateTaxCode(policy, customUnitRateID); const taxClaimablePercentage = customUnitRate.attributes?.taxClaimablePercentage ?? (hasRateTax ? CONST.DEFAULT_NUMBER_ID : 1); return amount * taxClaimablePercentage; } - When the rate has an active selectable rate-level tax, fall back to
-
In
src/libs/actions/IOU/SplitExpenseItems.ts: Update line 327 to use the same logic when calculating taxable amount for split distance expenses:const hasRateTax = hasSelectableRateTaxCode(policy, splitCustomUnitRateID); const taxClaimablePercentage = splitCustomUnitRate?.attributes?.taxClaimablePercentage ?? (hasRateTax ? CONST.DEFAULT_NUMBER_ID : 1); const taxableAmount = isDistanceRequestTransactionUtils(transaction) && splitCustomUnitRateID ? splitAmount * taxClaimablePercentage : splitAmount;
Automated Tests
In tests/unit/DistanceRequestUtilsTest.ts:
Add a test case in describe('getTaxableAmount'):
it('should return 100% of distance amount when distance rate has no rate-level tax configured', () => {
// Given a rate without rate-level tax (attributes: {})
const result = DistanceRequestUtils.getTaxableAmount(FAKE_POLICY, 'B593F3FBBB0BD', totalDistance);
const expectedAmount = DistanceRequestUtils.getDistanceRequestAmount(totalDistance, distanceUnit, 900);
expect(result).toBe(expectedAmount);
});
What alternative solutions did you explore? (Optional)
- Unconditionally defaulting
taxClaimablePercentage ?? 1: Rejected because it breakstests/unit/DistanceRequestUtilsTest.ts:911where distance rates with rate-level taxes intentionally omit the claimable percentage. Conditioning onhasSelectableRateTaxCodecorrectly preserves rate-level tax behavior while ensuring category rules and manual taxes apply to 100% of non-taxed distance rates.
Contributor details
Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0105126232377c4c5c
β Contributor details stored successfully. Thank you for contributing to Expensify!
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~015b34e130d9aad41d
Proposal
Please re-state the problem that we are trying to solve in this issue.
When creating or editing a distance expense with a distance rate that has no rate-level tax configured (Rate-NoTax) and selecting a category with an expense rule applying a tax rate (e.g., TaxA 10%), the Tax field correctly updates to TaxA (10%), but the Tax amount displays as 0 instead of 10% of the distance expense amount.
What is the root cause of that problem?
In src/libs/DistanceRequestUtils.ts:819-820 (getTaxableAmount):
const taxClaimablePercentage = customUnitRate?.attributes?.taxClaimablePercentage ?? 0;
return amount * taxClaimablePercentage;
- In
PolicyDistanceRateDetailsPage.tsx:273, the "Tax reclaimable on" field is only displayed and editable when a distance rate has a rate-level tax rate selected (taxRateExternalID). When a distance rate has no tax rate (Rate-NoTax),taxClaimablePercentageis undefined. - In PR #101674, category rules were enabled to apply tax to distance expenses without rate taxes. However,
getTaxableAmountfalls back to0whentaxClaimablePercentageis unset (amount * 0 = 0). Consequently, inuseTaxAmount.tsandtax.ts, calculating10% * taxableAmountresults in10% * 0 = 0. - The identical unhandled fallback exists in
src/libs/actions/IOU/SplitExpenseItems.ts:327:
const taxableAmount = isDistanceRequestTransactionUtils(transaction)
? splitAmount * (splitCustomUnitRate?.attributes?.taxClaimablePercentage ?? 0)
: splitAmount;
What changes do you think we should make in order to solve the problem?
-
In
src/libs/DistanceRequestUtils.ts: When a distance rate does not have a selectable rate-leveltaxRateExternalID, any tax applied to the distance expense (via category rules, default policy tax, or manual entry) should apply to100%(1) of the distance amount. Only when a selectable rate-level tax exists should it respecttaxClaimablePercentage ?? 0:function getTaxClaimablePercentage(policy: OnyxEntry<Policy>, customUnitRate: OnyxEntry<Rate>): number { if (!customUnitRate) { return CONST.DEFAULT_NUMBER_ID; } const rateTaxCode = customUnitRate.attributes?.taxRateExternalID; const taxes = policy?.taxRates?.taxes; const rateTaxRate = rateTaxCode ? taxes?.[rateTaxCode] : undefined; const hasSelectableRateTax = !!rateTaxCode && !!rateTaxRate && !rateTaxRate.isDisabled && rateTaxRate.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; if (!hasSelectableRateTax) { return 1; } return customUnitRate.attributes?.taxClaimablePercentage ?? CONST.DEFAULT_NUMBER_ID; } function getTaxableAmount(policy: OnyxEntry<Policy>, customUnitRateID: string, distance: number) { const distanceUnit = getDistanceRateCustomUnit(policy); const customUnitRate = getDistanceRateCustomUnitRate(policy, customUnitRateID); if (!distanceUnit?.customUnitID || !customUnitRate) { return 0; } 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 = getTaxClaimablePercentage(policy, customUnitRate); return amount * taxClaimablePercentage; } -
In
src/libs/actions/IOU/SplitExpenseItems.ts:326-328: UseDistanceRequestUtils.getTaxClaimablePercentage(policy, splitCustomUnitRate):const taxableAmount = isDistanceRequestTransactionUtils(transaction) ? splitAmount * DistanceRequestUtils.getTaxClaimablePercentage(policy, splitCustomUnitRate) : splitAmount; -
Automated Unit Tests: Add unit tests in
tests/unit/TaxUtilsTest.tsandtests/unit/DistanceRequestUtilsTest.ts:- Test that for distance rates without a rate-level tax,
getTaxableAmountevaluates to 100% of the distance amount when a category rule tax is present. - Test that distance rates with an active rate-level tax preserve their configured
taxClaimablePercentage.
- Test that for distance rates without a rate-level tax,
What alternative solutions did you explore? (Optional)
Defaulting taxClaimablePercentage to 1 unconditionally across all rates was explored, but rejected because rates that explicitly configure a rate tax without reclaimable percentage would be unintentionally changed. Gating the 1 fallback strictly to rates without selectable rate-level tax preserves existing behavior.
β Contributor details stored successfully. Thank you for contributing to Expensify!
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a workspace has Distance rates and Taxes enabled, and an admin configures a custom tax rate on a distance rate without manually editing the Tax claimable percentage (leaving customUnitRate.attributes.taxClaimablePercentage as undefined after setting the tax rate), creating a distance expense with that rate displays and calculates a tax amount of $0.00 even though a non-zero tax rate is selected.
What is the root cause of that problem?
- In
src/libs/DistanceRequestUtils.ts:810β821,getTaxableAmountcalculates the taxable portion of a distance expense using:const amount = getDistanceRequestAmount(distance, unit, rate); const taxClaimablePercentage = customUnitRate.attributes?.taxClaimablePercentage ?? CONST.DEFAULT_NUMBER_ID; return amount * taxClaimablePercentage; - Likewise, in
src/libs/actions/IOU/SplitExpenseItems.ts:326β328,initSplitExpenseItemDatacomputes the taxable amount for distance split expenses when resolving stale tax values using the same fallback:const taxableAmount = isDistanceRequestTransactionUtils(transaction) ? splitAmount * (splitCustomUnitRate?.attributes?.taxClaimablePercentage ?? CONST.DEFAULT_NUMBER_ID) : splitAmount; - Because
CONST.DEFAULT_NUMBER_IDis0, whenevercustomUnitRate.attributes?.taxClaimablePercentageisundefined(for example, when a tax rate is assigned to a distance rate before a claimable percentage is explicitly set, or when a distance expense uses a selectable workspace tax rate whiletaxClaimablePercentageis unset),getTaxableAmountmultipliesamountby0and returns0. - Consequently, both
src/components/MoneyRequestConfirmationList/hooks/useTaxAmount.ts:94β100andsrc/libs/TransactionUtils/tax.ts:158β162(getDistanceRateTaxUpdates) passtaxableAmount = 0intocalculateTaxAmount, resulting in a$0.00tax amount despite a valid non-zero tax rate.
What changes do you think we should make in order to solve the problem?
We need a single, consistent helper that resolves the effective taxClaimablePercentage for a distance rate without breaking either:
tests/unit/DistanceRequestUtilsTest.ts:911β914(should return 0 if tax reclaimable percentage is undefined, whereFAKE_POLICYhas notaxRatescollection, soisSelectableTaxCodeisfalse), ortests/actions/IOU/SplitExpenseItemsTest.ts:264β278(applies the distance rate's claimable percentage to the fallback tax, where the rate's owntaxRateExternalIDis disabled and the split falls back to the policy's selectabledefaultExternalID).
Specifically:
- Add
getDistanceRateTaxClaimablePercentageinsrc/libs/PolicyUtils/customUnits.ts(re-exported viasrc/libs/PolicyUtils/index.ts:11):- If
customUnitRate?.attributes?.taxClaimablePercentage !== undefined, returncustomUnitRate.attributes.taxClaimablePercentage. - Otherwise, check whether distance tax tracking is enabled (
getDistanceRateCustomUnit(policy)?.attributes?.taxEnabled) and whether eithercustomUnitRate?.attributes?.taxRateExternalIDorpolicy?.taxRates?.defaultExternalIDis a selectable tax code onpolicy(isSelectableTaxCode). If so, default the claimable percentage to1(100%); otherwise returnCONST.DEFAULT_NUMBER_ID(0).
function getDistanceRateTaxClaimablePercentage(policy: OnyxEntry<Policy>, customUnitRate: Rate | undefined): number { if (customUnitRate?.attributes?.taxClaimablePercentage !== undefined) { return customUnitRate.attributes.taxClaimablePercentage; } const distanceUnit = getDistanceRateCustomUnit(policy); if (!distanceUnit?.attributes?.taxEnabled) { return CONST.DEFAULT_NUMBER_ID; } const rateTaxCode = customUnitRate?.attributes?.taxRateExternalID; const defaultTaxCode = policy?.taxRates?.defaultExternalID; if (isSelectableTaxCode(policy, rateTaxCode) || isSelectableTaxCode(policy, defaultTaxCode)) { return 1; } return CONST.DEFAULT_NUMBER_ID; } - If
- Update
getTaxableAmountinsrc/libs/DistanceRequestUtils.ts:819:- const taxClaimablePercentage = customUnitRate.attributes?.taxClaimablePercentage ?? CONST.DEFAULT_NUMBER_ID; + const taxClaimablePercentage = getDistanceRateTaxClaimablePercentage(policy, customUnitRate); - Update
initSplitExpenseItemDatainsrc/libs/actions/IOU/SplitExpenseItems.ts:326β328:- const taxableAmount = isDistanceRequestTransactionUtils(transaction) - ? splitAmount * (splitCustomUnitRate?.attributes?.taxClaimablePercentage ?? CONST.DEFAULT_NUMBER_ID) - : splitAmount; + const taxableAmount = isDistanceRequestTransactionUtils(transaction) + ? splitAmount * getDistanceRateTaxClaimablePercentage(policy, splitCustomUnitRate) + : splitAmount; - Add unit tests in
tests/unit/DistanceRequestUtilsTest.tsandtests/actions/IOU/SplitExpenseItemsTest.ts:- Verify
getTaxableAmountreturns0whentaxClaimablePercentageisundefinedand no selectable tax rate exists onpolicy(preservingDistanceRequestUtilsTest.ts:911), and returns100%of the distance request amount whentaxClaimablePercentageisundefinedbut the rate or policy has an active selectable tax rate.
- Verify
What alternative solutions did you explore? (Optional)
- Replacing
?? CONST.DEFAULT_NUMBER_IDdirectly with?? 1inDistanceRequestUtils.ts:819: Rejected because when a policy has no active selectable tax rates (such asFAKE_POLICYinDistanceRequestUtilsTest.ts:911β914),getTaxableAmountmust return0whentaxClaimablePercentageisundefined. - Falling back to
1only whenhasSelectableRateTaxCode(policy, customUnitRateID)istrue: Rejected because when a distance rate's owntaxRateExternalIDis disabled or unset and the expense uses a category tax rule or the workspace'sdefaultExternalID(as tested inSplitExpenseItemsTest.ts:264β278),hasSelectableRateTaxCodeisfalseeven though a valid tax rate applies to the distance expense.
@aimane-chnaif Whoops! This issue is 2 days overdue. Let's get this updated quick!
@aimane-chnaif Whoops! This issue is 2 days overdue. Let's get this updated quick!
@aimane-chnaif Whoops! This issue is 2 days overdue. Let's get this updated quick!
@aimane-chnaif Eep! 4 days overdue now. Issues have feelings too...
@aimane-chnaif Huh... This is 4 days overdue. Who can take care of this?
@aimane-chnaif Eep! 4 days overdue now. Issues have feelings too...