Skip to content

Commit e8673ae

Browse files
committed
preserve the tax rate
1 parent 5b5031c commit e8673ae

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/components/MoneyRequestConfirmationList/sections/AmountField.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {convertToBackendAmount, convertToFrontendAmountAsString, getLocalizedCur
1515
import {calculateAmount, isMovingTransactionFromTrackExpense} from '@libs/IOUUtils';
1616
import Navigation from '@libs/Navigation/Navigation';
1717
import {shouldEnableNegative} from '@libs/ReportUtils';
18-
import {calculateTaxAmount, getTaxValue} from '@libs/TransactionUtils';
18+
import {calculateTaxAmount, getTaxCode, getTaxValue} from '@libs/TransactionUtils';
1919
import {isParticipantP2P} from '@pages/iou/request/step/IOURequestStepAmount';
2020
import IOURequestStepCurrencyModal from '@pages/iou/request/step/IOURequestStepCurrencyModal';
2121
import {resetSplitShares, setDraftSplitTransaction, setSplitShares} from '@userActions/IOU/Split';
@@ -240,6 +240,15 @@ function AmountField({
240240

241241
buildAndSaveSplitShares(updatedAmount, value);
242242
persistMainDraftTotal(updatedAmount, value);
243+
244+
if (isMovingTransactionFromTrackExpense(action)) {
245+
const taxCode = getTaxCode(transactionForHandlers);
246+
if (taxCode) {
247+
const taxPercentage = getTaxValue(policy, transactionForHandlers, taxCode) ?? '';
248+
const taxAmount = convertToBackendAmount(calculateTaxAmount(taxPercentage, updatedAmount, getCurrencyDecimals(value)));
249+
setMoneyRequestTaxAmount(transactionID, taxAmount);
250+
}
251+
}
243252
};
244253

245254
const handleAmountChange = (newAmount: string) => {
@@ -268,7 +277,8 @@ function AmountField({
268277

269278
if (isMovingTransactionFromTrackExpense(action)) {
270279
const amountInSmallestCurrencyUnits = convertToBackendAmount(Number.parseFloat(newAmount));
271-
const taxCode = effectiveCurrency !== policy?.outputCurrency ? policy?.taxRates?.foreignTaxDefault : policy?.taxRates?.defaultExternalID;
280+
const defaultTaxCode = effectiveCurrency !== policy?.outputCurrency ? policy?.taxRates?.foreignTaxDefault : policy?.taxRates?.defaultExternalID;
281+
const taxCode = getTaxCode(transactionForHandlers) || defaultTaxCode;
272282
if (taxCode) {
273283
setMoneyRequestTaxRate(transactionID, taxCode);
274284
const taxPercentage = getTaxValue(policy, transactionForHandlers, taxCode) ?? '';

src/components/MoneyRequestConfirmationList/sections/selectors.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ type AmountSlice = {
147147
comment: {type: NonNullable<Transaction['comment']>['type']; customUnit: NonNullable<Transaction['comment']>['customUnit']} | undefined;
148148
isAmountMissing: boolean;
149149
isAmountSet: Transaction['isAmountSet'];
150+
taxCode: Transaction['taxCode'];
150151
};
151152

152153
const amountSliceSelector = (t: OnyxEntry<Transaction>): AmountSlice | undefined => {
@@ -163,6 +164,7 @@ const amountSliceSelector = (t: OnyxEntry<Transaction>): AmountSlice | undefined
163164
comment: t.comment ? {type: t.comment.type, customUnit: t.comment.customUnit} : undefined,
164165
isAmountMissing: isAmountMissing(t),
165166
isAmountSet: t.isAmountSet,
167+
taxCode: t.taxCode,
166168
};
167169
};
168170

0 commit comments

Comments
 (0)