Repository navigation
Fix tax rates values mismatch #81888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
979d817
0a50cb5
6f01b08
36de541
6016430
14a89f8
73bc11a
0a74746
8c875ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2180,6 +2180,47 @@ function getTaxName(policy: OnyxEntry<Policy>, transaction: OnyxEntry<Transactio | |
| return taxRate?.modifiedName; | ||
| } | ||
|
|
||
| /** | ||
| * Checks if the tax rate with matching transaction's tax rate value exists in the policy tax rates | ||
| */ | ||
| function hasTaxRateWithMatchingValue(policy: OnyxEntry<Policy>, transaction: OnyxEntry<Transaction>) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-2 (docs)The function performs expensive work ( Suggested fix: function hasTaxRateWithMatchingValue(policy: OnyxEntry<Policy>, transaction: OnyxEntry<Transaction>) {
const transactionTaxCode = getTaxCode(transaction);
const transactionTaxValue = transaction?.taxValue;
// Early return: if no tax code, no point in checking rates
if (!transactionTaxCode) {
return false;
}
const taxRate = Object.values(transformedTaxRates(policy, transaction)).find((rate) => rate.code === transactionTaxCode);
if (!transactionTaxValue) {
return !!taxRate;
}
return taxRate?.value === transactionTaxValue;
}Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
koko57 marked this conversation as resolved.
Resolved
koko57 marked this conversation as resolved.
Resolved
|
||
| if (!policy || !transaction) { | ||
| return false; | ||
| } | ||
|
|
||
| const transactionTaxCode = getTaxCode(transaction); | ||
| const transformedRates = transformedTaxRates(policy, transaction); | ||
| const taxRate = Object.values(transformedRates).find((rate) => rate.code === transactionTaxCode); | ||
|
|
||
| if (!transaction?.taxValue) { | ||
| return !!taxRate; | ||
| } | ||
|
|
||
| return taxRate?.value === transaction?.taxValue; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the tax rate title for display, handling the case when moving expenses from track to submit | ||
| */ | ||
| function getTaxRateTitle(policy: OnyxEntry<Policy>, transaction: OnyxEntry<Transaction>, isMovingFromTrackExpense: boolean, policyForMovingExpenses?: OnyxEntry<Policy>): string { | ||
|
koko57 marked this conversation as resolved.
Resolved
|
||
| const currentTaxName = getTaxName(policy, transaction); | ||
|
koko57 marked this conversation as resolved.
Resolved
|
||
|
|
||
| if (currentTaxName) { | ||
| // If moving from track expense show the tax name from the moving policy | ||
| if (isMovingFromTrackExpense && !hasTaxRateWithMatchingValue(policy, transaction)) { | ||
| return getTaxName(policyForMovingExpenses, transaction) ?? ''; | ||
| } | ||
| return getTaxName(policy, transaction, true) ?? ''; | ||
| } | ||
|
|
||
| // If no tax name on current policy but moving from track expense, use the moving policy | ||
| if (isMovingFromTrackExpense) { | ||
| return getTaxName(policyForMovingExpenses, transaction, true) ?? ''; | ||
| } | ||
|
|
||
| return ''; | ||
| } | ||
|
|
||
| type FieldsToCompare = Record<string, Array<keyof Transaction>>; | ||
| type FieldsToChange = { | ||
| category?: Array<string | undefined>; | ||
|
|
@@ -2758,6 +2799,8 @@ export { | |
| transformedTaxRates, | ||
| getTaxValue, | ||
| getTaxName, | ||
| getTaxRateTitle, | ||
| hasTaxRateWithMatchingValue, | ||
| getEnabledTaxRateCount, | ||
| getUpdatedTransaction, | ||
| getClearedPendingFields, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.