@@ -23,6 +23,7 @@ import * as CardUtils from '@libs/CardUtils';
23
23
import * as CurrencyUtils from '@libs/CurrencyUtils' ;
24
24
import type { MileageRate } from '@libs/DistanceRequestUtils' ;
25
25
import DistanceRequestUtils from '@libs/DistanceRequestUtils' ;
26
+ import * as ErrorUtils from '@libs/ErrorUtils' ;
26
27
import * as OptionsListUtils from '@libs/OptionsListUtils' ;
27
28
import * as PolicyUtils from '@libs/PolicyUtils' ;
28
29
import { isTaxTrackingEnabled } from '@libs/PolicyUtils' ;
@@ -84,6 +85,18 @@ type MoneyRequestViewPropsWithoutTransaction = MoneyRequestViewOnyxPropsWithoutT
84
85
85
86
type MoneyRequestViewProps = MoneyRequestViewTransactionOnyxProps & MoneyRequestViewPropsWithoutTransaction ;
86
87
88
+ const deleteTransaction = ( parentReport : OnyxEntry < OnyxTypes . Report > , parentReportAction : OnyxEntry < OnyxTypes . ReportAction > ) => {
89
+ if ( ! parentReportAction ) {
90
+ return ;
91
+ }
92
+ const iouTransactionID = ReportActionsUtils . isMoneyRequestAction ( parentReportAction ) ? ReportActionsUtils . getOriginalMessage ( parentReportAction ) ?. IOUTransactionID ?? '-1' : '-1' ;
93
+ if ( ReportActionsUtils . isTrackExpenseAction ( parentReportAction ) ) {
94
+ IOU . deleteTrackExpense ( parentReport ?. reportID ?? '-1' , iouTransactionID , parentReportAction , true ) ;
95
+ return ;
96
+ }
97
+ IOU . deleteMoneyRequest ( iouTransactionID , parentReportAction , true ) ;
98
+ } ;
99
+
87
100
function MoneyRequestView ( {
88
101
report,
89
102
parentReport,
@@ -103,7 +116,7 @@ function MoneyRequestView({
103
116
const { translate, toLocaleDigit} = useLocalize ( ) ;
104
117
const [ activePolicyID ] = useOnyx ( ONYXKEYS . NVP_ACTIVE_POLICY_ID ) ;
105
118
106
- const parentReportAction = parentReportActions ?. [ report . parentReportActionID ?? '-1' ] ?? null ;
119
+ const parentReportAction = parentReportActions ?. [ report . parentReportActionID ?? '-1' ] ;
107
120
const isTrackExpense = ReportUtils . isTrackExpenseReport ( report ) ;
108
121
const { canUseViolations, canUseP2PDistanceRequests} = usePermissions ( isTrackExpense ? CONST . IOU . TYPE . TRACK : undefined ) ;
109
122
const moneyRequestReport = parentReport ;
@@ -391,6 +404,9 @@ function MoneyRequestView({
391
404
if ( ! transaction ?. transactionID ) {
392
405
return ;
393
406
}
407
+ if ( Object . values ( transaction ?. errors ?? { } ) ?. find ( ( error ) => ErrorUtils . isReceiptError ( error ) ) ) {
408
+ deleteTransaction ( parentReport , parentReportAction ) ;
409
+ }
394
410
Transaction . clearError ( transaction . transactionID ) ;
395
411
ReportActions . clearAllRelatedReportActionErrors ( report . reportID , parentReportAction ) ;
396
412
} }
0 commit comments