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
63 changes: 57 additions & 6 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import {shouldShowQBOReimbursableExportDestinationAccountError} from './actions/connections/QuickbooksOnline';
import {getCategoryApproverRule} from './CategoryUtils';
import {convertToBackendAmount} from './CurrencyUtils';
import Log from './Log';
import Navigation from './Navigation/Navigation';
import {isOffline as isOfflineNetworkStore} from './Network/NetworkStore';
import {formatMemberForList} from './OptionsListUtils';
Expand All @@ -72,7 +73,7 @@

let allPolicies: OnyxCollection<Policy>;

Onyx.connect({

Check warning on line 76 in src/libs/PolicyUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => (allPolicies = value),
Expand Down Expand Up @@ -1012,18 +1013,51 @@
const employeeAccountID = expenseReport?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID;
const employeeLogin = getLoginsByAccountIDs([employeeAccountID]).at(0) ?? '';
const defaultApprover = getDefaultApprover(policy);
const approvalWorkflow = getApprovalWorkflow(policy);

// For policy using the optional or basic workflow, the manager is the policy default approver.
if (([CONST.POLICY.APPROVAL_MODE.OPTIONAL, CONST.POLICY.APPROVAL_MODE.BASIC] as Array<ValueOf<typeof CONST.POLICY.APPROVAL_MODE>>).includes(getApprovalWorkflow(policy))) {
return getAccountIDsByLogins([defaultApprover]).at(0) ?? -1;
if (([CONST.POLICY.APPROVAL_MODE.OPTIONAL, CONST.POLICY.APPROVAL_MODE.BASIC] as Array<ValueOf<typeof CONST.POLICY.APPROVAL_MODE>>).includes(approvalWorkflow)) {
const managerAccountID = getAccountIDsByLogins([defaultApprover]).at(0) ?? -1;
Log.info('[getManagerAccountID] Using default approver for non-advanced workflow', false, {
policyID: policy?.id,
approvalWorkflow,
employeeAccountID,
employeeLogin,
defaultApprover,
policyApprover: policy?.approver,
policyOwner: policy?.owner,
managerAccountID,
});
return managerAccountID;
}

const employee = policy?.employeeList?.[employeeLogin];
if (!employee && !defaultApprover) {
Log.info('[getManagerAccountID] No employee found and no default approver', false, {
policyID: policy?.id,
employeeAccountID,
employeeLogin,
employeeListKeys: Object.keys(policy?.employeeList ?? {}),
hasPolicy: !!policy,
});
return -1;
}

return getAccountIDsByLogins([employee?.submitsTo ?? defaultApprover]).at(0) ?? -1;
const submitsTo = employee?.submitsTo ?? defaultApprover;
const managerAccountID = getAccountIDsByLogins([submitsTo]).at(0) ?? -1;
Log.info('[getManagerAccountID] Resolved manager for advanced workflow', false, {
policyID: policy?.id,
employeeAccountID,
employeeLogin,
employeeFound: !!employee,
employeeSubmitsTo: employee?.submitsTo,
defaultApprover,
policyApprover: policy?.approver,
policyOwner: policy?.owner,
resolvedSubmitsTo: submitsTo,
managerAccountID,
});
return managerAccountID;
}

/**
Expand All @@ -1037,9 +1071,26 @@
ruleApprovers.shift();
}
if (ruleApprovers.length > 0 && !isSubmitAndClose(policy)) {
return getAccountIDsByLogins([ruleApprovers.at(0) ?? '']).at(0) ?? -1;
}

const ruleApproverAccountID = getAccountIDsByLogins([ruleApprovers.at(0) ?? '']).at(0) ?? -1;
Log.info('[getSubmitToAccountID] Using rule approver', false, {
policyID: policy?.id,
reportID: expenseReport?.reportID,
employeeLogin,
ruleApprovers,
selectedRuleApprover: ruleApprovers.at(0),
ruleApproverAccountID,
});
return ruleApproverAccountID;
}

Log.info('[getSubmitToAccountID] No rule approvers, falling through to getManagerAccountID', false, {
policyID: policy?.id,
reportID: expenseReport?.reportID,
employeeLogin,
ruleApproversCount: ruleApprovers.length,
isSubmitAndClosePolicy: isSubmitAndClose(policy),
reportManagerID: expenseReport?.managerID,
});
return getManagerAccountID(policy, expenseReport);
}

Expand Down
18 changes: 17 additions & 1 deletion src/libs/actions/IOU/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@
};

let allPersonalDetails: OnyxTypes.PersonalDetailsList = {};
Onyx.connect({

Check warning on line 794 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value ?? {};
Expand Down Expand Up @@ -885,7 +885,7 @@
};

let allTransactions: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 888 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -899,7 +899,7 @@
});

let allTransactionDrafts: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 902 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_DRAFT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -908,7 +908,7 @@
});

let allTransactionViolations: NonNullable<OnyxCollection<OnyxTypes.TransactionViolations>> = {};
Onyx.connect({

Check warning on line 911 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -922,7 +922,7 @@
});

let allPolicyTags: OnyxCollection<OnyxTypes.PolicyTagLists> = {};
Onyx.connect({

Check warning on line 925 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_TAGS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -935,7 +935,7 @@
});

let allReports: OnyxCollection<OnyxTypes.Report>;
Onyx.connect({

Check warning on line 938 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -944,7 +944,7 @@
});

let allReportNameValuePairs: OnyxCollection<OnyxTypes.ReportNameValuePairs>;
Onyx.connect({

Check warning on line 947 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -954,7 +954,7 @@

let userAccountID = -1;
let currentUserEmail = '';
Onyx.connect({

Check warning on line 957 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
currentUserEmail = value?.email ?? '';
Expand All @@ -963,7 +963,7 @@
});

let deprecatedCurrentUserPersonalDetails: OnyxEntry<OnyxTypes.PersonalDetails>;
Onyx.connect({

Check warning on line 966 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
deprecatedCurrentUserPersonalDetails = value?.[userAccountID] ?? undefined;
Expand Down Expand Up @@ -11107,9 +11107,25 @@
});
}

const submitToAccountID = getSubmitToAccountID(policy, expenseReport);
const managerAccountIDParam = submitToAccountID ?? expenseReport.managerID;
Log.info('[submitReport] Submitting report with approval chain diagnostic', false, {
reportID: expenseReport.reportID,
policyID: expenseReport.policyID,
reportOwnerAccountID: expenseReport.ownerAccountID,
reportExistingManagerID: expenseReport.managerID,
getSubmitToAccountIDResult: submitToAccountID,
managerAccountIDSentToAPI: managerAccountIDParam,
optimisticManagerID: managerID,
approvalChainFromGetApprovalChain: approvalChain,
policyApprovalMode: policy?.approvalMode,
policyOwner: policy?.owner,
policyApprover: policy?.approver,
isDEWPolicy,
});
const parameters: SubmitReportParams = {
reportID: expenseReport.reportID,
managerAccountID: getSubmitToAccountID(policy, expenseReport) ?? expenseReport.managerID,
managerAccountID: managerAccountIDParam,
reportActionID: optimisticSubmittedReportAction.reportActionID,
};

Expand Down
18 changes: 17 additions & 1 deletion src/libs/actions/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {getCommandURL} from '@libs/ApiUtils';
import {convertToDisplayString} from '@libs/CurrencyUtils';
import {getMicroSecondOnyxErrorWithTranslationKey} from '@libs/ErrorUtils';
import fileDownload from '@libs/fileDownload';
import Log from '@libs/Log';
import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute';
import Navigation, {navigationRef} from '@libs/Navigation/Navigation';
import type {SearchFullscreenNavigatorParamList} from '@libs/Navigation/types';
Expand Down Expand Up @@ -559,9 +560,24 @@ function submitMoneyRequestOnSearch(hash: number, reportList: Report[], policy:
];

const report = (reportList.at(0) ?? {}) as Report;
const policyForReport = policy.at(0);
const submitToAccountID = getSubmitToAccountID(policyForReport, report);
const managerAccountIDParam = submitToAccountID ?? report?.managerID;
Log.info('[submitMoneyRequestOnSearch] Submitting report with approval chain diagnostic', false, {
reportID: report.reportID,
reportOwnerAccountID: report.ownerAccountID,
reportExistingManagerID: report.managerID,
getSubmitToAccountIDResult: submitToAccountID,
managerAccountIDSentToAPI: managerAccountIDParam,
hasPolicyData: !!policyForReport,
policyID: policyForReport?.id,
policyApprovalMode: policyForReport?.approvalMode,
policyOwner: policyForReport?.owner,
policyApprover: policyForReport?.approver,
});
const parameters: SubmitReportParams = {
reportID: report.reportID,
managerAccountID: getSubmitToAccountID(policy.at(0), report) ?? report?.managerID,
managerAccountID: managerAccountIDParam,
reportActionID: rand64(),
};

Expand Down
Loading