Skip to content
9 changes: 9 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5457,6 +5457,14 @@ function isHoldCreator(transaction: OnyxEntry<Transaction>, reportID: string): b
return isActionCreator(holdReportAction);
}

/**
* Get all held transactions of a iouReport
*/
function getAllHeldTransactions(iouReportID: string): Transaction[] {
const transactions = TransactionUtils.getAllReportTransactions(iouReportID);
return transactions.filter((transaction) => TransactionUtils.isOnHold(transaction));
}

/**
* Check if Report has any held expenses
*/
Expand Down Expand Up @@ -5979,6 +5987,7 @@ export {
hasActionsWithErrors,
getGroupChatName,
getOutstandingChildRequest,
getAllHeldTransactions,
};

export type {
Expand Down
28 changes: 27 additions & 1 deletion src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4861,7 +4861,8 @@ function hasIOUToApproveOrPay(chatReport: OnyxEntry<OnyxTypes.Report> | EmptyObj
function approveMoneyRequest(expenseReport: OnyxTypes.Report | EmptyObject, full?: boolean) {
const currentNextStep = allNextSteps[`${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`] ?? null;
let total = expenseReport.total ?? 0;
if (ReportUtils.hasHeldExpenses(expenseReport.reportID) && !full && !!expenseReport.unheldTotal) {
const hasHeldExpenses = ReportUtils.hasHeldExpenses(expenseReport.reportID);
if (hasHeldExpenses && !full && !!expenseReport.unheldTotal) {
total = expenseReport.unheldTotal;
}
const optimisticApprovedReportAction = ReportUtils.buildOptimisticApprovedReportAction(total, expenseReport.currency ?? '', expenseReport.reportID);
Expand Down Expand Up @@ -4956,6 +4957,31 @@ function approveMoneyRequest(expenseReport: OnyxTypes.Report | EmptyObject, full
},
];

// Clear hold reason of all transactions if we approve all requests
if (full && hasHeldExpenses) {
const heldTransactions = ReportUtils.getAllHeldTransactions(expenseReport.reportID);
heldTransactions.forEach((heldTransaction) => {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${heldTransaction.transactionID}`,
value: {
comment: {
hold: '',
},
},
});
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${heldTransaction.transactionID}`,
value: {
comment: {
hold: heldTransaction.comment.hold,
},
},
});
});
}

const parameters: ApproveMoneyRequestParams = {
reportID: expenseReport.reportID,
approvedReportActionID: optimisticApprovedReportAction.reportActionID,
Expand Down