Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2351,17 +2351,12 @@ function canAddOrDeleteTransactions(moneyRequestReport: OnyxEntry<Report>): 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<Report>): 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;
Expand Down Expand Up @@ -9340,7 +9335,7 @@ function hasMissingPaymentMethod(userWallet: OnyxEntry<UserWallet>, 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<Report> | undefined, chatReport: OnyxInputOrEntry<Report>): boolean {
return !existingIOUReport || hasIOUWaitingOnCurrentUserBankAccount(chatReport) || !canAddTransaction(existingIOUReport);
Expand Down
64 changes: 33 additions & 31 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -911,37 +911,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', () => {
Expand Down Expand Up @@ -1156,6 +1125,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", () => {
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(),
Expand Down