-
Notifications
You must be signed in to change notification settings - Fork 3.7k
fix: no RBR when deleting distance rates #57767
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
b070148
27de0ff
4529623
e792ff9
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 |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ import {getDistanceRateCustomUnit, goBackWhenEnableFeature, removePendingFieldsF | |
| import * as ReportUtils from '@libs/ReportUtils'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type {Policy, Report} from '@src/types/onyx'; | ||
| import type {Policy, Report, Transaction, TransactionViolation} from '@src/types/onyx'; | ||
| import type {ErrorFields} from '@src/types/onyx/OnyxCommon'; | ||
| import type {Attributes, CustomUnit, Rate} from '@src/types/onyx/Policy'; | ||
| import type {OnyxData} from '@src/types/onyx/Request'; | ||
|
|
@@ -62,6 +62,29 @@ Onyx.connect({ | |
| }, | ||
| }); | ||
|
|
||
| let allTransactions: NonNullable<OnyxCollection<Transaction>> = {}; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.COLLECTION.TRANSACTION, | ||
| waitForCollectionCallback: true, | ||
| callback: (value) => { | ||
| if (!value) { | ||
| allTransactions = {}; | ||
| return; | ||
| } | ||
|
|
||
| allTransactions = value; | ||
| }, | ||
| }); | ||
|
|
||
| let transactionViolations: OnyxCollection<TransactionViolation[]>; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, | ||
| waitForCollectionCallback: true, | ||
| callback: (value) => { | ||
| transactionViolations = value; | ||
| }, | ||
| }); | ||
|
|
||
| /** | ||
| * Takes array of customUnitRates and removes pendingFields and errorFields from each rate - we don't want to send those via API | ||
| */ | ||
|
|
@@ -550,6 +573,36 @@ function deletePolicyDistanceRates(policyID: string, customUnit: CustomUnit, rat | |
| }, | ||
| ]; | ||
|
|
||
| const transactions = Object.values(allTransactions ?? {}).filter((transaction) => transaction?.comment?.customUnit?.customUnitID === customUnit.customUnitID); | ||
| const optimisticTransactionsViolations: OnyxUpdate[] = []; | ||
|
Comment on lines
+576
to
+577
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. We should check that these transaction actually belong to reports that are associated to the policy 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. We probably should check for the report state/status too. I don't think we want to add violations we can't resolve to reports have already been payed for example.
Contributor
Author
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.
We filter transactions using
Violation also appear on paid expense
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.
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.
Ahh nice, I didn't know :)
Thanks for confirming @paultsimura ! |
||
|
|
||
| transactions.forEach((transaction) => { | ||
| const currentTransactionViolations = transactionViolations?.[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction?.transactionID}`] ?? []; | ||
| if (currentTransactionViolations.some((violation) => violation.name === CONST.VIOLATIONS.CUSTOM_UNIT_OUT_OF_POLICY)) { | ||
| return; | ||
| } | ||
| optimisticTransactionsViolations.push({ | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction?.transactionID}`, | ||
| value: [ | ||
| ...currentTransactionViolations, | ||
| { | ||
| type: CONST.VIOLATION_TYPES.VIOLATION, | ||
| name: CONST.VIOLATIONS.CUSTOM_UNIT_OUT_OF_POLICY, | ||
| showInReview: true, | ||
| }, | ||
| ], | ||
| }); | ||
| }); | ||
|
|
||
| const failureTransactionsViolations: OnyxUpdate[] = transactions.map((transaction) => { | ||
| const currentTransactionViolations = transactionViolations?.[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction?.transactionID}`]; | ||
| return {onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction?.transactionID}`, value: currentTransactionViolations}; | ||
| }); | ||
|
|
||
| optimisticData.push(...optimisticTransactionsViolations); | ||
| failureData.push(...failureTransactionsViolations); | ||
|
|
||
| const params: DeletePolicyDistanceRatesParams = { | ||
| policyID, | ||
| customUnitID: customUnit.customUnitID, | ||
|
|
||



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.
This line logic is setting violations for all transactions with the specific
customUnitIDinstead of checking for thecustomUnitRateIDwhich led to this issue:which we fixed by filtering for transactions with
customUnitRateIDas the deleted one.