From 7fc2fb8d1cc8be228729b2f339437fb1192127cc Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Fri, 7 Mar 2025 06:51:44 +0000 Subject: [PATCH 1/6] Don't show pay button if report has negative total --- src/libs/actions/IOU.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index ef8674e2f16c..fdf31a31b3b1 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -8277,7 +8277,7 @@ function canIOUBePaid( !isOpenExpenseReport && !iouSettled && !iouReport?.isWaitingOnBankAccount && - reimbursableSpend !== 0 && + reimbursableSpend > 0 && !isChatReportArchived && !isAutoReimbursable && (!shouldBeApproved || !shouldCheckApprovedState) && From c4f09389812cfd832be84217ba239fb34d05fd5c Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Fri, 7 Mar 2025 07:05:24 +0000 Subject: [PATCH 2/6] Add test --- tests/actions/IOUTest.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 51e621909f60..82b8db884cd5 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -6,6 +6,7 @@ import { canApproveIOU, canCancelPayment, cancelPayment, + canIOUBePaid, canUnapproveIOU, deleteMoneyRequest, payMoneyRequest, @@ -4768,4 +4769,26 @@ describe('actions/IOU', () => { expect(canCancelPayment(fakeReport, {accountID: RORY_ACCOUNT_ID})).toBeTruthy(); }); }); + + describe('canIOUBePaid', () => { + it('should return false if the report has negative total', () => { + const policyChat = createRandomReport(1); + const fakePolicy: Policy = { + ...createRandomPolicy(Number('AA')), + type: CONST.POLICY.TYPE.TEAM, + approvalMode: CONST.POLICY.APPROVAL_MODE.BASIC, + }; + + const fakeReport: Report = { + ...createRandomReport(1), + type: CONST.REPORT.TYPE.EXPENSE, + policyID: 'AA', + stateNum: CONST.REPORT.STATE_NUM.APPROVED, + statusNum: CONST.REPORT.STATUS_NUM.APPROVED, + managerID: RORY_ACCOUNT_ID, + total: 100, // positive amount in the DB means negative amount in the UI + }; + expect(canIOUBePaid(fakeReport, policyChat, fakePolicy)).toBeFalsy(); + }); + }); }); From 7e6a5f01350cb2ca8e1a647b2383a1d82f177708 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Sat, 8 Mar 2025 00:59:12 +0000 Subject: [PATCH 3/6] Fix display of submitted action to show negative amount --- src/libs/ReportUtils.ts | 12 ++++++++---- src/pages/home/report/PureReportActionItem.tsx | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 454c25a0b6d1..838f49116139 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5281,7 +5281,7 @@ function buildOptimisticExpenseReport( return expenseReport; } -function getFormattedAmount(reportAction: ReportAction) { +function getFormattedAmount(reportAction: ReportAction, report?: Report) { if ( !isSubmittedAction(reportAction) && !isForwardedAction(reportAction) && @@ -5292,7 +5292,8 @@ function getFormattedAmount(reportAction: ReportAction) { return ''; } const originalMessage = getOriginalMessage(reportAction); - const formattedAmount = convertToDisplayString(Math.abs(originalMessage?.amount ?? 0), originalMessage?.currency); + const amount = report && isExpenseReport(report) ? (originalMessage?.amount ?? 0) * -1 : Math.abs(originalMessage?.amount ?? 0); + const formattedAmount = convertToDisplayString(amount, originalMessage?.currency); return formattedAmount; } @@ -5302,8 +5303,11 @@ function getReportAutomaticallySubmittedMessage( return translateLocal('iou.automaticallySubmittedAmount', {formattedAmount: getFormattedAmount(reportAction)}); } -function getIOUSubmittedMessage(reportAction: ReportAction | ReportAction) { - return translateLocal('iou.submittedAmount', {formattedAmount: getFormattedAmount(reportAction)}); +function getIOUSubmittedMessage( + reportAction: ReportAction | ReportAction, + report: Report, +) { + return translateLocal('iou.submittedAmount', {formattedAmount: getFormattedAmount(reportAction, report)}); } function getReportAutomaticallyApprovedMessage(reportAction: ReportAction) { diff --git a/src/pages/home/report/PureReportActionItem.tsx b/src/pages/home/report/PureReportActionItem.tsx index de098395987f..8bc85f4dee72 100644 --- a/src/pages/home/report/PureReportActionItem.tsx +++ b/src/pages/home/report/PureReportActionItem.tsx @@ -839,7 +839,7 @@ function PureReportActionItem({ ); } else { - children = ; + children = ; } } else if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.APPROVED)) { const wasAutoApproved = getOriginalMessage(action)?.automaticAction ?? false; From 87c3098d5fbd229203a33fdb880c0bca7359c9ad Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Sat, 8 Mar 2025 02:53:28 +0000 Subject: [PATCH 4/6] Fix negative total display for all IOU actions --- src/libs/ReportUtils.ts | 23 ++++++++++--------- .../home/report/PureReportActionItem.tsx | 6 ++--- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 838f49116139..8ea8e1cf584e 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5281,7 +5281,7 @@ function buildOptimisticExpenseReport( return expenseReport; } -function getFormattedAmount(reportAction: ReportAction, report?: Report) { +function getFormattedAmount(reportAction: ReportAction, report?: Report | null) { if ( !isSubmittedAction(reportAction) && !isForwardedAction(reportAction) && @@ -5299,27 +5299,28 @@ function getFormattedAmount(reportAction: ReportAction, report?: Report) { function getReportAutomaticallySubmittedMessage( reportAction: ReportAction | ReportAction, + report?: Report, ) { - return translateLocal('iou.automaticallySubmittedAmount', {formattedAmount: getFormattedAmount(reportAction)}); + return translateLocal('iou.automaticallySubmittedAmount', {formattedAmount: getFormattedAmount(reportAction, report)}); } function getIOUSubmittedMessage( reportAction: ReportAction | ReportAction, - report: Report, + report?: Report, ) { return translateLocal('iou.submittedAmount', {formattedAmount: getFormattedAmount(reportAction, report)}); } -function getReportAutomaticallyApprovedMessage(reportAction: ReportAction) { - return translateLocal('iou.automaticallyApprovedAmount', {amount: getFormattedAmount(reportAction)}); +function getReportAutomaticallyApprovedMessage(reportAction: ReportAction, report?: Report) { + return translateLocal('iou.automaticallyApprovedAmount', {amount: getFormattedAmount(reportAction, report)}); } -function getIOUUnapprovedMessage(reportAction: ReportAction) { - return translateLocal('iou.unapprovedAmount', {amount: getFormattedAmount(reportAction)}); +function getIOUUnapprovedMessage(reportAction: ReportAction, report?: Report) { + return translateLocal('iou.unapprovedAmount', {amount: getFormattedAmount(reportAction, report)}); } -function getIOUApprovedMessage(reportAction: ReportAction) { - return translateLocal('iou.approvedAmount', {amount: getFormattedAmount(reportAction)}); +function getIOUApprovedMessage(reportAction: ReportAction, report?: Report) { + return translateLocal('iou.approvedAmount', {amount: getFormattedAmount(reportAction, report)}); } /** @@ -5333,7 +5334,7 @@ function getReportAutomaticallyForwardedMessage(reportAction: ReportAction - ${getReportAutomaticallyApprovedMessage(action)}`} /> + ${getReportAutomaticallyApprovedMessage(action, report)}`} /> ); } else { - children = ; + children = ; } } else if (isUnapprovedAction(action)) { - children = ; + children = ; } else if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.FORWARDED)) { const wasAutoForwarded = getOriginalMessage(action)?.automaticAction ?? false; if (wasAutoForwarded) { From 2d92a2d6ac86f9ae79308e466842c68ce24e598e Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Sat, 8 Mar 2025 02:54:45 +0000 Subject: [PATCH 5/6] Add missing param --- src/pages/home/report/PureReportActionItem.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/PureReportActionItem.tsx b/src/pages/home/report/PureReportActionItem.tsx index 1530671738a1..4208aa96f066 100644 --- a/src/pages/home/report/PureReportActionItem.tsx +++ b/src/pages/home/report/PureReportActionItem.tsx @@ -835,7 +835,7 @@ function PureReportActionItem({ if (wasSubmittedViaHarvesting) { children = ( - ${getReportAutomaticallySubmittedMessage(action)}`} /> + ${getReportAutomaticallySubmittedMessage(action, report)}`} /> ); } else { From f05bbd18357030270729b86c16beef24cf8f22e2 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Sat, 8 Mar 2025 03:03:28 +0000 Subject: [PATCH 6/6] Use the total from the report instead of report action --- src/libs/ReportUtils.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 8ea8e1cf584e..4f8b93e7dcfe 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5292,7 +5292,10 @@ function getFormattedAmount(reportAction: ReportAction, report?: Report | null) return ''; } const originalMessage = getOriginalMessage(reportAction); - const amount = report && isExpenseReport(report) ? (originalMessage?.amount ?? 0) * -1 : Math.abs(originalMessage?.amount ?? 0); + + // Expense reports can have a negative amount and we need to display it as negative in the UI + // the amount found in originalMessage does not accurately track this so we need to use the total from the report instead + const amount = report && isExpenseReport(report) ? (report?.total ?? 0) * -1 : Math.abs(originalMessage?.amount ?? 0); const formattedAmount = convertToDisplayString(amount, originalMessage?.currency); return formattedAmount; }