Skip to content

Commit 58dad9e

Browse files
luacmartinsOSBotify
authored andcommitted
Merge pull request #61704 from Expensify/cmartins-updateExportLogic
[CP Staging] Update export logic (cherry picked from commit 2fdd9e4) (cherry-picked to staging by luacmartins)
1 parent 3873d28 commit 58dad9e

3 files changed

Lines changed: 37 additions & 17 deletions

File tree

src/libs/ReportActionsUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,11 @@ function getOriginalMessage<T extends ReportActionName>(reportAction: OnyxInputO
276276
return reportAction.originalMessage;
277277
}
278278

279-
function isExportIntegrationAction(reportAction: OnyxInputOrEntry<ReportAction>): boolean {
279+
function isExportIntegrationAction(reportAction: OnyxInputOrEntry<ReportAction>): reportAction is ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.EXPORTED_TO_INTEGRATION> {
280280
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.EXPORTED_TO_INTEGRATION;
281281
}
282282

283-
function isIntegrationMessageAction(reportAction: OnyxInputOrEntry<ReportAction>): boolean {
283+
function isIntegrationMessageAction(reportAction: OnyxInputOrEntry<ReportAction>): reportAction is ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.INTEGRATIONS_MESSAGE> {
284284
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.INTEGRATIONS_MESSAGE;
285285
}
286286

src/libs/ReportUtils.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10343,23 +10343,17 @@ function isExported(reportActions: OnyxEntry<ReportActions> | ReportAction[]) {
1034310343
let exportIntegrationActionsCount = 0;
1034410344
let integrationMessageActionsCount = 0;
1034510345

10346-
if (Array.isArray(reportActions)) {
10347-
for (const action of reportActions) {
10348-
if (isExportIntegrationAction(action)) {
10349-
exportIntegrationActionsCount++;
10350-
}
10351-
if (isIntegrationMessageAction(action)) {
10352-
integrationMessageActionsCount++;
10346+
const reportActionList = Array.isArray(reportActions) ? reportActions : Object.values(reportActions);
10347+
for (const action of reportActionList) {
10348+
if (isExportIntegrationAction(action)) {
10349+
// We consider any reports marked manually as exported to be exported, so we shortcircuit here.
10350+
if (getOriginalMessage(action)?.markedManually) {
10351+
return true;
1035310352
}
10353+
exportIntegrationActionsCount++;
1035410354
}
10355-
} else {
10356-
for (const action of Object.values(reportActions)) {
10357-
if (isExportIntegrationAction(action)) {
10358-
exportIntegrationActionsCount++;
10359-
}
10360-
if (isIntegrationMessageAction(action)) {
10361-
integrationMessageActionsCount++;
10362-
}
10355+
if (isIntegrationMessageAction(action)) {
10356+
integrationMessageActionsCount++;
1036310357
}
1036410358
}
1036510359

tests/unit/ReportPrimaryActionUtilsTest.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,32 @@ describe('getPrimaryAction', () => {
128128
expect(getReportPrimaryAction(report, [], {}, policy as Policy)).toBe(CONST.REPORT.PRIMARY_ACTIONS.EXPORT_TO_ACCOUNTING);
129129
});
130130

131+
it('should not return EXPORT TO ACCOUNTING for reports marked manually as exported', async () => {
132+
const report = {
133+
reportID: REPORT_ID,
134+
type: CONST.REPORT.TYPE.EXPENSE,
135+
ownerAccountID: CURRENT_USER_ACCOUNT_ID,
136+
statusNum: CONST.REPORT.STATUS_NUM.CLOSED,
137+
} as unknown as Report;
138+
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
139+
const policy = {
140+
connections: {
141+
intacct: {
142+
config: {
143+
export: {
144+
exporter: CURRENT_USER_EMAIL,
145+
},
146+
},
147+
},
148+
},
149+
};
150+
const reportActions = [
151+
{actionName: CONST.REPORT.ACTIONS.TYPE.EXPORTED_TO_INTEGRATION, reportActionID: '1', created: '2025-01-01', originalMessage: {markedManually: true}},
152+
] as unknown as ReportAction[];
153+
154+
expect(getReportPrimaryAction(report, [], {}, policy as Policy, {}, reportActions)).toBe('');
155+
});
156+
131157
it('should return REMOVE HOLD for reports with transactions on hold', async () => {
132158
const report = {
133159
reportID: REPORT_ID,

0 commit comments

Comments
 (0)