From bc07a7f450423fa3c41d6f8fc481799e7cadd1d2 Mon Sep 17 00:00:00 2001 From: Joel Bettner Date: Tue, 2 Jan 2024 15:43:11 -0700 Subject: [PATCH] Merge pull request #33850 from paultsimura/fix/33786-smartscan-error fix: Make merchant required only on Expense reports (cherry picked from commit b53a425f44dc4754f3352ba3c57ac832ea21985f) --- src/libs/TransactionUtils.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/libs/TransactionUtils.ts b/src/libs/TransactionUtils.ts index 75815a2448e4..e02fb8e4b8f1 100644 --- a/src/libs/TransactionUtils.ts +++ b/src/libs/TransactionUtils.ts @@ -3,7 +3,7 @@ import Onyx, {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import {ValueOf} from 'type-fest'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import {RecentWaypoint, ReportAction, Transaction} from '@src/types/onyx'; +import {RecentWaypoint, Report, ReportAction, Transaction} from '@src/types/onyx'; import {Comment, Receipt, Waypoint, WaypointCollection} from '@src/types/onyx/Transaction'; import {EmptyObject} from '@src/types/utils/EmptyObject'; import {isCorporateCard, isExpensifyCard} from './CardUtils'; @@ -27,6 +27,13 @@ Onyx.connect({ }, }); +let allReports: OnyxCollection; +Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (value) => (allReports = value), +}); + function isDistanceRequest(transaction: Transaction): boolean { // This is used during the request creation flow before the transaction has been saved to the server if (lodashHas(transaction, 'iouRequestType')) { @@ -146,7 +153,9 @@ function isCreatedMissing(transaction: Transaction) { } function areRequiredFieldsEmpty(transaction: Transaction): boolean { - return isMerchantMissing(transaction) || isAmountMissing(transaction) || isCreatedMissing(transaction); + const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transaction?.reportID}`] ?? null; + const isFromExpenseReport = parentReport?.type === CONST.REPORT.TYPE.EXPENSE; + return (isFromExpenseReport && isMerchantMissing(transaction)) || isAmountMissing(transaction) || isCreatedMissing(transaction); } /**