Skip to content

Commit 52b9984

Browse files
authored
Merge pull request #49677 from Expensify/youssef_reports_awaiting_first_level_approval
Handle optimistic data when creating new expenses in Control w/ Instant Submit
2 parents 5e975f5 + 8d47250 commit 52b9984

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/libs/ReportUtils.ts

+15
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,16 @@ function isProcessingReport(report: OnyxEntry<Report>): boolean {
12891289
return report?.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED && report?.statusNum === CONST.REPORT.STATUS_NUM.SUBMITTED;
12901290
}
12911291

1292+
function isAwaitingFirstLevelApproval(report: OnyxEntry<Report>): boolean {
1293+
if (!report) {
1294+
return false;
1295+
}
1296+
1297+
const submitsToAccountID = PolicyUtils.getSubmitToAccountID(getPolicy(report.policyID), report.ownerAccountID ?? -1);
1298+
1299+
return isProcessingReport(report) && submitsToAccountID === report.managerID;
1300+
}
1301+
12921302
/**
12931303
* Check if the report is a single chat report that isn't a thread
12941304
* and personal detail of participant is optimistic data
@@ -1744,6 +1754,10 @@ function canAddOrDeleteTransactions(moneyRequestReport: OnyxEntry<Report>): bool
17441754
return false;
17451755
}
17461756

1757+
if (PolicyUtils.isInstantSubmitEnabled(policy) && isProcessingReport(moneyRequestReport)) {
1758+
return isAwaitingFirstLevelApproval(moneyRequestReport);
1759+
}
1760+
17471761
if (isReportApproved(moneyRequestReport) || isSettled(moneyRequestReport?.reportID)) {
17481762
return false;
17491763
}
@@ -8519,6 +8533,7 @@ export {
85198533
isPolicyExpenseChat,
85208534
isPolicyExpenseChatAdmin,
85218535
isProcessingReport,
8536+
isAwaitingFirstLevelApproval,
85228537
isPublicAnnounceRoom,
85238538
isPublicRoom,
85248539
isReportApproved,

tests/unit/ReportUtilsTest.ts

+9
Original file line numberDiff line numberDiff line change
@@ -691,13 +691,21 @@ describe('ReportUtils', () => {
691691
owner: '',
692692
outputCurrency: '',
693693
isPolicyExpenseChatEnabled: false,
694+
employeeList: {
695+
[currentUserEmail]: {
696+
email: currentUserEmail,
697+
submitsTo: currentUserEmail,
698+
},
699+
},
694700
};
695701
Promise.all([
696702
Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${paidPolicy.id}`, paidPolicy),
697703
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}101`, {
698704
reportID: '101',
699705
chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT,
700706
isOwnPolicyExpenseChat: true,
707+
policyID: paidPolicy.id,
708+
ownerAccountID: currentUserAccountID,
701709
}),
702710
]).then(() => {
703711
const report = {
@@ -708,6 +716,7 @@ describe('ReportUtils', () => {
708716
parentReportID: '101',
709717
policyID: paidPolicy.id,
710718
managerID: currentUserAccountID,
719+
ownerAccountID: currentUserAccountID,
711720
};
712721
const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, paidPolicy, [currentUserAccountID, participantsAccountIDs.at(0) ?? -1]);
713722
expect(moneyRequestOptions.length).toBe(2);

0 commit comments

Comments
 (0)