-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fix: [Dupe detection] Tax code review step shows empty option when workspace does not have tax rate #48958
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
Merged
Merged
fix: [Dupe detection] Tax code review step shows empty option when workspace does not have tax rate #48958
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
913a3d9
demo skip dupe tax step.
Krishna2323 19ae510
Merge branch 'Expensify:main' into krishna2323/issue/47796
Krishna2323 0429b7f
minor update.
Krishna2323 009faf4
Merge branch 'Expensify:main' into krishna2323/issue/47796
Krishna2323 9050810
revert changes in ReviewTaxRate page.
Krishna2323 4f6b4db
Merge branch 'Expensify:main' into krishna2323/issue/47796
Krishna2323 b2b979b
revert changes.
Krishna2323 61ce002
remove tax code from changes if policy doesn't include that.
Krishna2323 5fff73f
minor update.
Krishna2323 9801ae8
only add taxCode in changes if availble in policy.
Krishna2323 033b430
Merge branch 'Expensify:main' into krishna2323/issue/47796
Krishna2323 ca12200
Merge branch 'Expensify:main' into krishna2323/issue/47796
Krishna2323 1dae0d4
Merge branch 'main' into krishna2323/issue/47796
Krishna2323 f9d60f6
Merge branch 'Expensify:main' into krishna2323/issue/47796
Krishna2323 b2b14cd
feat: skip category review when category isn't present in policy.
Krishna2323 57bd400
minor fix.
Krishna2323 2124c24
minor update.
Krishna2323 5d7dee2
Merge branch 'Expensify:main' into krishna2323/issue/47796
Krishna2323 6cc3905
minor fix.
Krishna2323 d8cecc9
fix category dupe step skip.
Krishna2323 b98426c
Merge branch 'Expensify:main' into krishna2323/issue/47796
Krishna2323 6d07d46
feat: skip tags review if no valid tags are available.
Krishna2323 aa64f7e
minor fix.
Krishna2323 593c31f
Merge branch 'Expensify:main' into krishna2323/issue/47796
Krishna2323 45d852f
clear review duplicates data when starting a new flow.
Krishna2323 1d3dee8
category/tag review shows when feature is disabled.
Krishna2323 83c2a2b
Merge branch 'Expensify:main' into krishna2323/issue/47796
Krishna2323 0bc8694
minor update.
Krishna2323 b6ed014
Merge branch 'Expensify:main' into krishna2323/issue/47796
Krishna2323 0516d60
Merge branch 'Expensify:main' into krishna2323/issue/47796
Krishna2323 16008d8
fix: category, tag review step not shown.
Krishna2323 9a3e1db
Merge branch 'Expensify:main' into krishna2323/issue/47796
Krishna2323 5c6f079
added comment/
Krishna2323 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
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 |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ import lodashSet from 'lodash/set'; | |
| import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; | ||
| import Onyx from 'react-native-onyx'; | ||
| import type {ValueOf} from 'type-fest'; | ||
| import {getPolicyCategoriesData} from '@libs/actions/Policy/Category'; | ||
| import {getPolicyTagsData} from '@libs/actions/Policy/Tag'; | ||
| import type {TransactionMergeParams} from '@libs/API/parameters'; | ||
| import {getCurrencyDecimals} from '@libs/CurrencyUtils'; | ||
| import DateUtils from '@libs/DateUtils'; | ||
|
|
@@ -1034,7 +1036,7 @@ function removeSettledAndApprovedTransactions(transactionIDs: string[]) { | |
| * 6. It returns the 'keep' and 'change' objects. | ||
| */ | ||
|
|
||
| function compareDuplicateTransactionFields(transactionID: string): {keep: Partial<ReviewDuplicates>; change: FieldsToChange} { | ||
| function compareDuplicateTransactionFields(transactionID: string, reportID: string): {keep: Partial<ReviewDuplicates>; change: FieldsToChange} { | ||
| const transactionViolations = allTransactionViolations?.[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`]; | ||
| const duplicates = transactionViolations?.find((violation) => violation.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION)?.data?.duplicates ?? []; | ||
| const transactions = removeSettledAndApprovedTransactions([transactionID, ...duplicates]).map((item) => getTransaction(item)); | ||
|
|
@@ -1095,7 +1097,10 @@ function compareDuplicateTransactionFields(transactionID: string): {keep: Partia | |
| const keys = fieldsToCompare[fieldName]; | ||
| const firstTransaction = transactions.at(0); | ||
| const isFirstTransactionCommentEmptyObject = typeof firstTransaction?.comment === 'object' && firstTransaction?.comment?.comment === ''; | ||
| const report = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] ?? null; | ||
| const policy = PolicyUtils.getPolicy(report?.policyID); | ||
|
|
||
| const areAllFieldsEqualForKey = areAllFieldsEqual(transactions, (item) => keys.map((key) => item?.[key]).join('|')); | ||
| if (fieldName === 'description') { | ||
| const allCommentsAreEqual = areAllCommentsEqual(transactions, firstTransaction); | ||
| const allCommentsAreEmpty = isFirstTransactionCommentEmptyObject && transactions.every((item) => getDescription(item) === ''); | ||
|
|
@@ -1110,7 +1115,52 @@ function compareDuplicateTransactionFields(transactionID: string): {keep: Partia | |
| } else { | ||
| processChanges(fieldName, transactions, keys); | ||
| } | ||
| } else if (areAllFieldsEqual(transactions, (item) => keys.map((key) => item?.[key]).join('|'))) { | ||
| } else if (fieldName === 'taxCode') { | ||
|
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. When both duplicate tax or category or tag are not valid anymore, when resolving the dupe, the tax/category/tag becomes empty. #82925 |
||
| const differentValues = getDifferentValues(transactions, keys); | ||
| const validTaxes = differentValues?.filter((taxID) => { | ||
| const tax = PolicyUtils.getTaxByID(policy, (taxID as string) ?? ''); | ||
| return tax?.name && !tax.isDisabled && tax.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; | ||
| }); | ||
|
|
||
| if (!areAllFieldsEqualForKey && validTaxes.length > 1) { | ||
| change[fieldName] = validTaxes; | ||
| } else if (areAllFieldsEqualForKey) { | ||
| keep[fieldName] = firstTransaction?.[keys[0]] ?? firstTransaction?.[keys[1]]; | ||
| } | ||
| } else if (fieldName === 'category') { | ||
| const differentValues = getDifferentValues(transactions, keys); | ||
| const policyCategories = getPolicyCategoriesData(report?.policyID ?? '-1'); | ||
| const availableCategories = Object.values(policyCategories) | ||
| .filter((category) => differentValues.includes(category.name) && category.enabled && category.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) | ||
| .map((e) => e.name); | ||
|
|
||
| if (!areAllFieldsEqualForKey && policy?.areCategoriesEnabled && (availableCategories.length > 1 || (availableCategories.length === 1 && differentValues.includes('')))) { | ||
| change[fieldName] = [...availableCategories, ...(differentValues.includes('') ? [''] : [])]; | ||
| } else if (areAllFieldsEqualForKey) { | ||
| keep[fieldName] = firstTransaction?.[keys[0]] ?? firstTransaction?.[keys[1]]; | ||
| } | ||
| } else if (fieldName === 'tag') { | ||
| const policyTags = getPolicyTagsData(report?.policyID ?? '-1'); | ||
| const isMultiLevelTags = PolicyUtils.isMultiLevelTags(policyTags); | ||
| if (isMultiLevelTags) { | ||
| if (areAllFieldsEqualForKey || !policy?.areTagsEnabled) { | ||
| keep[fieldName] = firstTransaction?.[keys[0]] ?? firstTransaction?.[keys[1]]; | ||
| } else { | ||
| processChanges(fieldName, transactions, keys); | ||
| } | ||
| } else { | ||
| const differentValues = getDifferentValues(transactions, keys); | ||
| const policyTagsObj = Object.values(Object.values(policyTags).at(0)?.tags ?? {}); | ||
| const availableTags = policyTagsObj | ||
| .filter((tag) => differentValues.includes(tag.name) && tag.enabled && tag.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) | ||
| .map((e) => e.name); | ||
| if (!areAllFieldsEqualForKey && policy?.areTagsEnabled && (availableTags.length > 1 || (availableTags.length === 1 && differentValues.includes('')))) { | ||
| change[fieldName] = [...availableTags, ...(differentValues.includes('') ? [''] : [])]; | ||
| } else if (areAllFieldsEqualForKey) { | ||
| keep[fieldName] = firstTransaction?.[keys[0]] ?? firstTransaction?.[keys[1]]; | ||
| } | ||
| } | ||
| } else if (areAllFieldsEqualForKey) { | ||
| keep[fieldName] = firstTransaction?.[keys[0]] ?? firstTransaction?.[keys[1]]; | ||
| } else { | ||
| processChanges(fieldName, transactions, keys); | ||
|
|
||
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.
I approved, but now that I think about it, can you add a comment before this line explaining why we need to call
Transaction.abandonReviewDuplicateTransactions();?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.
comment added.