-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Revert "Fix tax updating for changing waypoints or currency" #73352
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -332,19 +332,27 @@ function MoneyRequestConfirmationList({ | |
|
|
||
| const shouldShowTax = isTaxTrackingEnabled(isPolicyExpenseChat, policy, isDistanceRequest, isPerDiemRequest); | ||
|
|
||
| const previousTransactionAmount = usePrevious(transaction?.amount); | ||
| const previousTransactionCurrency = usePrevious(transaction?.currency); | ||
| const previousTransactionModifiedCurrency = usePrevious(transaction?.modifiedCurrency); | ||
| const previousCustomUnitRateID = usePrevious(customUnitRateID); | ||
| useEffect(() => { | ||
| // Set the default tax code when conditions change | ||
| if (!shouldShowTax || !transaction || !transactionID) { | ||
| // previousTransaction is in the condition because if it is falsy, it means this is the first time the useEffect is triggered after we load it, so we should calculate the default | ||
| // tax even if the other parameters are the same against their previous values. | ||
| if ( | ||
| !shouldShowTax || | ||
| !transaction || | ||
| !transactionID || | ||
| (transaction.taxCode && | ||
| previousTransactionModifiedCurrency === transaction.modifiedCurrency && | ||
| previousTransactionCurrency === transaction.currency && | ||
| previousCustomUnitRateID === customUnitRateID) | ||
| ) { | ||
| return; | ||
| } | ||
| const defaultTaxCode = getDefaultTaxCode(policy, transaction); | ||
| const currentTaxCode = transaction.taxCode ?? ''; | ||
|
|
||
| // Update tax code if it's different from what should be the default | ||
| if (defaultTaxCode !== currentTaxCode) { | ||
| setMoneyRequestTaxRate(transactionID, defaultTaxCode ?? ''); | ||
| } | ||
| }, [customUnitRateID, policy, shouldShowTax, transaction, transactionID]); | ||
| setMoneyRequestTaxRate(transactionID, defaultTaxCode ?? ''); | ||
| }, [customUnitRateID, policy, previousCustomUnitRateID, previousTransactionCurrency, previousTransactionModifiedCurrency, shouldShowTax, transaction, transactionID]); | ||
|
|
||
| const isMovingTransactionFromTrackExpense = isMovingTransactionFromTrackExpenseUtil(action); | ||
|
|
||
|
|
@@ -479,9 +487,19 @@ function MoneyRequestConfirmationList({ | |
| } | ||
| }, [shouldCalculateDistanceAmount, isReadOnly, distanceRequestAmount, transactionID, currency, isTypeSplit, isPolicyExpenseChat, selectedParticipantsProp, transaction]); | ||
|
|
||
| const previousTaxCode = usePrevious(transaction?.taxCode); | ||
|
|
||
| // Calculate and set tax amount in transaction draft | ||
| useEffect(() => { | ||
| if (!shouldShowTax || !transaction) { | ||
| if ( | ||
| !shouldShowTax || | ||
| !transaction || | ||
| (transaction.taxAmount !== undefined && | ||
| previousTransactionAmount === transaction.amount && | ||
| previousTransactionCurrency === transaction.currency && | ||
| previousCustomUnitRateID === customUnitRateID && | ||
| previousTaxCode === transaction.taxCode) | ||
| ) { | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -502,13 +520,20 @@ function MoneyRequestConfirmationList({ | |
| const taxPercentage = getTaxValue(policy, transaction, taxCode) ?? ''; | ||
| const taxAmount = calculateTaxAmount(taxPercentage, taxableAmount, transaction.currency); | ||
| const taxAmountInSmallestCurrencyUnits = convertToBackendAmount(Number.parseFloat(taxAmount.toString())); | ||
|
|
||
| // Only update if the calculated tax amount is different from the current one | ||
| if (transaction.taxAmount !== taxAmountInSmallestCurrencyUnits) { | ||
| setMoneyRequestTaxAmount(transaction.transactionID, taxAmountInSmallestCurrencyUnits); | ||
| } | ||
| setMoneyRequestTaxAmount(transaction.transactionID, taxAmountInSmallestCurrencyUnits); | ||
| } | ||
| }, [policy, shouldShowTax, transaction, isDistanceRequest, customUnitRateID, distance]); | ||
| }, [ | ||
| policy, | ||
| shouldShowTax, | ||
| previousTransactionAmount, | ||
| previousTransactionCurrency, | ||
| transaction, | ||
| isDistanceRequest, | ||
| customUnitRateID, | ||
| previousCustomUnitRateID, | ||
| previousTaxCode, | ||
| distance, | ||
| ]); | ||
|
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-6 (docs)In Replace the }, [
policy,
shouldShowTax,
previousTransactionAmount,
previousTransactionCurrency,
transaction?.amount,
transaction?.currency,
transaction?.taxCode,
transaction?.taxAmount,
transaction?.transactionID,
isDistanceRequest,
customUnitRateID,
previousCustomUnitRateID,
previousTaxCode,
distance,
]); |
||
|
|
||
| // If completing a split expense fails, set didConfirm to false to allow the user to edit the fields again | ||
| if (isEditingSplitBill && didConfirm) { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ PERF-6 (docs)
In
useEffect,useMemo, anduseCallback, specify individual object properties as dependencies instead of passing entire objects.Replace the
transactiondependency with its specific properties that are actually used: