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
10 changes: 5 additions & 5 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ function MoneyRequestView({
originalCurrency: transactionOriginalCurrency,
postedDate: transactionPostedDate,
convertedAmount: transactionConvertedAmount,
convertedTaxAmount: transactionConvertedTaxAmount,
} = getTransactionDetails(displayTransaction, undefined, undefined, allowNegativeAmount, false) ?? {};
const transactionAttendees = useAttendees(transaction);
const isEmptyMerchant = isInvalidMerchantValue(transactionMerchant);
Expand Down Expand Up @@ -377,11 +376,12 @@ function MoneyRequestView({
const shouldShowCard = isFromCardImport && cardProgramName;

const taxRates = policy?.taxRates;
// Use the updated transaction tax amount in merge flow to have correct positive/negative sign
const actualTaxAmount = isFromMergeTransaction && updatedTransaction ? updatedTransaction.taxAmount : transactionTaxAmount;
const formattedTaxAmount = convertToDisplayString(actualTaxAmount ?? 0, actualCurrency);
const formattedTaxAmount =
updatedTransaction?.taxAmount !== undefined
? convertToDisplayString(Math.abs(updatedTransaction?.taxAmount), actualCurrency)
: convertToDisplayString(Math.abs(transactionTaxAmount ?? 0), actualCurrency);
// Skip a zero converted tax (e.g. tax exempt) so we don't render a redundant "Converted 0.00".
const formattedConvertedTaxAmount = transactionConvertedTaxAmount ? convertToDisplayString(transactionConvertedTaxAmount, moneyRequestReport?.currency) : '';
const formattedConvertedTaxAmount = transaction?.convertedTaxAmount ? convertToDisplayString(Math.abs(transaction.convertedTaxAmount), moneyRequestReport?.currency) : '';

const taxRatesDescription = taxRates?.name;

Expand Down
3 changes: 0 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ import {
getCardName,
getCategory,
getConvertedAmount,
getConvertedTaxAmount,
getCurrency,
getDescription,
getDisplayTransactionWithoutInvalidCommuterExclusion,
Expand Down Expand Up @@ -843,7 +842,6 @@ type TransactionDetails = {
odometerStart?: number;
odometerEnd?: number;
convertedAmount: number;
convertedTaxAmount?: number;
gpsCoordinates?: string;
};

Expand Down Expand Up @@ -5663,7 +5661,6 @@ function getTransactionDetails(
originalAmount: getOriginalAmount(transaction),
originalCurrency: getOriginalCurrency(transaction),
convertedAmount: getConvertedAmount(transaction, isFromExpenseReport, transaction?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID, allowNegativeAmount, disableOppositeConversion),
convertedTaxAmount: getConvertedTaxAmount(transaction, isFromExpenseReport),
postedDate: getFormattedPostedDate(transaction),
transactionID: transaction.transactionID,
...(isDistanceRequest(transaction) && {distance: transaction.comment?.customUnit?.quantity ?? undefined}),
Expand Down
24 changes: 4 additions & 20 deletions src/libs/TransactionUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,34 +533,19 @@ function getAmount(transaction: OnyxInputOrEntry<Transaction>, isFromExpenseRepo
}

/**
* Convert a stored tax amount to the sign we display.
* Return the tax amount field from the transaction.
*/
function normalizeTaxAmountSign(rawAmount: number | undefined, isFromExpenseReport: boolean): number {
function getTaxAmount(transaction: OnyxInputOrEntry<Transaction>, isFromExpenseReport: boolean): number {
// IOU requests cannot have negative values but they can be stored as negative values, let's return absolute value
if (!isFromExpenseReport) {
return Math.abs(rawAmount ?? 0);
return Math.abs(transaction?.taxAmount ?? 0);
}

// To avoid -0 being shown, lets only change the sign if the value is other than 0.
const amount = rawAmount ?? 0;
const amount = transaction?.taxAmount ?? 0;
return amount ? -amount : 0;
}

/**
* Return the tax amount field from the transaction.
*/
function getTaxAmount(transaction: OnyxInputOrEntry<Transaction>, isFromExpenseReport: boolean): number {
return normalizeTaxAmountSign(transaction?.taxAmount, isFromExpenseReport);
}

/**
* Return the converted tax amount field from the transaction.
* It follows the same sign convention as `getTaxAmount`.
*/
function getConvertedTaxAmount(transaction: OnyxInputOrEntry<Transaction>, isFromExpenseReport: boolean): number {
return normalizeTaxAmountSign(transaction?.convertedTaxAmount, isFromExpenseReport);
}

/**
* Return the tax code from the transaction.
*/
Expand Down Expand Up @@ -1992,7 +1977,6 @@ export {
getMCCForDisplay,
hasDisplayableMCC,
getConvertedAmount,
getConvertedTaxAmount,
isTimeRequest,
getExpenseTypeTranslationKey,
getDetailedExpenseTypeTranslationKey,
Expand Down
73 changes: 1 addition & 72 deletions tests/ui/MoneyRequestViewTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import initOnyxDerivedValues from '@userActions/OnyxDerived';

import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Policy, Transaction} from '@src/types/onyx';
import type {Policy} from '@src/types/onyx';

import type * as NativeNavigation from '@react-navigation/native';
import type {PartialDeep} from 'type-fest';
Expand Down Expand Up @@ -608,77 +608,6 @@ describe('MoneyRequestView edit fields', () => {
});
});

it('shows a negative tax amount for a negative expense on an expense report', async () => {
// Given a negative expense on an expense report. Expense reports store amounts with the opposite sign,
// so a -$9.50 expense with -$0.95 tax is stored as amount 950 and taxAmount 95.
const threadReport = {
...LHNTestUtils.getFakeReport(),
parentReportID: expenseReportID,
parentReportActionID,
};

await setupTestData();
await act(async () => {
await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {
amount: 950,
taxCode: 'TAX_10',
taxAmount: 95,
});
});
await waitForBatchedUpdatesWithAct();

// When the expense details are rendered
renderMoneyRequestView(threadReport, {tax: {trackingEnabled: true}});
await waitForBatchedUpdatesWithAct();

// Then the tax amount keeps the negative sign instead of being shown as an absolute value
await waitFor(() => {
expect(screen.getByLabelText('iou.taxAmount, USD-95')).toBeOnTheScreen();
});
});

it('shows a negative tax amount on the merge confirmation page for a negative merged expense', async () => {
// Given a merged expense preview on an expense report. The merge flow keeps amounts with the sign they are
// displayed with, so a -$9.50 expense with -$0.95 tax is kept as amount -950 and taxAmount -95.
await setupTestData();
const mergedTransaction = createMock<Transaction>({
transactionID,
reportID: expenseReportID,
amount: -950,
modifiedAmount: -950,
currency: CONST.CURRENCY.USD,
created: '2025-06-01',
merchant: 'Coffee Shop',
comment: {},
taxCode: 'TAX_10',
taxName: 'Tax 10%',
taxValue: '10%',
taxAmount: -95,
});

// When the merge confirmation page renders the merged expense
render(
<ComposeProviders components={[OnyxListItemProvider]}>
<ScreenWrapperStatusContext.Provider value={SCREEN_WRAPPER_STATUS}>
<MoneyRequestView
parentReportID={expenseReportID}
expensePolicy={createMock<Policy>({id: policyID, type: CONST.POLICY.TYPE.TEAM, outputCurrency: CONST.CURRENCY.USD, tax: {trackingEnabled: true}})}
shouldShowAnimatedBackground={false}
readonly
updatedTransaction={mergedTransaction}
mergeTransactionID={transactionID}
/>
</ScreenWrapperStatusContext.Provider>
</ComposeProviders>,
);
await waitForBatchedUpdatesWithAct();

// Then the tax amount keeps the negative sign instead of being flipped again for the expense report
await waitFor(() => {
expect(screen.getByLabelText('iou.taxAmount, USD-95')).toBeOnTheScreen();
});
});

it('does NOT append "Converted" to the Tax amount description when the converted tax is zero (tax exempt)', async () => {
const threadReport = {
...LHNTestUtils.getFakeReport(),
Expand Down
35 changes: 0 additions & 35 deletions tests/unit/TransactionUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4135,41 +4135,6 @@ describe('TransactionUtils', () => {
});
});

describe('getConvertedTaxAmount', () => {
it('should return the absolute converted tax amount if the transaction is not from an expense report', () => {
// Given an IOU transaction whose converted tax is stored as a negative value
const transaction = generateTransaction({convertedTaxAmount: -100});

// When we read the converted tax amount for a non-expense report
const convertedTaxAmount = TransactionUtils.getConvertedTaxAmount(transaction, false);

// Then it is returned unsigned, because IOU requests cannot have negative values
expect(convertedTaxAmount).toBe(100);
});

it('should return the opposite sign if the transaction is from an expense report', () => {
// Given an expense-report transaction whose converted tax is stored with the opposite sign of what we display
const transaction = generateTransaction({convertedTaxAmount: 182});

// When we read the converted tax amount for an expense report
const convertedTaxAmount = TransactionUtils.getConvertedTaxAmount(transaction, true);

// Then the sign is flipped back, so a refund's tax displays as negative
expect(convertedTaxAmount).toBe(-182);
});

it('should return 0 instead of -0 when there is no converted tax amount', () => {
// Given an expense-report transaction with no converted tax
const transaction = generateTransaction({convertedTaxAmount: 0});

// When we read the converted tax amount
const convertedTaxAmount = TransactionUtils.getConvertedTaxAmount(transaction, true);

// Then we get 0 rather than -0, so we never render "-0.00"
expect(Object.is(convertedTaxAmount, 0)).toBe(true);
});
});

describe('hasTaxRateWithMatchingValue', () => {
const policy: Policy = {
...createRandomPolicy(0),
Expand Down
Loading