Skip to content

Commit 633646b

Browse files
authored
Merge pull request Expensify#66712 from etCoderDysto/move_invoice_report
2 parents 78c7094 + ae046de commit 633646b

2 files changed

Lines changed: 77 additions & 0 deletions

File tree

src/libs/ReportUtils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4229,6 +4229,17 @@ function canEditFieldOfMoneyRequest(reportAction: OnyxInputOrEntry<ReportAction>
42294229
if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.REPORT) {
42304230
// Unreported transaction from OldDot can have the reportID as an empty string
42314231
const isUnreportedExpense = !transaction?.reportID || transaction?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID;
4232+
4233+
if (isInvoiceReport(moneyRequestReport) && !isUnreportedExpense) {
4234+
return (
4235+
getOutstandingReportsForUser(
4236+
moneyRequestReport?.policyID,
4237+
moneyRequestReport?.ownerAccountID,
4238+
reportsByPolicyID?.[moneyRequestReport?.policyID ?? CONST.DEFAULT_NUMBER_ID] ?? {},
4239+
).length > 0
4240+
);
4241+
}
4242+
42324243
return isUnreportedExpense
42334244
? Object.values(allPolicies ?? {}).flatMap((currentPolicy) =>
42344245
getOutstandingReportsForUser(currentPolicy?.id, currentUserAccountID, reportsByPolicyID?.[currentPolicy?.id ?? CONST.DEFAULT_NUMBER_ID] ?? {}),

tests/unit/ReportUtilsTest.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
canAddTransaction,
2323
canDeleteReportAction,
2424
canDeleteTransaction,
25+
canEditFieldOfMoneyRequest,
2526
canEditReportDescription,
2627
canEditRoomVisibility,
2728
canEditWriteCapability,
@@ -295,6 +296,71 @@ describe('ReportUtils', () => {
295296
});
296297
beforeEach(() => IntlStore.load(CONST.LOCALES.DEFAULT).then(waitForBatchedUpdates));
297298

299+
describe('canEditFieldOfMoneyRequest', () => {
300+
const reportActionID = 2;
301+
const IOUReportID = '1234';
302+
const IOUTransactionID = '123';
303+
const randomReportAction = createRandomReportAction(reportActionID);
304+
const policyID = '2424';
305+
const amount = 39;
306+
307+
const policy1 = {...createRandomPolicy(Number(policyID), CONST.POLICY.TYPE.TEAM), areInvoicesEnabled: true, role: CONST.POLICY.ROLE.ADMIN};
308+
309+
// Given that there is at least one outstanding expense report in a policy
310+
const outstandingExpenseReport = {
311+
...createExpenseReport(483),
312+
policyID,
313+
stateNum: CONST.REPORT.STATE_NUM.OPEN,
314+
statusNum: CONST.REPORT.STATUS_NUM.OPEN,
315+
ownerAccountID: currentUserAccountID,
316+
};
317+
318+
// When a user creates an invoice in the same policy
319+
320+
const reportAction = {
321+
...randomReportAction,
322+
actionName: CONST.REPORT.ACTIONS.TYPE.IOU,
323+
actorAccountID: currentUserAccountID,
324+
childStateNum: CONST.REPORT.STATE_NUM.OPEN,
325+
childStatusNum: CONST.REPORT.STATUS_NUM.OPEN,
326+
originalMessage: {
327+
// eslint-disable-next-line deprecation/deprecation
328+
...randomReportAction.originalMessage,
329+
IOUReportID,
330+
IOUTransactionID,
331+
type: CONST.IOU.ACTION.CREATE,
332+
amount,
333+
currency: CONST.CURRENCY.USD,
334+
},
335+
};
336+
337+
const moneyRequestTransaction = {...createRandomTransaction(Number(IOUTransactionID)), reportID: IOUReportID, transactionID: IOUTransactionID, amount};
338+
339+
const invoiceReport = {
340+
...createInvoiceReport(Number(IOUReportID)),
341+
policyID,
342+
ownerAccountID: currentUserAccountID,
343+
state: CONST.REPORT.ACTIONS.TYPE.SUBMITTED,
344+
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
345+
statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED,
346+
managerID: 8723,
347+
};
348+
349+
beforeAll(() => {
350+
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${IOUTransactionID}`, moneyRequestTransaction);
351+
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${IOUReportID}`, invoiceReport);
352+
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${483}`, outstandingExpenseReport);
353+
Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, policy1);
354+
return waitForBatchedUpdates();
355+
});
356+
357+
// Then the user should be able to move the invoice to the outstanding expense report
358+
it('should return true for invoice report action given that there is a minimum of one outstanding report', () => {
359+
const canEditReportField = canEditFieldOfMoneyRequest(reportAction, CONST.EDIT_REQUEST_FIELD.REPORT);
360+
expect(canEditReportField).toBe(true);
361+
});
362+
});
363+
298364
describe('prepareOnboardingOnyxData', () => {
299365
it('provides test drive url to task title', () => {
300366
const title = jest.fn();

0 commit comments

Comments
 (0)