Skip to content

Commit

Permalink
Merge pull request #33850 from paultsimura/fix/33786-smartscan-error
Browse files Browse the repository at this point in the history
fix: Make merchant required only on Expense reports
(cherry picked from commit b53a425)
  • Loading branch information
Joel Bettner authored and OSBotify committed Jan 2, 2024
1 parent f29bfe9 commit bc07a7f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/libs/TransactionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -27,6 +27,13 @@ Onyx.connect({
},
});

let allReports: OnyxCollection<Report>;
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')) {
Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit bc07a7f

Please sign in to comment.