Skip to content

Commit

Permalink
Pass taxCode when currency changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MonilBhavsar committed May 14, 2024
1 parent 229027a commit 1e57b99
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5092,6 +5092,7 @@ type UpdateMoneyRequestAmountAndCurrencyParams = {
policy?: OnyxEntry<OnyxTypes.Policy>;
policyTagList?: OnyxEntry<OnyxTypes.PolicyTagList>;
policyCategories?: OnyxEntry<OnyxTypes.PolicyCategories>;
taxCode: string;
};

/** Updates the amount and currency fields of an expense */
Expand All @@ -5104,11 +5105,13 @@ function updateMoneyRequestAmountAndCurrency({
policy,
policyTagList,
policyCategories,
taxCode,
}: UpdateMoneyRequestAmountAndCurrencyParams) {
const transactionChanges = {
amount,
currency,
...(taxAmount && {taxAmount}),
taxCode,
};
const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`] ?? null;
const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`] ?? null;
Expand Down
9 changes: 5 additions & 4 deletions src/pages/iou/request/step/IOURequestStepAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ type IOURequestStepAmountProps = IOURequestStepAmountOnyxProps &
transaction: OnyxEntry<OnyxTypes.Transaction>;
};

function getTaxAmount(transaction: OnyxEntry<OnyxTypes.Transaction>, policy: OnyxEntry<OnyxTypes.Policy>, newAmount: number) {
function getTaxAmount(transaction: OnyxEntry<OnyxTypes.Transaction>, policy: OnyxEntry<OnyxTypes.Policy>, newAmount: number, currency: string) {
if (!transaction?.amount) {
return;
}
const transactionTaxCode = transaction?.taxCode ?? '';
const defaultTaxCode = TransactionUtils.getDefaultTaxCode(policy, transaction) ?? '';
const defaultTaxCode = TransactionUtils.getDefaultTaxCode(policy, transaction, currency) ?? '';
const taxPercentage = TransactionUtils.getTaxValue(policy, transaction, transactionTaxCode ?? defaultTaxCode) ?? '';
return CurrencyUtils.convertToBackendAmount(TransactionUtils.calculateTaxAmount(taxPercentage, newAmount));
}
Expand Down Expand Up @@ -290,9 +290,10 @@ function IOURequestStepAmount({
return;
}

const taxAmount = getTaxAmount(transaction, policy, newAmount);
const taxAmount = getTaxAmount(transaction, policy, newAmount, currency);
const taxCode = TransactionUtils.getDefaultTaxCode(policy, transaction, currency) ?? '';

IOU.updateMoneyRequestAmountAndCurrency({transactionID, transactionThreadReportID: reportID, currency, amount: newAmount, taxAmount});
IOU.updateMoneyRequestAmountAndCurrency({transactionID, transactionThreadReportID: reportID, currency, amount: newAmount, taxAmount, taxCode});
Navigation.dismissModal();
};

Expand Down

0 comments on commit 1e57b99

Please sign in to comment.