diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 709c10d07f6c..a867a8b99cda 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -22,6 +22,7 @@ import type { NetSuiteCustomSegment, NetSuiteTaxAccount, NetSuiteVendor, + PolicyConnectionSyncProgress, PolicyFeatureName, Rate, Tenant, @@ -751,14 +752,26 @@ function isNetSuiteCustomFieldPropertyEditable(customField: NetSuiteCustomList | return fieldsAllowedToEdit.includes(fieldKey); } -function getIntegrationLastSuccessfulDate(connection?: Connections[keyof Connections]) { +function getIntegrationLastSuccessfulDate(connection?: Connections[keyof Connections], connectionSyncProgress?: PolicyConnectionSyncProgress) { + let syncSuccessfulDate; if (!connection) { return undefined; } if ((connection as NetSuiteConnection)?.lastSyncDate) { - return (connection as NetSuiteConnection)?.lastSyncDate; + syncSuccessfulDate = (connection as NetSuiteConnection)?.lastSyncDate; + } else { + syncSuccessfulDate = (connection as ConnectionWithLastSyncData)?.lastSync?.successfulDate; } - return (connection as ConnectionWithLastSyncData)?.lastSync?.successfulDate; + + if ( + connectionSyncProgress && + connectionSyncProgress.stageInProgress === CONST.POLICY.CONNECTIONS.SYNC_STAGE_NAME.JOB_DONE && + syncSuccessfulDate && + connectionSyncProgress.timestamp > syncSuccessfulDate + ) { + syncSuccessfulDate = connectionSyncProgress.timestamp; + } + return syncSuccessfulDate; } function getCurrentSageIntacctEntityName(policy: Policy | undefined, defaultNameIfNoEntity: string): string | undefined { diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index 9202591de7f2..80a2e4c73c70 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -225,7 +225,11 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { const connectedIntegration = getConnectedIntegration(policy, accountingIntegrations) ?? connectionSyncProgress?.connectionName; const policyID = policy?.id ?? '-1'; - const successfulDate = getIntegrationLastSuccessfulDate(connectedIntegration ? policy?.connections?.[connectedIntegration] : undefined); + // Get the last successful date of the integration. Then, if `connectionSyncProgress` is the same integration displayed and the state is 'jobDone', get the more recent update time of the two. + const successfulDate = getIntegrationLastSuccessfulDate( + connectedIntegration ? policy?.connections?.[connectedIntegration] : undefined, + connectedIntegration === connectionSyncProgress?.connectionName ? connectionSyncProgress : undefined, + ); const tenants = useMemo(() => getXeroTenants(policy), [policy]); const currentXeroOrganization = findCurrentXeroOrganization(tenants, policy?.connections?.xero?.config?.tenantID);