Skip to content

Commit ca308ca

Browse files
committed
fix: incorrect violation when moving smart scan failed expense
1 parent 1661839 commit ca308ca

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/libs/Violations/ViolationsUtils.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,10 @@ const ViolationsUtils = {
226226
hasDependentTags: boolean,
227227
isInvoiceTransaction: boolean,
228228
): OnyxUpdate {
229-
if (TransactionUtils.isPartial(updatedTransaction)) {
229+
const isScanning = TransactionUtils.isScanning(updatedTransaction);
230+
const isScanRequest = TransactionUtils.isScanRequest(updatedTransaction);
231+
const isPartialTransaction = TransactionUtils.isPartial(updatedTransaction);
232+
if (isPartialTransaction && isScanning) {
230233
return {
231234
onyxMethod: Onyx.METHOD.SET,
232235
key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${updatedTransaction.transactionID}`,
@@ -236,6 +239,15 @@ const ViolationsUtils = {
236239

237240
let newTransactionViolations = [...transactionViolations];
238241

242+
const shouldShowSmartScanFailedError = !isScanning && isScanRequest && isPartialTransaction;
243+
const hasSmartScanFailedError = transactionViolations.some((violation) => violation.name === CONST.VIOLATIONS.SMARTSCAN_FAILED);
244+
if (shouldShowSmartScanFailedError && !hasSmartScanFailedError) {
245+
newTransactionViolations.push({name: CONST.VIOLATIONS.SMARTSCAN_FAILED, type: CONST.VIOLATION_TYPES.WARNING, showInReview: true});
246+
}
247+
if (!shouldShowSmartScanFailedError && hasSmartScanFailedError) {
248+
newTransactionViolations = reject(newTransactionViolations, {name: CONST.VIOLATIONS.SMARTSCAN_FAILED});
249+
}
250+
239251
// Calculate client-side category violations
240252
const policyRequiresCategories = !!policy.requiresCategory;
241253
if (policyRequiresCategories) {
@@ -260,7 +272,7 @@ const ViolationsUtils = {
260272
}
261273

262274
// Add 'missingCategory' violation if category is required and not set
263-
if (!hasMissingCategoryViolation && policyRequiresCategories && !categoryKey) {
275+
if (!hasMissingCategoryViolation && policyRequiresCategories && !categoryKey && !shouldShowSmartScanFailedError) {
264276
newTransactionViolations.push({name: 'missingCategory', type: CONST.VIOLATION_TYPES.VIOLATION, showInReview: true});
265277
}
266278
}

0 commit comments

Comments
 (0)