Skip to content

Commit 71ee505

Browse files
authored
Merge pull request #55801 from Tony-MK/fix/55138
fix: Removing the transaction's ID from other duplicate violation data when deleting one of the duplicate expenses.
2 parents a06540c + 3c6f219 commit 71ee505

File tree

1 file changed

+51
-8
lines changed

1 file changed

+51
-8
lines changed

src/libs/actions/IOU.ts

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ import {
159159
isPerDiemRequest as isPerDiemRequestTransactionUtils,
160160
isReceiptBeingScanned as isReceiptBeingScannedTransactionUtils,
161161
isScanRequest as isScanRequestTransactionUtils,
162+
removeSettledAndApprovedTransactions,
162163
shouldShowBrokenConnectionViolation,
163164
} from '@libs/TransactionUtils';
164165
import ViolationsUtils from '@libs/Violations/ViolationsUtils';
@@ -6764,6 +6765,56 @@ function deleteMoneyRequest(transactionID: string | undefined, reportAction: Ony
67646765
value: null,
67656766
});
67666767

6768+
const failureData: OnyxUpdate[] = [
6769+
{
6770+
onyxMethod: Onyx.METHOD.SET,
6771+
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
6772+
value: transaction ?? null,
6773+
},
6774+
];
6775+
6776+
if (transactionViolations) {
6777+
removeSettledAndApprovedTransactions(
6778+
transactionViolations.filter((violation) => violation?.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION).flatMap((violation) => violation?.data?.duplicates ?? []),
6779+
).forEach((duplicateID) => {
6780+
const duplicateTransactionsViolations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${duplicateID}`];
6781+
if (!duplicateTransactionsViolations) {
6782+
return;
6783+
}
6784+
6785+
const duplicateViolation = duplicateTransactionsViolations.find((violation) => violation.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION);
6786+
if (!duplicateViolation?.data?.duplicates) {
6787+
return;
6788+
}
6789+
6790+
const duplicateTransactionIDs = duplicateViolation.data.duplicates.filter((duplicateTransactionID) => duplicateTransactionID !== transactionID);
6791+
6792+
const optimisticViolations: OnyxTypes.TransactionViolations = duplicateTransactionsViolations.filter((violation) => violation.name !== CONST.VIOLATIONS.DUPLICATED_TRANSACTION);
6793+
6794+
if (duplicateTransactionIDs.length > 0) {
6795+
optimisticViolations.push({
6796+
...duplicateViolation,
6797+
data: {
6798+
...duplicateViolation.data,
6799+
duplicates: duplicateTransactionIDs,
6800+
},
6801+
});
6802+
}
6803+
6804+
optimisticData.push({
6805+
onyxMethod: Onyx.METHOD.SET,
6806+
key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${duplicateID}`,
6807+
value: optimisticViolations.length > 0 ? optimisticViolations : null,
6808+
});
6809+
6810+
failureData.push({
6811+
onyxMethod: Onyx.METHOD.SET,
6812+
key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${duplicateID}`,
6813+
value: duplicateTransactionsViolations,
6814+
});
6815+
});
6816+
}
6817+
67676818
if (shouldDeleteTransactionThread) {
67686819
optimisticData.push(
67696820
// Use merge instead of set to avoid deleting the report too quickly, which could cause a brief "not found" page to appear.
@@ -6909,14 +6960,6 @@ function deleteMoneyRequest(transactionID: string | undefined, reportAction: Ony
69096960
});
69106961
}
69116962

6912-
const failureData: OnyxUpdate[] = [
6913-
{
6914-
onyxMethod: Onyx.METHOD.SET,
6915-
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
6916-
value: transaction ?? null,
6917-
},
6918-
];
6919-
69206963
failureData.push({
69216964
onyxMethod: Onyx.METHOD.SET,
69226965
key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`,

0 commit comments

Comments
 (0)