diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 9c8dcbdd44b15..622ac433b953c 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2642,19 +2642,26 @@ function isOneOnOneChat(report: OnyxEntry): boolean { function isPayer(session: OnyxEntry, iouReport: OnyxEntry, onlyShowPayElsewhere = false, reportPolicy?: OnyxInputOrEntry) { const policy = reportPolicy ?? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${iouReport?.policyID}`] ?? null; - const policyType = policy?.type; - const isAdmin = policyType !== CONST.POLICY.TYPE.PERSONAL && policy?.role === CONST.POLICY.ROLE.ADMIN; + + if (!policy) { + Log.warn('Missing policy during isPayer check'); + + return false; + } + + const policyType = policy.type; + const isAdmin = policyType !== CONST.POLICY.TYPE.PERSONAL && policy.role === CONST.POLICY.ROLE.ADMIN; const isManager = iouReport?.managerID === session?.accountID; - const reimbursementChoice = policy?.reimbursementChoice; + const reimbursementChoice = policy.reimbursementChoice; if (isPaidGroupPolicy(iouReport)) { if (reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES) { - if (!policy?.achAccount?.reimburser) { + if (!policy.achAccount?.reimburser) { return isAdmin; } // If we are the reimburser and the report is approved or we are the manager then we can pay it. - const isReimburser = session?.email === policy?.achAccount?.reimburser; + const isReimburser = session?.email === policy.achAccount?.reimburser; return isReimburser; } if (reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL || onlyShowPayElsewhere) { diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 0f95c838d5286..8e27b8944b266 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -10679,10 +10679,6 @@ function canIOUBePaid( ); } -function canCancelPayment(iouReport: OnyxEntry, session: OnyxEntry) { - return isPayerReportUtils(session, iouReport) && (isSettled(iouReport) || iouReport?.isWaitingOnBankAccount) && isExpenseReport(iouReport); -} - function canSubmitReport( report: OnyxEntry, policy: OnyxEntry, @@ -15160,7 +15156,6 @@ export { canUnapproveIOU, cancelPayment, canIOUBePaid, - canCancelPayment, cleanUpMoneyRequest, clearMoneyRequest, completeSplitBill, diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index c67d079be66c5..fcfcc9b8a76d5 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -16,7 +16,6 @@ import { approveMoneyRequest, calculateDiffAmount, canApproveIOU, - canCancelPayment, cancelPayment, canIOUBePaid, canUnapproveIOU, @@ -6876,21 +6875,6 @@ describe('actions/IOU', () => { }); }); - describe('canCancelPayment', () => { - it('should return true if the report is waiting for a bank account', () => { - const fakeReport: Report = { - ...createRandomReport(1, undefined), - type: CONST.REPORT.TYPE.EXPENSE, - policyID: 'A', - stateNum: CONST.REPORT.STATE_NUM.APPROVED, - statusNum: CONST.REPORT.STATUS_NUM.APPROVED, - isWaitingOnBankAccount: true, - managerID: RORY_ACCOUNT_ID, - }; - expect(canCancelPayment(fakeReport, {accountID: RORY_ACCOUNT_ID})).toBeTruthy(); - }); - }); - describe('canIOUBePaid', () => { it('should return false if the report has negative total and onlyShowPayElsewhere is false', async () => { const policyChat = createRandomReport(1, CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT);