Skip to content

Commit a451af9

Browse files
committed
fix: report field is not editable for invoice/track expense
1 parent 981b112 commit a451af9

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

src/libs/ReportUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4300,7 +4300,7 @@ function canEditFieldOfMoneyRequest(
43004300
}
43014301

43024302
if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.REPORT) {
4303-
if (!isReportOutstanding(moneyRequestReport, moneyRequestReport.policyID)) {
4303+
if (!isReportOutstanding(moneyRequestReport, moneyRequestReport.policyID) && isExpenseReport(moneyRequestReport)) {
43044304
return false;
43054305
}
43064306

tests/unit/canEditFieldOfMoneyRequestTest.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,14 @@ describe('canEditFieldOfMoneyRequest', () => {
103103
return waitForBatchedUpdates();
104104
});
105105

106-
it('should return false for invoice report action if it is not outstanding report', async () => {
106+
// Then the user should be able to move the invoice to the outstanding expense report
107+
it('should return true for invoice report action given that there is a minimum of one outstanding report', async () => {
107108
const outstandingReportsByPolicyID = await OnyxUtils.get(ONYXKEYS.DERIVED.OUTSTANDING_REPORTS_BY_POLICY_ID);
108109

109110
const canEditReportField = canEditFieldOfMoneyRequest(reportAction, CONST.EDIT_REQUEST_FIELD.REPORT, undefined, undefined, outstandingReportsByPolicyID);
110-
expect(canEditReportField).toBe(false);
111-
});
112-
113-
it('should return true for invoice report action when there are outstanding reports', async () => {
114-
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${IOUReportID}`, outstandingExpenseReport);
115-
await waitForBatchedUpdates();
116-
const outstandingReportsByPolicyID = await OnyxUtils.get(ONYXKEYS.DERIVED.OUTSTANDING_REPORTS_BY_POLICY_ID);
117-
118-
const canEditReportField = canEditFieldOfMoneyRequest(reportAction, CONST.EDIT_REQUEST_FIELD.REPORT, undefined, undefined, outstandingReportsByPolicyID);
119-
120111
expect(canEditReportField).toBe(true);
121112
});
113+
122114
});
123115

124116
describe('type is expense', () => {
@@ -260,6 +252,21 @@ describe('canEditFieldOfMoneyRequest', () => {
260252
// Then they should not be able to move the expense since there's only one outstanding report
261253
expect(canEditReportField).toBe(false);
262254
});
255+
256+
it('should return false when the expense report is not outstanding report', async () => {
257+
// Given that there are multiple outstanding expense reports in the same policy
258+
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${IOUReportID}`, {...expenseReport, stateNum: CONST.REPORT.STATE_NUM.APPROVED, statusNum: CONST.REPORT.STATUS_NUM.APPROVED});
259+
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${EXPENSE_OUTSTANDING_REPORT_1_ID}`, outstandingExpenseReport1);
260+
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${EXPENSE_OUTSTANDING_REPORT_2_ID}`, outstandingExpenseReport2);
261+
await waitForBatchedUpdates();
262+
const outstandingReportsByPolicyID = await OnyxUtils.get(ONYXKEYS.DERIVED.OUTSTANDING_REPORTS_BY_POLICY_ID);
263+
264+
// When the submitter tries to move an expense between reports
265+
const canEditReportField = canEditFieldOfMoneyRequest(reportAction, CONST.EDIT_REQUEST_FIELD.REPORT, undefined, undefined, outstandingReportsByPolicyID);
266+
267+
// Then they should be able to move the expense since there are multiple outstanding expense reports
268+
expect(canEditReportField).toBe(false);
269+
});
263270
});
264271
});
265272
});

0 commit comments

Comments
 (0)