Skip to content

Commit 37e5ee1

Browse files
authored
Merge pull request Expensify#68847 from mkzie2/mkzie2-issue/68798
fix: report field is not editable for invoice/track expense
2 parents 615f6d1 + fab7cf8 commit 37e5ee1

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

src/libs/ReportUtils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4300,7 +4300,10 @@ function canEditFieldOfMoneyRequest(
43004300
}
43014301

43024302
if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.REPORT) {
4303-
if (!isReportOutstanding(moneyRequestReport, moneyRequestReport.policyID)) {
4303+
// Unreported transaction from OldDot can have the reportID as an empty string
4304+
const isUnreportedExpense = !transaction?.reportID || transaction?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID;
4305+
4306+
if (!isReportOutstanding(moneyRequestReport, moneyRequestReport.policyID) && !isUnreportedExpense) {
43044307
return false;
43054308
}
43064309

@@ -4310,9 +4313,6 @@ function canEditFieldOfMoneyRequest(
43104313
}
43114314
const isOwner = moneyRequestReport?.ownerAccountID === currentUserAccountID;
43124315

4313-
// Unreported transaction from OldDot can have the reportID as an empty string
4314-
const isUnreportedExpense = !transaction?.reportID || transaction?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID;
4315-
43164316
if (isInvoiceReport(moneyRequestReport) && !isUnreportedExpense) {
43174317
return (
43184318
getOutstandingReportsForUser(

tests/unit/canEditFieldOfMoneyRequestTest.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,21 @@ describe('canEditFieldOfMoneyRequest', () => {
260260
// Then they should not be able to move the expense since there's only one outstanding report
261261
expect(canEditReportField).toBe(false);
262262
});
263+
264+
it('should return false when the expense report is not outstanding report', async () => {
265+
// Given that there are multiple outstanding expense reports in the same policy
266+
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${IOUReportID}`, {...expenseReport, stateNum: CONST.REPORT.STATE_NUM.APPROVED, statusNum: CONST.REPORT.STATUS_NUM.APPROVED});
267+
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${EXPENSE_OUTSTANDING_REPORT_1_ID}`, outstandingExpenseReport1);
268+
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${EXPENSE_OUTSTANDING_REPORT_2_ID}`, outstandingExpenseReport2);
269+
await waitForBatchedUpdates();
270+
const outstandingReportsByPolicyID = await OnyxUtils.get(ONYXKEYS.DERIVED.OUTSTANDING_REPORTS_BY_POLICY_ID);
271+
272+
// When the submitter tries to move an expense between reports
273+
const canEditReportField = canEditFieldOfMoneyRequest(reportAction, CONST.EDIT_REQUEST_FIELD.REPORT, undefined, undefined, outstandingReportsByPolicyID);
274+
275+
// Then they should be able to move the expense since there are multiple outstanding expense reports
276+
expect(canEditReportField).toBe(false);
277+
});
263278
});
264279
});
265280
});

0 commit comments

Comments
 (0)