Skip to content

[CP Staging] Align primary/search action logic #62237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 19, 2025
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
2 changes: 1 addition & 1 deletion src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ function isInstantSubmitEnabled(policy: OnyxInputOrEntry<Policy> | SearchPolicy)
*
* Note that "daily" and "manual" only exist as options for the API, not in the database or Onyx.
*/
function getCorrectedAutoReportingFrequency(policy: OnyxInputOrEntry<Policy>): ValueOf<typeof CONST.POLICY.AUTO_REPORTING_FREQUENCIES> | undefined {
function getCorrectedAutoReportingFrequency(policy: OnyxInputOrEntry<Policy> | SearchPolicy): ValueOf<typeof CONST.POLICY.AUTO_REPORTING_FREQUENCIES> | undefined {
if (policy?.autoReportingFrequency !== CONST.POLICY.AUTO_REPORTING_FREQUENCIES.IMMEDIATE) {
return policy?.autoReportingFrequency;
}
Expand Down
3 changes: 3 additions & 0 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import Permissions from '@libs/Permissions';
import {getAccountIDsByLogins} from '@libs/PersonalDetailsUtils';
import {addSMSDomainIfPhoneNumber} from '@libs/PhoneNumber';
import {
getCorrectedAutoReportingFrequency,
getMemberAccountIDsForWorkspace,
getPerDiemCustomUnit,
getPersonalPolicy,
Expand Down Expand Up @@ -8932,6 +8933,7 @@ function canSubmitReport(
const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN;
const transactionIDList = transactions.map((transaction) => transaction.transactionID);
const hasAllPendingRTERViolations = allHavePendingRTERViolation(transactionIDList, allViolations);
const isManualSubmitEnabled = getCorrectedAutoReportingFrequency(policy) === CONST.POLICY.AUTO_REPORTING_FREQUENCIES.MANUAL;
const hasTransactionWithoutRTERViolation = hasAnyTransactionWithoutRTERViolation(transactionIDList, allViolations);
const hasOnlyPendingCardOrScanFailTransactions =
transactions.length > 0 &&
Expand All @@ -8940,6 +8942,7 @@ function canSubmitReport(
return (
transactions.length > 0 &&
isOpenExpenseReport &&
isManualSubmitEnabled &&
!isReportArchived &&
!hasOnlyPendingCardOrScanFailTransactions &&
!hasAllPendingRTERViolations &&
Expand Down
6 changes: 6 additions & 0 deletions src/types/onyx/SearchResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ type SearchPolicy = {
/** Whether the rules feature is enabled */
areRulesEnabled?: boolean;

/** Scheduled submit data */
harvesting?: {
/** Whether the scheduled submit is enabled */
enabled: boolean;
};

/**
* The scheduled submit frequency set up on this policy.
* Note that manual does not exist in the DB and thus should not exist in Onyx, only as a param for the API.
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/IOUUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ describe('canSubmitReport', () => {
ownerAccountID: currentUserAccountID,
areRulesEnabled: true,
preventSelfApproval: false,
autoReportingFrequency: 'immediate',
harvesting: {
enabled: false,
},
};
const expenseReport: Report = {
...createRandomReport(6),
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/Search/SearchUIUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ const searchResults: OnyxTypes.SearchResults = {
},
autoReimbursementLimit: 0,
autoReporting: true,
autoReportingFrequency: 'instant',
autoReportingFrequency: 'immediate',
harvesting: {
enabled: false,
},
preventSelfApproval: false,
owner: adminEmail,
reimbursementChoice: 'reimburseManual',
Expand Down