Skip to content

Commit adce9b9

Browse files
Merge pull request Expensify#90881 from paulnjs/paulnjs-fix/89703
fix: Unexpected error when approver hold expense
2 parents 8517363 + 43d0fb0 commit adce9b9

4 files changed

Lines changed: 49 additions & 1 deletion

File tree

src/libs/ReportSecondaryActionUtils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import {
5858
hasOnlyNonReimbursableTransactions,
5959
hasReportBeenReopened as hasReportBeenReopenedUtils,
6060
hasReportBeenRetracted as hasReportBeenRetractedUtils,
61+
isActionCreator,
6162
isArchivedReport,
6263
isAwaitingFirstLevelApproval,
6364
isClosedReport as isClosedReportUtils,
@@ -68,6 +69,7 @@ import {
6869
isInvoiceReport as isInvoiceReportUtils,
6970
isIOUReport as isIOUReportUtils,
7071
isMoneyRequestReportEligibleForMerge,
72+
isOpenExpenseReport,
7173
isOpenReport as isOpenReportUtils,
7274
isPayer as isPayerUtils,
7375
isProcessingReport as isProcessingReportUtils,
@@ -563,6 +565,11 @@ function isHoldActionForTransaction(
563565
const iouOrExpenseReport = isExpenseReport || isIOUReport;
564566
const holdReportAction = getReportAction(reportAction?.childReportID, `${reportTransaction?.comment?.hold ?? ''}`);
565567
const {canHoldRequest} = canHoldUnholdReportAction(report, reportAction, holdReportAction, reportTransaction, policy, currentUserAccountID);
568+
const isActionOwner = isActionCreator(reportAction);
569+
570+
if (isOpenExpenseReport(report)) {
571+
return isActionOwner && canHoldRequest;
572+
}
566573

567574
if (!iouOrExpenseReport || !canHoldRequest) {
568575
return false;

src/libs/ReportUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5076,7 +5076,7 @@ function canModifyHoldStatus(report: Report, reportAction: ReportAction, current
50765076
}
50775077

50785078
if (isOpenExpenseReport(report)) {
5079-
return isActionOwner || isManager;
5079+
return isActionOwner;
50805080
}
50815081

50825082
if (isActionOwner && !isAdmin) {

src/libs/actions/IOU/Hold.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ function putOnHold(
161161
| typeof ONYXKEYS.COLLECTION.REPORT
162162
| typeof ONYXKEYS.COLLECTION.REPORT_METADATA
163163
| typeof ONYXKEYS.COLLECTION.NEXT_STEP
164+
| typeof ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS
164165
>
165166
> = [
166167
{
@@ -189,6 +190,11 @@ function putOnHold(
189190
lastVisibleActionCreated: transactionThreadReport.lastVisibleActionCreated,
190191
},
191192
},
193+
{
194+
onyxMethod: Onyx.METHOD.MERGE,
195+
key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`,
196+
value: transactionViolations,
197+
},
192198
];
193199

194200
// If the transaction thread report wasn't created before, we create it optimistically

tests/unit/ReportSecondaryActionUtilsTest.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,41 @@ describe('getSecondaryAction', () => {
14941494
expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.HOLD)).toBe(false);
14951495
});
14961496

1497+
it('does not include HOLD option for action owner on open expense report when expense is already on hold', () => {
1498+
const report = {
1499+
reportID: REPORT_ID,
1500+
type: CONST.REPORT.TYPE.EXPENSE,
1501+
ownerAccountID: EMPLOYEE_ACCOUNT_ID,
1502+
stateNum: CONST.REPORT.STATE_NUM.OPEN,
1503+
statusNum: CONST.REPORT.STATUS_NUM.OPEN,
1504+
} as unknown as Report;
1505+
1506+
const transaction = {
1507+
transactionID: 'TRANSACTION_ID_R14932',
1508+
comment: {
1509+
hold: 'REPORT_ACTION_ID',
1510+
},
1511+
} as unknown as Transaction;
1512+
const policy = {} as unknown as Policy;
1513+
1514+
jest.spyOn(ReportUtils, 'canHoldUnholdReportAction').mockReturnValueOnce({canHoldRequest: false, canUnholdRequest: true});
1515+
jest.spyOn(ReportUtils, 'isActionCreator').mockReturnValue(true);
1516+
jest.spyOn(ReportActionsUtils, 'getOneTransactionThreadReportID').mockReturnValueOnce(originalMessageR14932.IOUTransactionID);
1517+
const result = getSecondaryReportActions({
1518+
currentUserLogin: EMPLOYEE_EMAIL,
1519+
currentUserAccountID: EMPLOYEE_ACCOUNT_ID,
1520+
report,
1521+
chatReport,
1522+
reportTransactions: [transaction],
1523+
originalTransaction: {} as Transaction,
1524+
violations: {},
1525+
bankAccountList: {},
1526+
policy,
1527+
reportActions: [actionR14932],
1528+
});
1529+
expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.HOLD)).toBe(false);
1530+
});
1531+
14971532
it('does not include CHANGE_WORKSPACE option for submitted IOU report and manager being the payer of the new policy', async () => {
14981533
const report = {
14991534
reportID: REPORT_ID,

0 commit comments

Comments
 (0)