From be2aaafb677c3a6bc61cc58996b884bc9b31eea9 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Fri, 16 May 2025 12:51:49 -0600 Subject: [PATCH 1/4] align primary/search action logic --- src/libs/PolicyUtils.ts | 2 +- src/libs/actions/IOU.ts | 3 +++ src/types/onyx/SearchResults.ts | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 1df263dbef67..dafd37acbb5b 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -485,7 +485,7 @@ function isInstantSubmitEnabled(policy: OnyxInputOrEntry | SearchPolicy) * * Note that "daily" and "manual" only exist as options for the API, not in the database or Onyx. */ -function getCorrectedAutoReportingFrequency(policy: OnyxInputOrEntry): ValueOf | undefined { +function getCorrectedAutoReportingFrequency(policy: OnyxInputOrEntry | SearchPolicy): ValueOf | undefined { if (policy?.autoReportingFrequency !== CONST.POLICY.AUTO_REPORTING_FREQUENCIES.IMMEDIATE) { return policy?.autoReportingFrequency; } diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 245db884a0d1..791073726137 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -73,6 +73,7 @@ import { isPaidGroupPolicy, isPolicyAdmin, isSubmitAndClose, + getCorrectedAutoReportingFrequency, } from '@libs/PolicyUtils'; import { getAllReportActions, @@ -8925,6 +8926,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 && @@ -8933,6 +8935,7 @@ function canSubmitReport( return ( transactions.length > 0 && isOpenExpenseReport && + isManualSubmitEnabled && !isReportArchived && !hasOnlyPendingCardOrScanFailTransactions && !hasAllPendingRTERViolations && diff --git a/src/types/onyx/SearchResults.ts b/src/types/onyx/SearchResults.ts index e9d4ff5d6432..c0b12697c32a 100644 --- a/src/types/onyx/SearchResults.ts +++ b/src/types/onyx/SearchResults.ts @@ -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. From bdca34eed345ac4685a3fefa00373375440d80ff Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 19 May 2025 08:28:46 -0600 Subject: [PATCH 2/4] fix lint, tests --- src/libs/actions/IOU.ts | 2 +- tests/unit/Search/SearchUIUtilsTest.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index ee76177defb8..85184ed903ea 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -63,6 +63,7 @@ import Permissions from '@libs/Permissions'; import {getAccountIDsByLogins} from '@libs/PersonalDetailsUtils'; import {addSMSDomainIfPhoneNumber} from '@libs/PhoneNumber'; import { + getCorrectedAutoReportingFrequency, getMemberAccountIDsForWorkspace, getPerDiemCustomUnit, getPersonalPolicy, @@ -73,7 +74,6 @@ import { isPaidGroupPolicy, isPolicyAdmin, isSubmitAndClose, - getCorrectedAutoReportingFrequency, } from '@libs/PolicyUtils'; import { getAllReportActions, diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts index 45eb8e0c5682..04a0d140372f 100644 --- a/tests/unit/Search/SearchUIUtilsTest.ts +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -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', From e1df528c4d79232eefa8a155c72bf7baa530e8ed Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 19 May 2025 08:35:47 -0600 Subject: [PATCH 3/4] fix test --- tests/unit/IOUUtilsTest.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/unit/IOUUtilsTest.ts b/tests/unit/IOUUtilsTest.ts index 8960a92340e9..b70cb5f06f7a 100644 --- a/tests/unit/IOUUtilsTest.ts +++ b/tests/unit/IOUUtilsTest.ts @@ -264,6 +264,10 @@ describe('canSubmitReport', () => { ownerAccountID: currentUserAccountID, areRulesEnabled: true, preventSelfApproval: false, + autoReportingFrequency: 'immediate', + harvesting: { + enabled: false, + } }; const expenseReport: Report = { ...createRandomReport(6), From 7b2021c4bc83fa3c97d0ec4015e187a3ef0f8716 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 19 May 2025 08:44:13 -0600 Subject: [PATCH 4/4] fix lint --- tests/unit/IOUUtilsTest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/IOUUtilsTest.ts b/tests/unit/IOUUtilsTest.ts index b70cb5f06f7a..057d34f3673a 100644 --- a/tests/unit/IOUUtilsTest.ts +++ b/tests/unit/IOUUtilsTest.ts @@ -267,7 +267,7 @@ describe('canSubmitReport', () => { autoReportingFrequency: 'immediate', harvesting: { enabled: false, - } + }, }; const expenseReport: Report = { ...createRandomReport(6),