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
4 changes: 2 additions & 2 deletions src/hooks/useExportActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,14 @@ function useExportActions({reportID, policy, onPDFModalOpen}: UseExportActionsPa
value: CONST.REPORT.EXPORT_OPTIONS.MARK_AS_EXPORTED,
sentryLabel: CONST.SENTRY_LABEL.MORE_MENU.EXPORT_FILE,
onSelected: () => {
if (!connectedIntegration || !moneyRequestReport) {
if (!connectedIntegrationFallback || !moneyRequestReport) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use the fallback integration for re-marking exports

When the connected accounting integration is unverified, this new fallback guard lets the Mark as exported option appear, but already-exported reports still take the isExported branch and call triggerExportOrConfirm. That hook still derives connectedIntegration via getValidConnectedIntegration and returns immediately when it is undefined, so for the newly supported invalid-QBO case selecting Mark as exported on an already-exported report silently does nothing instead of showing the confirmation/re-marking it.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

return;
}
if (isExported) {
triggerExportOrConfirm(CONST.REPORT.EXPORT_OPTIONS.MARK_AS_EXPORTED);
return;
}
markAsManuallyExported([moneyRequestReport.reportID ?? CONST.DEFAULT_NUMBER_ID], connectedIntegration);
markAsManuallyExported([moneyRequestReport.reportID ?? CONST.DEFAULT_NUMBER_ID], connectedIntegrationFallback);
},
},
};
Expand Down
12 changes: 7 additions & 5 deletions src/hooks/useExportAgainModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,28 @@ function useExportAgainModal(reportID: string | undefined, policyID: string | un
const reportName = report?.reportName ?? '';

const triggerExportOrConfirm = (exportType: ExportType) => {
if (!connectedIntegration) {
const integrationForExport = exportType === CONST.REPORT.EXPORT_OPTIONS.MARK_AS_EXPORTED ? connectedIntegrationFallback : connectedIntegration;

if (!integrationForExport) {
return;
}

showConfirmModal({
title: translate('workspace.exportAgainModal.title'),
prompt: translate('workspace.exportAgainModal.description', {
connectionName: connectedIntegration ?? connectedIntegrationFallback,
connectionName: integrationForExport,
reportName,
}),
confirmText: translate('workspace.exportAgainModal.confirmText'),
cancelText: translate('workspace.exportAgainModal.cancelText'),
}).then((result) => {
if (result.action !== ModalActions.CONFIRM || !reportID || !connectedIntegration) {
if (result.action !== ModalActions.CONFIRM || !reportID) {
return;
}
if (exportType === CONST.REPORT.EXPORT_OPTIONS.EXPORT_TO_INTEGRATION) {
exportToIntegration(reportID, connectedIntegration);
exportToIntegration(reportID, integrationForExport);
} else if (exportType === CONST.REPORT.EXPORT_OPTIONS.MARK_AS_EXPORTED) {
markAsManuallyExported([reportID], connectedIntegration);
markAsManuallyExported([reportID], integrationForExport);
}
});
};
Expand Down
20 changes: 8 additions & 12 deletions src/libs/ReportSecondaryActionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,8 @@ function isMarkAsExportedAction(currentAccountID: number, currentUserLogin: stri
return false;
}

const hasAccountingConnection = !!getValidConnectedIntegration(policy);
if (!hasAccountingConnection) {
const connectedIntegration = getConnectedIntegration(policy);
if (!connectedIntegration) {
return false;
}

Expand All @@ -545,26 +545,22 @@ function isMarkAsExportedAction(currentAccountID: number, currentUserLogin: stri
const arePaymentsEnabled = arePaymentsEnabledUtils(policy);
const isReportApproved = isReportApprovedUtils({report});
const isReportClosed = isClosedReportUtils(report);
const isReportClosedOrApproved = isReportClosed || isReportApproved;

if (isReportPayer && arePaymentsEnabled && isReportClosedOrApproved) {
return true;
}

const isReportReimbursed = isSettled(report);
const connectedIntegration = getConnectedIntegration(policy);
const syncEnabled = hasIntegrationAutoSync(policy, connectedIntegration);
const isReportFinished = isReportClosedOrApproved || isReportReimbursed;
const isReportFinished = isReportClosed || isReportApproved || isReportReimbursed;

if (!isReportFinished) {
return false;
}

if (isReportPayer && arePaymentsEnabled) {
return true;
}

const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN;

const isExporter = isPreferredExporter(policy, currentUserLogin);

return (isAdmin && syncEnabled) || (isExporter && !syncEnabled);
return isAdmin || isExporter;
}

function isHoldAction(
Expand Down
125 changes: 125 additions & 0 deletions tests/unit/ReportSecondaryActionUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
isMergeActionForSelectedTransactions,
} from '@libs/ReportSecondaryActionUtils';
import CONST from '@src/CONST';
import {getValidConnectedIntegration, isPreferredExporter} from '@src/libs/PolicyUtils';
import * as ReportActionsUtils from '@src/libs/ReportActionsUtils';
import * as ReportUtils from '@src/libs/ReportUtils';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -39,6 +40,59 @@ const POLICY_ID = 'POLICY_ID';
const OLD_POLICY_ID = 'OLD_POLICY_ID';
const ORIGINAL_TRANSACTION_ID = 'ORIGINAL_TRANSACTION_ID';
const SPLIT_TRANSACTION_ID = 'SPLIT_TRANSACTION_ID';
type QBOConfig = NonNullable<Policy['connections']>[typeof CONST.POLICY.CONNECTIONS.NAME.QBO]['config'];

const createQBOConfig = (autoSyncEnabled: boolean, exporter = EMPLOYEE_EMAIL): QBOConfig => ({
realmId: 'realm-id',
companyName: 'QBO Company',
autoSync: {
jobID: '',
enabled: autoSyncEnabled,
},
syncPeople: false,
syncItems: false,
markChecksToBePrinted: false,
reimbursableExpensesExportDestination: CONST.QUICKBOOKS_REIMBURSABLE_ACCOUNT_TYPE.VENDOR_BILL,
nonReimbursableExpensesExportDestination: CONST.QUICKBOOKS_NON_REIMBURSABLE_EXPORT_ACCOUNT_TYPE.CREDIT_CARD,
nonReimbursableBillDefaultVendor: '',
autoCreateVendor: false,
hasChosenAutoSyncOption: true,
syncClasses: CONST.INTEGRATION_ENTITY_MAP_TYPES.DEFAULT,
syncCustomers: CONST.INTEGRATION_ENTITY_MAP_TYPES.DEFAULT,
syncLocations: CONST.INTEGRATION_ENTITY_MAP_TYPES.DEFAULT,
lastConfigurationTime: 0,
syncTax: false,
enableNewCategories: false,
exportDate: CONST.QUICKBOOKS_EXPORT_DATE.REPORT_EXPORTED,
export: {
exporter,
},
credentials: {
companyID: 'company-id',
companyName: 'QBO Company',
scope: '',
},
});

const createQBOConnections = (autoSyncEnabled: boolean, exporter = EMPLOYEE_EMAIL) =>
// The test only needs the QBO connection branch, while Policy['connections'] is typed as the full integration map.
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
({
[CONST.POLICY.CONNECTIONS.NAME.QBO]: {
config: createQBOConfig(autoSyncEnabled, exporter),
},
}) as NonNullable<Policy['connections']>;

const createQBOPolicy = (role: Policy['role'], autoSyncEnabled: boolean, exporter = EMPLOYEE_EMAIL): Policy => ({
id: POLICY_ID,
name: 'QBO Policy',
role,
type: CONST.POLICY.TYPE.TEAM,
owner: ADMIN_EMAIL,
outputCurrency: CONST.CURRENCY.USD,
isPolicyExpenseChatEnabled: true,
connections: createQBOConnections(autoSyncEnabled, exporter),
});

jest.mock('@libs/PolicyUtils', () => ({
...jest.requireActual<typeof PolicyUtils>('@libs/PolicyUtils'),
Expand All @@ -65,6 +119,9 @@ describe('getSecondaryAction', () => {

beforeEach(async () => {
jest.clearAllMocks();
jest.mocked(getValidConnectedIntegration).mockReturnValue('netsuite');
jest.mocked(jest.requireMock<typeof PolicyUtils>('@libs/PolicyUtils').isPaidGroupPolicy).mockReturnValue(true);
jest.mocked(isPreferredExporter).mockReturnValue(true);
Onyx.clear();
});

Expand Down Expand Up @@ -3440,6 +3497,20 @@ describe('getSecondaryExportReportActions', () => {
expect(result.includes(CONST.REPORT.EXPORT_OPTIONS.MARK_AS_EXPORTED)).toBe(true);
});

it('includes MARK_AS_EXPORTED option for expense report preferred exporter when auto-sync is enabled', () => {
const report: Report = {
reportID: `${REPORT_ID}`,
type: CONST.REPORT.TYPE.EXPENSE,
ownerAccountID: EMPLOYEE_ACCOUNT_ID,
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
statusNum: CONST.REPORT.STATUS_NUM.APPROVED,
};
const policy = createQBOPolicy(CONST.POLICY.ROLE.USER, true);

const result = getSecondaryExportReportActions(SESSION.accountID, SESSION.email, report, {}, policy);
expect(result.includes(CONST.REPORT.EXPORT_OPTIONS.MARK_AS_EXPORTED)).toBe(true);
});

it('includes MARK_AS_EXPORTED option for expense report admin', () => {
const report = {
reportID: REPORT_ID,
Expand All @@ -3457,6 +3528,60 @@ describe('getSecondaryExportReportActions', () => {
expect(result.includes(CONST.REPORT.EXPORT_OPTIONS.MARK_AS_EXPORTED)).toBe(true);
});

it('includes MARK_AS_EXPORTED option for expense report admin when auto-sync is disabled and live export connection is invalid', () => {
jest.mocked(getValidConnectedIntegration).mockReturnValue(undefined);
jest.mocked(isPreferredExporter).mockReturnValue(false);

const report: Report = {
reportID: `${REPORT_ID}`,
type: CONST.REPORT.TYPE.EXPENSE,
ownerAccountID: EMPLOYEE_ACCOUNT_ID,
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
statusNum: CONST.REPORT.STATUS_NUM.APPROVED,
};
const policy = createQBOPolicy(CONST.POLICY.ROLE.ADMIN, false);

const result = getSecondaryExportReportActions(SESSION.accountID, SESSION.email, report, {}, policy);
expect(result.includes(CONST.REPORT.EXPORT_OPTIONS.EXPORT_TO_INTEGRATION)).toBe(false);
expect(result.includes(CONST.REPORT.EXPORT_OPTIONS.MARK_AS_EXPORTED)).toBe(true);
});

it('includes MARK_AS_EXPORTED option for reimbursed expense report payer', () => {
jest.mocked(jest.requireMock<typeof PolicyUtils>('@libs/PolicyUtils').isPaidGroupPolicy).mockReturnValue(false);
jest.mocked(isPreferredExporter).mockReturnValue(false);

const report: Report = {
reportID: `${REPORT_ID}`,
type: CONST.REPORT.TYPE.EXPENSE,
ownerAccountID: EMPLOYEE_ACCOUNT_ID,
managerID: EMPLOYEE_ACCOUNT_ID,
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
statusNum: CONST.REPORT.STATUS_NUM.REIMBURSED,
};
const policy = createQBOPolicy(CONST.POLICY.ROLE.USER, false);

const result = getSecondaryExportReportActions(SESSION.accountID, SESSION.email, report, {}, policy);
expect(result.includes(CONST.REPORT.EXPORT_OPTIONS.MARK_AS_EXPORTED)).toBe(true);
});

it('does not include MARK_AS_EXPORTED option for expense report non-admin who is not preferred exporter or payer', () => {
jest.mocked(jest.requireMock<typeof PolicyUtils>('@libs/PolicyUtils').isPaidGroupPolicy).mockReturnValue(false);
jest.mocked(isPreferredExporter).mockReturnValue(false);

const report: Report = {
reportID: `${REPORT_ID}`,
type: CONST.REPORT.TYPE.EXPENSE,
ownerAccountID: EMPLOYEE_ACCOUNT_ID,
managerID: MANAGER_ACCOUNT_ID,
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
statusNum: CONST.REPORT.STATUS_NUM.APPROVED,
};
const policy = createQBOPolicy(CONST.POLICY.ROLE.USER, false);

const result = getSecondaryExportReportActions(SESSION.accountID, SESSION.email, report, {}, policy);
expect(result.includes(CONST.REPORT.EXPORT_OPTIONS.MARK_AS_EXPORTED)).toBe(false);
});

it('includes REMOVE HOLD option for admin if he is not the holder', () => {
const report = {} as unknown as Report;
const policy = {
Expand Down
Loading