Skip to content

Commit

Permalink
Merge pull request #49677 from Expensify/youssef_reports_awaiting_fir…
Browse files Browse the repository at this point in the history
…st_level_approval

Handle optimistic data when creating new expenses in Control w/ Instant Submit
  • Loading branch information
jasperhuangg authored Oct 23, 2024
2 parents 5e975f5 + 8d47250 commit 52b9984
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,16 @@ function isProcessingReport(report: OnyxEntry<Report>): boolean {
return report?.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED && report?.statusNum === CONST.REPORT.STATUS_NUM.SUBMITTED;
}

function isAwaitingFirstLevelApproval(report: OnyxEntry<Report>): boolean {
if (!report) {
return false;
}

const submitsToAccountID = PolicyUtils.getSubmitToAccountID(getPolicy(report.policyID), report.ownerAccountID ?? -1);

return isProcessingReport(report) && submitsToAccountID === report.managerID;
}

/**
* Check if the report is a single chat report that isn't a thread
* and personal detail of participant is optimistic data
Expand Down Expand Up @@ -1744,6 +1754,10 @@ function canAddOrDeleteTransactions(moneyRequestReport: OnyxEntry<Report>): bool
return false;
}

if (PolicyUtils.isInstantSubmitEnabled(policy) && isProcessingReport(moneyRequestReport)) {
return isAwaitingFirstLevelApproval(moneyRequestReport);
}

if (isReportApproved(moneyRequestReport) || isSettled(moneyRequestReport?.reportID)) {
return false;
}
Expand Down Expand Up @@ -8519,6 +8533,7 @@ export {
isPolicyExpenseChat,
isPolicyExpenseChatAdmin,
isProcessingReport,
isAwaitingFirstLevelApproval,
isPublicAnnounceRoom,
isPublicRoom,
isReportApproved,
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,13 +691,21 @@ describe('ReportUtils', () => {
owner: '',
outputCurrency: '',
isPolicyExpenseChatEnabled: false,
employeeList: {
[currentUserEmail]: {
email: currentUserEmail,
submitsTo: currentUserEmail,
},
},
};
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,
policyID: paidPolicy.id,
ownerAccountID: currentUserAccountID,
}),
]).then(() => {
const report = {
Expand All @@ -708,6 +716,7 @@ describe('ReportUtils', () => {
parentReportID: '101',
policyID: paidPolicy.id,
managerID: currentUserAccountID,
ownerAccountID: currentUserAccountID,
};
const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, paidPolicy, [currentUserAccountID, participantsAccountIDs.at(0) ?? -1]);
expect(moneyRequestOptions.length).toBe(2);
Expand Down

0 comments on commit 52b9984

Please sign in to comment.