-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Fix duplicate tax handling to preserve original tax data when unchanged #88125
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
base: main
Are you sure you want to change the base?
Changes from all commits
b716146
c2e683f
fed3eb7
47d2c27
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 |
|---|---|---|
|
|
@@ -57,6 +57,7 @@ function Confirmation() { | |
| const [reviewDuplicatesReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reviewDuplicates?.reportID}`); | ||
| const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${getNonEmptyStringOnyxID(reviewDuplicatesReport?.policyID)}`); | ||
| const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`); | ||
| const [duplicatedTransactionPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${getNonEmptyStringOnyxID(reviewDuplicatesReport?.policyID)}`); | ||
| const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${getNonEmptyStringOnyxID(reviewDuplicatesReport?.policyID)}`); | ||
| const compareResult = TransactionUtils.compareDuplicateTransactionFields(policyTags ?? {}, transaction, allDuplicates, reviewDuplicatesReport, undefined, policy, policyCategories); | ||
| const {goBack} = useReviewDuplicatesNavigation(Object.keys(compareResult.change ?? {}), 'confirmation', route.params.threadReportID, route.params.backTo); | ||
|
|
@@ -75,12 +76,18 @@ function Confirmation() { | |
| ); | ||
| const taxData = useMemo(() => { | ||
| const taxCode = reviewDuplicates?.taxCode ?? ''; | ||
| const taxRate = taxCode ? policy?.taxRates?.taxes?.[taxCode] : undefined; | ||
| const taxRate = taxCode ? duplicatedTransactionPolicy?.taxRates?.taxes?.[taxCode] : undefined; | ||
| // Preserve taxAmount and taxValue if taxCode is deleted or remains unchanged compared to duplicatedTransaction?.taxCode. | ||
| if (!taxRate || (taxCode && duplicatedTransaction?.taxCode === taxCode) || reviewDuplicates?.taxAmount === undefined) { | ||
| return; | ||
|
Comment on lines
+80
to
+82
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.
The new guard in Useful? React with 👍 / 👎.
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. I believe this is acceptable because the policy is fully retrieved from the server when the report is opened. Additionally, on the confirmation page, the user must click "Confirm" to apply changes, and the policy will have been loaded beforehand. |
||
| } | ||
|
|
||
| return { | ||
| taxAmount: -(reviewDuplicates?.taxAmount ?? 0), | ||
| taxValue: taxRate?.value ?? '', | ||
| taxAmount: -reviewDuplicates.taxAmount, | ||
| taxValue: taxRate?.value, | ||
| taxCode, | ||
| }; | ||
| }, [reviewDuplicates?.taxCode, reviewDuplicates?.taxAmount, policy?.taxRates?.taxes]); | ||
| }, [reviewDuplicates?.taxCode, reviewDuplicates?.taxAmount, duplicatedTransactionPolicy?.taxRates?.taxes, duplicatedTransaction?.taxCode]); | ||
| const isReportOwner = iouReport?.ownerAccountID === currentUserPersonalDetails?.accountID; | ||
|
|
||
| const handleMergeDuplicates = useCallback(() => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ function ReviewTaxRate() { | |
| const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${route.params.threadReportID}`); | ||
| const transactionID = getTransactionID(transactionThreadReport); | ||
| const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(transactionID)}`); | ||
| const [duplicatedTransaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(reviewDuplicates?.transactionID)}`); | ||
| const [transactionViolations] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`); | ||
| const allDuplicateIDs = useMemo( | ||
| () => transactionViolations?.find((violation) => violation.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION)?.data?.duplicates ?? [], | ||
|
|
@@ -64,11 +65,15 @@ function ReviewTaxRate() { | |
| ); | ||
| const getTaxAmount = useCallback( | ||
| (taxID: string) => { | ||
| // If the tax code remains unchanged, preserve the tax amount to avoid resetting it to the default value when resolving duplicates. | ||
| if (taxID === duplicatedTransaction?.taxCode) { | ||
| return; | ||
|
Comment on lines
+69
to
+70
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.
Returning Useful? React with 👍 / 👎. |
||
| } | ||
| const taxPercentage = getTaxValue(policy, transaction, taxID); | ||
| const decimals = getCurrencyDecimals(transaction?.currency); | ||
| return convertToBackendAmount(calculateTaxAmount(taxPercentage ?? '', getAmount(transaction), decimals)); | ||
| }, | ||
| [policy, transaction, getCurrencyDecimals], | ||
| [policy, transaction, getCurrencyDecimals, duplicatedTransaction?.taxCode], | ||
| ); | ||
|
|
||
| const setTaxCode = useCallback( | ||
|
|
||
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.
In
Confirmation, the new early return on!taxRatecan incorrectly drop user tax changes for cross-report duplicate flows:taxCode/taxAmountcome from the kept duplicate (reviewDuplicates), buttaxRateis looked up frompolicytied toroute.params.threadReportID(current thread report), which may be a different report/policy. When that lookup misses,taxDatabecomesundefined; combined withbuildMergeDuplicatesParams()no longer sendingtaxCode, merge/resolve fall back to the original transaction tax fields and silently ignore the selected tax choice.Useful? React with 👍 / 👎.
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.
@MelvinBot apply this patch:
patch
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.
@MelvinBot bump ^
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.
The Codex concern here has already been addressed by the latest commit. The taxRate lookup now uses duplicatedTransactionPolicy (keyed off reviewDuplicatesReport?.policyID) instead of policy (keyed off report?.policyID), so cross-report duplicate flows will resolve tax codes against the correct policy.