From 06dcc1908ff38a85e367a16f91f07cc369451507 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Tue, 27 May 2025 20:30:12 +0300 Subject: [PATCH 1/2] fix approve amount when other expenses are held --- src/libs/MoneyRequestReportUtils.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libs/MoneyRequestReportUtils.ts b/src/libs/MoneyRequestReportUtils.ts index dcbb7f1aa848..75625660ccb1 100644 --- a/src/libs/MoneyRequestReportUtils.ts +++ b/src/libs/MoneyRequestReportUtils.ts @@ -100,7 +100,8 @@ function shouldDisplayReportTableView(report: OnyxEntry, transactions: T * @returns - The total amount to be formatted as a string. Returns an empty string if no amount is applicable. */ const getTotalAmountForIOUReportPreviewButton = (report: OnyxEntry, policy: OnyxEntry, reportPreviewAction: ValueOf) => { - // Determine whether the non-held amount is appropriate to display for the PAY button. + // Determine whether the non-held amount is appropriate to display for the PAY or APPROVE button. + const isPayOrApproveAction: boolean = reportPreviewAction === CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY || reportPreviewAction === CONST.REPORT.REPORT_PREVIEW_ACTIONS.APPROVE; const {nonHeldAmount, hasValidNonHeldAmount} = getNonHeldAndFullAmount(report, reportPreviewAction === CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY); const hasOnlyHeldExpenses = hasOnlyHeldExpensesReportUtils(report?.reportID); const canAllowSettlement = hasUpdatedTotal(report, policy); @@ -108,8 +109,8 @@ const getTotalAmountForIOUReportPreviewButton = (report: OnyxEntry, poli // Split the total spend into different categories as needed. const {totalDisplaySpend, reimbursableSpend} = getMoneyRequestSpendBreakdown(report); - if (reportPreviewAction === CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY) { - // Return empty string if there are only held expenses which cannot be paid. + if (isPayOrApproveAction) { + // Return empty string if there are only held expenses which cannot be paid or approved. if (hasOnlyHeldExpenses) { return ''; } From dcd4fb09652988f410a832623d80bb56dbd77dea Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Tue, 27 May 2025 21:34:33 +0300 Subject: [PATCH 2/2] changed test expectation --- tests/unit/MoneyRequestReportButtonUtils.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/MoneyRequestReportButtonUtils.test.ts b/tests/unit/MoneyRequestReportButtonUtils.test.ts index ae95549ca3f1..b3d36b8df94c 100644 --- a/tests/unit/MoneyRequestReportButtonUtils.test.ts +++ b/tests/unit/MoneyRequestReportButtonUtils.test.ts @@ -45,7 +45,7 @@ describe('ReportButtonUtils', () => { it('returns total reimbursable spend for PAY & total value for other buttons', () => { expect(getTotalAmountForIOUReportPreviewButton(mockReport, mockPolicy, CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY)).toBe(`$50.00`); expect(getTotalAmountForIOUReportPreviewButton(mockReport, mockPolicy, CONST.REPORT.REPORT_PREVIEW_ACTIONS.REVIEW)).toBe(`$100.00`); - expect(getTotalAmountForIOUReportPreviewButton(mockReport, mockPolicy, CONST.REPORT.REPORT_PREVIEW_ACTIONS.APPROVE)).toBe(`$100.00`); + expect(getTotalAmountForIOUReportPreviewButton(mockReport, mockPolicy, CONST.REPORT.REPORT_PREVIEW_ACTIONS.APPROVE)).toBe(`$50.00`); expect(getTotalAmountForIOUReportPreviewButton(mockReport, mockPolicy, CONST.REPORT.REPORT_PREVIEW_ACTIONS.SUBMIT)).toBe(`$100.00`); }); });