Skip to content

Commit 3ae888e

Browse files
lakchoteOSBotify
authored andcommitted
Merge pull request #89377 from Expensify/lucien/revert-88708
[CP Staging] Revert PR #88708 (cherry picked from commit a2fa790) (cherry-picked to staging by lakchote)
1 parent 0a85fdf commit 3ae888e

4 files changed

Lines changed: 5 additions & 154 deletions

File tree

src/libs/PolicyUtils.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,19 +1242,6 @@ function getSubmitToAccountID(policy: OnyxEntry<Policy>, expenseReport: OnyxEntr
12421242
return getManagerAccountID(policy, expenseReport);
12431243
}
12441244

1245-
function getSubmitReportManagerAccountID(policy: OnyxEntry<Policy>, expenseReport: OnyxEntry<Report>): number {
1246-
const existingManagerID = expenseReport?.managerID ?? CONST.DEFAULT_NUMBER_ID;
1247-
const ownerAccountID = expenseReport?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID;
1248-
1249-
if (existingManagerID > CONST.DEFAULT_NUMBER_ID && existingManagerID !== ownerAccountID) {
1250-
// Existing reports may already have a server-computed or manually changed approver.
1251-
return existingManagerID;
1252-
}
1253-
1254-
const submitToAccountID = getSubmitToAccountID(policy, expenseReport);
1255-
return submitToAccountID > CONST.DEFAULT_NUMBER_ID ? submitToAccountID : existingManagerID;
1256-
}
1257-
12581245
function getManagerAccountEmail(policy: OnyxEntry<Policy>, expenseReport: OnyxEntry<Report>): string {
12591246
const managerAccountID = getManagerAccountID(policy, expenseReport);
12601247
return getLoginsByAccountIDs([managerAccountID]).at(0) ?? '';
@@ -2270,7 +2257,6 @@ export {
22702257
getDefaultChatEnabledPolicy,
22712258
getForwardsToAccount,
22722259
getSubmitToAccountID,
2273-
getSubmitReportManagerAccountID,
22742260
getAllTaxRatesNamesAndKeys as getAllTaxRates,
22752261
getAllTaxRatesNamesAndValues,
22762262
getTagNamesFromTagsLists,

src/libs/actions/IOU/ReportWorkflow.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {getMicroSecondOnyxErrorWithTranslationKey} from '@libs/ErrorUtils';
1616
import Navigation from '@libs/Navigation/Navigation';
1717
import {getIsOffline} from '@libs/NetworkState';
1818
import {buildNextStepNew, buildOptimisticNextStep} from '@libs/NextStepUtils';
19-
import {arePaymentsEnabled, getSubmitReportManagerAccountID, hasDynamicExternalWorkflow, isPaidGroupPolicy, isPolicyAdmin, isSubmitAndClose} from '@libs/PolicyUtils';
19+
import {arePaymentsEnabled, getSubmitToAccountID, hasDynamicExternalWorkflow, isPaidGroupPolicy, isPolicyAdmin, isSubmitAndClose} from '@libs/PolicyUtils';
2020
import {getAllReportActions, getReportActionHtml, getReportActionText, hasPendingDEWApprove, isCreatedAction, isDeletedAction} from '@libs/ReportActionsUtils';
2121
import {
2222
buildOptimisticApprovedReportAction,
@@ -1299,7 +1299,8 @@ function submitReport({
12991299
isASAPSubmitBetaEnabled,
13001300
isUnapprove: true,
13011301
});
1302-
const managerID = getSubmitReportManagerAccountID(policy, expenseReport);
1302+
const submitToAccountID = getSubmitToAccountID(policy, expenseReport);
1303+
const managerID = submitToAccountID > 0 ? submitToAccountID : expenseReport.managerID;
13031304

13041305
const optimisticData: Array<
13051306
OnyxUpdate<typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS | typeof ONYXKEYS.COLLECTION.REPORT | typeof ONYXKEYS.COLLECTION.NEXT_STEP | typeof ONYXKEYS.COLLECTION.REPORT_METADATA>

src/libs/actions/Search.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import type {SearchFullscreenNavigatorParamList} from '@libs/Navigation/types';
2929
import enhanceParameters from '@libs/Network/enhanceParameters';
3030
import {rand64} from '@libs/NumberUtils';
3131
import {getActivePaymentType} from '@libs/PaymentUtils';
32-
import {getSubmitReportManagerAccountID, getValidConnectedIntegration, isDelayedSubmissionEnabled} from '@libs/PolicyUtils';
32+
import {getSubmitToAccountID, getValidConnectedIntegration, isDelayedSubmissionEnabled} from '@libs/PolicyUtils';
3333
import type {OptimisticExportIntegrationAction} from '@libs/ReportUtils';
3434
import {
3535
buildOptimisticExportIntegrationAction,
@@ -661,7 +661,7 @@ function submitMoneyRequestOnSearch(hash: number, reportList: Report[], policy:
661661
const report = (reportList.at(0) ?? {}) as Report;
662662
const parameters: SubmitReportParams = {
663663
reportID: report.reportID,
664-
managerAccountID: getSubmitReportManagerAccountID(policy.at(0), report),
664+
managerAccountID: getSubmitToAccountID(policy.at(0), report) ?? report?.managerID,
665665
reportActionID: rand64(),
666666
};
667667

tests/actions/IOUTest/ReportWorkflowTest.ts

Lines changed: 0 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,141 +1185,6 @@ describe('actions/IOU/ReportWorkflow', () => {
11851185
expect(Navigation.navigate).not.toHaveBeenCalledWith(ROUTES.RESTRICTED_ACTION.getRoute(policyID));
11861186
}
11871187
});
1188-
1189-
it('preserves the existing report manager when cached policy data resolves to a different approver', async () => {
1190-
const apiWriteSpy = jest.spyOn(API, 'write').mockImplementation(() => Promise.resolve());
1191-
const policyID = '1';
1192-
const submitterAccountID = 100;
1193-
const correctManagerAccountID = 101;
1194-
const defaultApproverAccountID = 102;
1195-
const submitterEmail = 'submitter@example.com';
1196-
const correctManagerEmail = 'correct-manager@example.com';
1197-
const defaultApproverEmail = 'default-approver@example.com';
1198-
1199-
await Onyx.set(ONYXKEYS.PERSONAL_DETAILS_LIST, {
1200-
[submitterAccountID]: {accountID: submitterAccountID, login: submitterEmail},
1201-
[correctManagerAccountID]: {accountID: correctManagerAccountID, login: correctManagerEmail},
1202-
[defaultApproverAccountID]: {accountID: defaultApproverAccountID, login: defaultApproverEmail},
1203-
});
1204-
1205-
// Given cached policy data resolves to the default approver.
1206-
const policy: Policy = {
1207-
...createRandomPolicy(Number(policyID)),
1208-
id: policyID,
1209-
type: CONST.POLICY.TYPE.CORPORATE,
1210-
approvalMode: CONST.POLICY.APPROVAL_MODE.ADVANCED,
1211-
approver: defaultApproverEmail,
1212-
owner: defaultApproverEmail,
1213-
employeeList: {},
1214-
};
1215-
1216-
// And the report already has the correct manager.
1217-
const expenseReport: Report = {
1218-
...createRandomReport(Number(policyID), undefined),
1219-
reportID: '1',
1220-
policyID,
1221-
type: CONST.REPORT.TYPE.EXPENSE,
1222-
ownerAccountID: submitterAccountID,
1223-
managerID: correctManagerAccountID,
1224-
stateNum: CONST.REPORT.STATE_NUM.OPEN,
1225-
statusNum: CONST.REPORT.STATUS_NUM.OPEN,
1226-
total: 1000,
1227-
currency: CONST.CURRENCY.USD,
1228-
};
1229-
1230-
// When submitting the report.
1231-
submitReport({
1232-
expenseReport,
1233-
policy,
1234-
currentUserAccountIDParam: submitterAccountID,
1235-
currentUserEmailParam: submitterEmail,
1236-
hasViolations: false,
1237-
isASAPSubmitBetaEnabled: false,
1238-
expenseReportCurrentNextStepDeprecated: undefined,
1239-
userBillingGracePeriodEnds: undefined,
1240-
amountOwed: 0,
1241-
ownerBillingGracePeriodEnd: undefined,
1242-
delegateEmail: undefined,
1243-
});
1244-
1245-
// Then the API payload and optimistic report update preserve the existing manager.
1246-
const [, parameters, onyxData] = apiWriteSpy.mock.calls.at(0) as [unknown, {managerAccountID?: number}, OnyxData<typeof ONYXKEYS.COLLECTION.REPORT>];
1247-
expect(parameters.managerAccountID).toBe(correctManagerAccountID);
1248-
1249-
const optimisticReportUpdate = onyxData.optimisticData?.find((update) => update.key === `${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`);
1250-
expect((optimisticReportUpdate?.value as Report | undefined)?.managerID).toBe(correctManagerAccountID);
1251-
1252-
apiWriteSpy.mockRestore();
1253-
});
1254-
1255-
it('ignores the existing report manager when it points to the submitter', async () => {
1256-
// eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting API.write calls to verify submit payload and optimistic data.
1257-
const apiWriteSpy = jest.spyOn(API, 'write').mockImplementation(() => Promise.resolve());
1258-
const policyID = '1';
1259-
const submitterAccountID = 100;
1260-
const computedManagerAccountID = 101;
1261-
const submitterEmail = 'submitter@example.com';
1262-
const computedManagerEmail = 'computed-manager@example.com';
1263-
1264-
await Onyx.set(ONYXKEYS.PERSONAL_DETAILS_LIST, {
1265-
[submitterAccountID]: {accountID: submitterAccountID, login: submitterEmail},
1266-
[computedManagerAccountID]: {accountID: computedManagerAccountID, login: computedManagerEmail},
1267-
});
1268-
1269-
// Given cached policy data resolves to the configured approver.
1270-
const policy: Policy = {
1271-
...createRandomPolicy(Number(policyID)),
1272-
id: policyID,
1273-
type: CONST.POLICY.TYPE.CORPORATE,
1274-
approvalMode: CONST.POLICY.APPROVAL_MODE.ADVANCED,
1275-
approver: computedManagerEmail,
1276-
owner: computedManagerEmail,
1277-
employeeList: {
1278-
[submitterEmail]: {
1279-
email: submitterEmail,
1280-
submitsTo: computedManagerEmail,
1281-
},
1282-
},
1283-
};
1284-
1285-
// And the draft report manager is still the submitter.
1286-
const expenseReport: Report = {
1287-
...createRandomReport(Number(policyID), undefined),
1288-
reportID: '1',
1289-
policyID,
1290-
type: CONST.REPORT.TYPE.EXPENSE,
1291-
ownerAccountID: submitterAccountID,
1292-
managerID: submitterAccountID,
1293-
stateNum: CONST.REPORT.STATE_NUM.OPEN,
1294-
statusNum: CONST.REPORT.STATUS_NUM.OPEN,
1295-
total: 1000,
1296-
currency: CONST.CURRENCY.USD,
1297-
};
1298-
1299-
// When submitting the report.
1300-
submitReport({
1301-
expenseReport,
1302-
policy,
1303-
currentUserAccountIDParam: submitterAccountID,
1304-
currentUserEmailParam: submitterEmail,
1305-
hasViolations: false,
1306-
isASAPSubmitBetaEnabled: false,
1307-
expenseReportCurrentNextStepDeprecated: undefined,
1308-
userBillingGracePeriodEnds: undefined,
1309-
amountOwed: 0,
1310-
ownerBillingGracePeriodEnd: undefined,
1311-
delegateEmail: undefined,
1312-
});
1313-
1314-
// Then the API payload and optimistic report update use the configured approver instead of routing to the submitter.
1315-
const [, parameters, onyxData] = apiWriteSpy.mock.calls.at(0) as [unknown, {managerAccountID?: number}, OnyxData<typeof ONYXKEYS.COLLECTION.REPORT>];
1316-
expect(parameters.managerAccountID).toBe(computedManagerAccountID);
1317-
1318-
const optimisticReportUpdate = onyxData.optimisticData?.find((update) => update.key === `${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`);
1319-
expect((optimisticReportUpdate?.value as Report | undefined)?.managerID).toBe(computedManagerAccountID);
1320-
1321-
apiWriteSpy.mockRestore();
1322-
});
13231188
});
13241189

13251190
describe('delegateAccountID forwarding', () => {
@@ -1328,7 +1193,6 @@ describe('actions/IOU/ReportWorkflow', () => {
13281193

13291194
beforeEach(async () => {
13301195
jest.clearAllMocks();
1331-
// eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting API.write calls to verify optimistic data.
13321196
jest.spyOn(API, 'write');
13331197
await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, {
13341198
[DELEGATE_ACCOUNT_ID]: {

0 commit comments

Comments
 (0)