diff --git a/src/libs/API/parameters/SyncPolicyToNSQSParams.ts b/src/libs/API/parameters/SyncPolicyToNSQSParams.ts index 319ccb2f1d50..aa867403586d 100644 --- a/src/libs/API/parameters/SyncPolicyToNSQSParams.ts +++ b/src/libs/API/parameters/SyncPolicyToNSQSParams.ts @@ -1,5 +1,6 @@ type SyncPolicyToNSQSParams = { policyID: string; + netSuiteAccountID: string; idempotencyKey: string; }; diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 556522ae573e..dae199a34dd7 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -1004,6 +1004,10 @@ function getIntegrationLastSuccessfulDate(connection?: Connections[keyof Connect return syncSuccessfulDate; } +function getNSQSCompanyID(policy: Policy) { + return policy.connections?.netsuiteQuickStart?.config?.credentials?.companyID; +} + function getCurrentSageIntacctEntityName(policy: Policy | undefined, defaultNameIfNoEntity: string): string | undefined { const currentEntityID = policy?.connections?.intacct?.config?.entity; if (!currentEntityID) { @@ -1407,6 +1411,7 @@ export { getNetSuiteReceivableAccountOptions, getNetSuiteInvoiceItemOptions, getNetSuiteTaxAccountOptions, + getNSQSCompanyID, getSageIntacctVendors, getSageIntacctNonReimbursableActiveDefaultVendor, getSageIntacctCreditCards, diff --git a/src/libs/actions/connections/index.ts b/src/libs/actions/connections/index.ts index 0008b22cd380..f15f0d6996d0 100644 --- a/src/libs/actions/connections/index.ts +++ b/src/libs/actions/connections/index.ts @@ -5,6 +5,7 @@ import Onyx from 'react-native-onyx'; import * as API from '@libs/API'; import type { RemovePolicyConnectionParams, + SyncPolicyToNSQSParams, SyncPolicyToQuickbooksDesktopParams, UpdateManyPolicyConnectionConfigurationsParams, UpdatePolicyConnectionConfigParams, @@ -12,6 +13,7 @@ import type { import {READ_COMMANDS, WRITE_COMMANDS} from '@libs/API/types'; import * as ErrorUtils from '@libs/ErrorUtils'; import * as PolicyUtils from '@libs/PolicyUtils'; +import {getNSQSCompanyID} from '@libs/PolicyUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type * as OnyxCommon from '@src/types/onyx/OnyxCommon'; @@ -222,14 +224,15 @@ function getSyncConnectionParameters(connectionName: PolicyConnectionName) { /** * This method helps in syncing policy to the connected accounting integration. * - * @param policyID - ID of the policy for which the sync is needed + * @param policy - Policy for which the sync is needed * @param connectionName - Name of the connection, QBO/Xero * @param forceDataRefresh - If true, it will trigger a full data refresh */ -function syncConnection(policyID: string, connectionName: PolicyConnectionName | undefined, forceDataRefresh = false) { - if (!connectionName) { +function syncConnection(policy: Policy | undefined, connectionName: PolicyConnectionName | undefined, forceDataRefresh = false) { + if (!connectionName || !policy) { return; } + const policyID = policy.id; const syncConnectionData = getSyncConnectionParameters(connectionName); if (!syncConnectionData) { @@ -255,7 +258,7 @@ function syncConnection(policyID: string, connectionName: PolicyConnectionName | }, ]; - const parameters: SyncPolicyToQuickbooksDesktopParams = { + const parameters: SyncPolicyToQuickbooksDesktopParams | SyncPolicyToNSQSParams = { policyID, idempotencyKey: policyID, }; @@ -263,6 +266,9 @@ function syncConnection(policyID: string, connectionName: PolicyConnectionName | if (connectionName === CONST.POLICY.CONNECTIONS.NAME.QBD) { parameters.forceDataRefresh = forceDataRefresh; } + if (connectionName === CONST.POLICY.CONNECTIONS.NAME.NSQS) { + (parameters as SyncPolicyToNSQSParams).netSuiteAccountID = getNSQSCompanyID(policy) ?? ''; + } API.read(syncConnectionData.readCommand, parameters, { optimisticData, diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index e20239e96ac3..dae6d7b20432 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -147,7 +147,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { { icon: Expensicons.Sync, text: translate('workspace.accounting.syncNow'), - onSelected: () => syncConnection(policyID, connectedIntegration), + onSelected: () => syncConnection(policy, connectedIntegration), disabled: isOffline, }, ]), @@ -158,7 +158,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { shouldCallAfterModalHide: true, }, ], - [shouldShowEnterCredentials, shouldShowReinstallConnectorMenuItem, translate, isOffline, policyID, connectedIntegration, startIntegrationFlow], + [shouldShowEnterCredentials, shouldShowReinstallConnectorMenuItem, translate, isOffline, policy, connectedIntegration, startIntegrationFlow], ); useFocusEffect( diff --git a/src/pages/workspace/accounting/qbd/QuickBooksDesktopSetupFlowSyncPage.tsx b/src/pages/workspace/accounting/qbd/QuickBooksDesktopSetupFlowSyncPage.tsx index 5dbd6c3cb01a..8110f9bf3292 100644 --- a/src/pages/workspace/accounting/qbd/QuickBooksDesktopSetupFlowSyncPage.tsx +++ b/src/pages/workspace/accounting/qbd/QuickBooksDesktopSetupFlowSyncPage.tsx @@ -23,7 +23,7 @@ function QuickBooksDesktopSetupFlowSyncPage({route}: QuickBooksDesktopSetupFlowS const isSyncInProgress = isConnectionInProgress(connectionSyncProgress, policy); if (!isSyncInProgress) { - syncConnection(policyID, CONST.POLICY.CONNECTIONS.NAME.QBD, true); + syncConnection(policy, CONST.POLICY.CONNECTIONS.NAME.QBD, true); } Navigation.navigate(ROUTES.WORKSPACE_ACCOUNTING.getRoute(policyID));