@@ -64,6 +64,7 @@ import {getManagerMcTestParticipant, getPersonalDetailsForAccountIDs} from '@lib
6464import Parser from '@libs/Parser' ;
6565import { getCustomUnitID } from '@libs/PerDiemRequestUtils' ;
6666import Performance from '@libs/Performance' ;
67+ import Permissions from '@libs/Permissions' ;
6768import { getAccountIDsByLogins } from '@libs/PersonalDetailsUtils' ;
6869import { addSMSDomainIfPhoneNumber } from '@libs/PhoneNumber' ;
6970import {
@@ -662,6 +663,12 @@ type GetSearchOnyxUpdateParams = {
662663 transactionThreadReportID : string | undefined ;
663664} ;
664665
666+ let allBetas : OnyxEntry < OnyxTypes . Beta [ ] > ;
667+ Onyx . connect ( {
668+ key : ONYXKEYS . BETAS ,
669+ callback : ( value ) => ( allBetas = value ) ,
670+ } ) ;
671+
665672let allTransactions : NonNullable < OnyxCollection < OnyxTypes . Transaction > > = { } ;
666673Onyx . connect ( {
667674 key : ONYXKEYS . COLLECTION . TRANSACTION ,
@@ -1394,6 +1401,7 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR
13941401
13951402 const isScanRequest = isScanRequestTransactionUtils ( transaction ) ;
13961403 const isPerDiemRequest = isPerDiemRequestTransactionUtils ( transaction ) ;
1404+ const isASAPSubmitBetaEnabled = Permissions . isBetaEnabled ( CONST . BETAS . ASAP_SUBMIT , allBetas ) ;
13971405 const outstandingChildRequest = getOutstandingChildRequest ( iou . report ) ;
13981406 const clearedPendingFields = Object . fromEntries ( Object . keys ( transaction . pendingFields ?? { } ) . map ( ( key ) => [ key , null ] ) ) ;
13991407 const isMoneyRequestToManagerMcTest = isTestTransactionReport ( iou . report ) ;
@@ -1424,7 +1432,8 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR
14241432 ...chat . report ,
14251433 lastReadTime : DateUtils . getDBTime ( ) ,
14261434 ...( shouldCreateNewMoneyRequestReport ? { lastVisibleActionCreated : chat . reportPreviewAction . created } : { } ) ,
1427- iouReportID : iou . report . reportID ,
1435+ // do not update iouReportID if auto submit beta is enabled and it is a scan request
1436+ ...( isASAPSubmitBetaEnabled && isScanRequest ? { } : { iouReportID : iou . report . reportID } ) ,
14281437 ...outstandingChildRequest ,
14291438 ...( isNewChatReport ? { pendingFields : { createChat : CONST . RED_BRICK_ROAD_PENDING_ACTION . ADD } } : { } ) ,
14301439 } ,
@@ -2411,6 +2420,7 @@ function buildOnyxDataForTrackExpense({
24112420 const { policy, tagList : policyTagList , categories : policyCategories } = policyParams ;
24122421
24132422 const isScanRequest = isScanRequestTransactionUtils ( transaction ) ;
2423+ const isASAPSubmitBetaEnabled = Permissions . isBetaEnabled ( CONST . BETAS . ASAP_SUBMIT , allBetas ) ;
24142424 const isDistanceRequest = isDistanceRequestTransactionUtils ( transaction ) ;
24152425 const clearedPendingFields = Object . fromEntries ( Object . keys ( transaction . pendingFields ?? { } ) . map ( ( key ) => [ key , null ] ) ) ;
24162426
@@ -2437,7 +2447,8 @@ function buildOnyxDataForTrackExpense({
24372447 lastMessageText : getReportActionText ( iouAction ) ,
24382448 lastMessageHtml : getReportActionHtml ( iouAction ) ,
24392449 lastReadTime : DateUtils . getDBTime ( ) ,
2440- iouReportID : iouReport ?. reportID ,
2450+ // do not update iouReportID if auto submit beta is enabled and it is a scan request
2451+ iouReportID : isASAPSubmitBetaEnabled && isScanRequest ? null : iouReport ?. reportID ,
24412452 lastVisibleActionCreated : shouldCreateNewMoneyRequestReport ? reportPreviewAction ?. created : chatReport . lastVisibleActionCreated ,
24422453 } ,
24432454 } ,
@@ -3317,7 +3328,8 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma
33173328 iouReport = allReports ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ chatReport . iouReportID } ` ] ?? null ;
33183329 }
33193330
3320- const shouldCreateNewMoneyRequestReport = shouldCreateNewMoneyRequestReportReportUtils ( iouReport , chatReport ) ;
3331+ const isScanRequest = isScanRequestTransactionUtils ( { amount, receipt} ) ;
3332+ const shouldCreateNewMoneyRequestReport = shouldCreateNewMoneyRequestReportReportUtils ( iouReport , chatReport , isScanRequest ) ;
33213333
33223334 if ( ! iouReport || shouldCreateNewMoneyRequestReport ) {
33233335 iouReport = isPolicyExpenseChat
@@ -3576,7 +3588,7 @@ function getPerDiemExpenseInformation(perDiemExpenseInformation: PerDiemExpenseI
35763588 iouReport = allReports ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ chatReport . iouReportID } ` ] ?? null ;
35773589 }
35783590
3579- const shouldCreateNewMoneyRequestReport = shouldCreateNewMoneyRequestReportReportUtils ( iouReport , chatReport ) ;
3591+ const shouldCreateNewMoneyRequestReport = shouldCreateNewMoneyRequestReportReportUtils ( iouReport , chatReport , false ) ;
35803592
35813593 if ( ! iouReport || shouldCreateNewMoneyRequestReport ) {
35823594 iouReport = isPolicyExpenseChat
@@ -3787,8 +3799,8 @@ function getTrackExpenseInformation(params: GetTrackExpenseInformationParams): T
37873799 } else {
37883800 iouReport = allReports ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ chatReport . iouReportID } ` ] ?? null ;
37893801 }
3790-
3791- shouldCreateNewMoneyRequestReport = shouldCreateNewMoneyRequestReportReportUtils ( iouReport , chatReport ) ;
3802+ const isScanRequest = isScanRequestTransactionUtils ( { amount , receipt } ) ;
3803+ shouldCreateNewMoneyRequestReport = shouldCreateNewMoneyRequestReportReportUtils ( iouReport , chatReport , isScanRequest ) ;
37923804 if ( ! iouReport || shouldCreateNewMoneyRequestReport ) {
37933805 iouReport = buildOptimisticExpenseReport ( chatReport . reportID , chatReport . policyID , payeeAccountID , amount , currency , amount ) ;
37943806 } else {
@@ -6189,7 +6201,8 @@ function createSplitsAndOnyxData({
61896201
61906202 // STEP 2: Get existing IOU/Expense report and update its total OR build a new optimistic one
61916203 let oneOnOneIOUReport : OneOnOneIOUReport = oneOnOneChatReport . iouReportID ? allReports ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ oneOnOneChatReport . iouReportID } ` ] : null ;
6192- const shouldCreateNewOneOnOneIOUReport = shouldCreateNewMoneyRequestReportReportUtils ( oneOnOneIOUReport , oneOnOneChatReport ) ;
6204+ const isScanRequest = isScanRequestTransactionUtils ( splitTransaction ) ;
6205+ const shouldCreateNewOneOnOneIOUReport = shouldCreateNewMoneyRequestReportReportUtils ( oneOnOneIOUReport , oneOnOneChatReport , isScanRequest ) ;
61936206
61946207 if ( ! oneOnOneIOUReport || shouldCreateNewOneOnOneIOUReport ) {
61956208 oneOnOneIOUReport = isOwnPolicyExpenseChat
@@ -7010,7 +7023,7 @@ function completeSplitBill(
70107023 }
70117024
70127025 let oneOnOneIOUReport : OneOnOneIOUReport = oneOnOneChatReport ?. iouReportID ? allReports ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ oneOnOneChatReport . iouReportID } ` ] : null ;
7013- const shouldCreateNewOneOnOneIOUReport = shouldCreateNewMoneyRequestReportReportUtils ( oneOnOneIOUReport , oneOnOneChatReport ) ;
7026+ const shouldCreateNewOneOnOneIOUReport = shouldCreateNewMoneyRequestReportReportUtils ( oneOnOneIOUReport , oneOnOneChatReport , false ) ;
70147027
70157028 if ( ! oneOnOneIOUReport || shouldCreateNewOneOnOneIOUReport ) {
70167029 oneOnOneIOUReport = isPolicyExpenseChat
0 commit comments