From 6a20b01147b6d864c856bc10384ef5d43ff58278 Mon Sep 17 00:00:00 2001 From: daledah Date: Wed, 2 Apr 2025 14:15:18 +0700 Subject: [PATCH 1/3] fix: allow create expense on submitted report --- src/libs/ReportUtils.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index a583da653005..3b3e7bd49283 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2233,17 +2233,12 @@ function canAddOrDeleteTransactions(moneyRequestReport: OnyxEntry): bool * Return true if: * - report is a non-settled IOU * - report is a draft - * - report is a processing expense report and its policy has Instant reporting frequency */ function canAddTransaction(moneyRequestReport: OnyxEntry): boolean { if (!isMoneyRequestReport(moneyRequestReport)) { return false; } - if (isReportInGroupPolicy(moneyRequestReport) && isProcessingReport(moneyRequestReport) && !isInstantSubmitEnabled(getPolicy(moneyRequestReport?.policyID))) { - return false; - } - const policy = getPolicy(moneyRequestReport?.policyID); if (isInstantSubmitEnabled(policy) && isSubmitAndClose(policy) && hasOnlyNonReimbursableTransactions(moneyRequestReport?.reportID)) { return false; @@ -8912,7 +8907,7 @@ function hasMissingPaymentMethod(userWallet: OnyxEntry, iouReportID: * Create a new report if: * - we don't have an iouReport set in the chatReport * - we have one, but it's waiting on the payee adding a bank account - * - we have one, but we can't add more transactions to it due to: report is approved or settled, or report is processing and policy isn't on Instant submit reporting frequency + * - we have one, but we can't add more transactions to it due to: report is approved or settled */ function shouldCreateNewMoneyRequestReport(existingIOUReport: OnyxInputOrEntry | undefined, chatReport: OnyxInputOrEntry): boolean { return !existingIOUReport || hasIOUWaitingOnCurrentUserBankAccount(chatReport) || !canAddTransaction(existingIOUReport); From c4f825561229eaab98ee529b694dd91d659c1d1d Mon Sep 17 00:00:00 2001 From: daledah Date: Wed, 2 Apr 2025 14:28:53 +0700 Subject: [PATCH 2/3] fix: update test case --- tests/unit/ReportUtilsTest.ts | 64 ++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 4c5d3ec6c9a0..2afeb7e3e235 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -735,37 +735,6 @@ describe('ReportUtils', () => { expect(moneyRequestOptions.length).toBe(0); }); }); - - it("it is a submitted report tied to user's own policy expense chat and the policy does not have Instant Submit frequency", () => { - const paidPolicy: Policy = { - id: '3f54cca8', - type: CONST.POLICY.TYPE.TEAM, - name: '', - role: 'user', - owner: '', - outputCurrency: '', - isPolicyExpenseChatEnabled: false, - }; - Promise.all([ - Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${paidPolicy.id}`, paidPolicy), - Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}101`, { - reportID: '101', - chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, - isOwnPolicyExpenseChat: true, - }), - ]).then(() => { - const report = { - ...LHNTestUtils.getFakeReport(), - type: CONST.REPORT.TYPE.EXPENSE, - stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, - statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, - parentReportID: '101', - policyID: paidPolicy.id, - }; - const moneyRequestOptions = temporary_getMoneyRequestOptions(report, paidPolicy, [currentUserAccountID, participantsAccountIDs.at(0) ?? CONST.DEFAULT_NUMBER_ID]); - expect(moneyRequestOptions.length).toBe(0); - }); - }); }); describe('return only iou split option if', () => { @@ -980,6 +949,39 @@ describe('ReportUtils', () => { expect(moneyRequestOptions.indexOf(CONST.IOU.TYPE.SUBMIT)).toBe(0); }); + it("it is a submitted report tied to user's own policy expense chat and the policy does not have Instant Submit frequency", () => { + const paidPolicy: Policy = { + id: '3f54cca8', + type: CONST.POLICY.TYPE.TEAM, + name: '', + role: 'user', + owner: '', + outputCurrency: '', + isPolicyExpenseChatEnabled: false, + }; + Promise.all([ + Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${paidPolicy.id}`, paidPolicy), + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}101`, { + reportID: '101', + chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, + isOwnPolicyExpenseChat: true, + }), + ]).then(() => { + const report = { + ...LHNTestUtils.getFakeReport(), + type: CONST.REPORT.TYPE.EXPENSE, + stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, + statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, + parentReportID: '101', + policyID: paidPolicy.id, + }; + const moneyRequestOptions = temporary_getMoneyRequestOptions(report, paidPolicy, [currentUserAccountID, participantsAccountIDs.at(0) ?? CONST.DEFAULT_NUMBER_ID]); + expect(moneyRequestOptions.length).toBe(2); + expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(true); + expect(moneyRequestOptions.includes(CONST.IOU.TYPE.TRACK)).toBe(true); + }); + }); + it("it is user's own policy expense chat", () => { const report = { ...LHNTestUtils.getFakeReport(), From daad377c7efa84f134f051405c344e8bc288e1b3 Mon Sep 17 00:00:00 2001 From: daledah Date: Fri, 16 May 2025 23:01:32 +0700 Subject: [PATCH 3/3] fix: correct test description --- tests/unit/ReportUtilsTest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 080ca0d9b7e4..9130788584d3 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -1125,7 +1125,7 @@ describe('ReportUtils', () => { expect(moneyRequestOptions.indexOf(CONST.IOU.TYPE.SUBMIT)).toBe(0); }); - it("it is a submitted report tied to user's own policy expense chat and the policy does not have Instant Submit frequency", () => { + it("it is a submitted report tied to user's own policy expense chat", () => { const paidPolicy: Policy = { id: '3f54cca8', type: CONST.POLICY.TYPE.TEAM,