Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d156bd7
fix: show correct report field
daledah May 22, 2025
21964e8
fix: correct logics
daledah May 22, 2025
5ad6243
Merge branch 'main' into fix/62415
daledah May 26, 2025
06ccc92
refactor: rename param
daledah May 27, 2025
e80e224
Merge branch 'main' into fix/62415
daledah May 27, 2025
e5f6540
Merge branch 'main' into fix/62415
daledah May 28, 2025
e8efece
fix: show report for instant submit policy only
daledah May 28, 2025
2af2aa3
fix: revert changes
daledah May 28, 2025
604be91
Merge branch 'main' into fix/62415
daledah May 29, 2025
5f30834
Merge branch 'main' into fix/62415
daledah Jun 4, 2025
184d996
Merge branch 'main' into fix/62415
daledah Jun 9, 2025
a68c698
Merge branch 'main' into fix/62415
daledah Jun 24, 2025
6ba3a21
Merge branch 'main' into fix/62415
daledah Jul 7, 2025
efa2d20
fix: allow submitted report selection for processing reports
daledah Jul 7, 2025
2ded881
fix: remove unused
daledah Jul 7, 2025
b9a41a9
fix: lint
daledah Jul 7, 2025
adee10e
fix: add test case
daledah Jul 7, 2025
fc529bf
fix: get correct reportID
daledah Jul 8, 2025
db06b91
fix: test
daledah Jul 8, 2025
8ab7b16
Merge branch 'main' into fix/62415
daledah Jul 10, 2025
bf201dc
fix: apply suggestions
daledah Jul 10, 2025
c59c45e
fix: test
daledah Jul 10, 2025
c217404
Merge branch 'main' into fix/62415
daledah Jul 10, 2025
9867ecf
Merge branch 'main' into fix/62415
daledah Jul 22, 2025
b4b4cf0
Merge branch 'main' into fix/62415
daledah Jul 25, 2025
9e49657
fix: allow move expense to processing report
daledah Jul 25, 2025
db1e0df
Merge branch 'main' into fix/62415
daledah Jul 28, 2025
4517fd7
fix: update allow submission logics
daledah Jul 28, 2025
e3d7b17
fix: change default value
daledah Jul 28, 2025
5f8357d
Merge branch 'main' into fix/62415
daledah Jul 29, 2025
b3ff211
fix: test
daledah Jul 29, 2025
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/components/MoneyRequestConfirmationListFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ function MoneyRequestConfirmationListFooter({
const transactionReport = !!transaction?.reportID && Object.values(allReports ?? {}).find((report) => report?.reportID === transaction.reportID);
const policyID = selectedParticipants?.at(0)?.policyID;
const reportOwnerAccountID = selectedParticipants?.at(0)?.ownerAccountID;
const shouldUseTransactionReport = !!transactionReport && isReportOutstanding(transactionReport, policyID);
const firstOutstandingReport = getOutstandingReportsForUser(policyID, reportOwnerAccountID, allReports ?? {}).at(0);
const shouldUseTransactionReport = !!transactionReport && isReportOutstanding(transactionReport, policyID, undefined, false);
const firstOutstandingReport = getOutstandingReportsForUser(policyID, reportOwnerAccountID, allReports ?? {}, undefined, false).at(0);
Comment thread
daledah marked this conversation as resolved.
Resolved
let reportName: string | undefined;
if (shouldUseTransactionReport) {
reportName = transactionReport.reportName;
Expand Down
14 changes: 11 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ import getStateFromPath from './Navigation/helpers/getStateFromPath';
import {isFullScreenName} from './Navigation/helpers/isNavigatorName';
import {linkingConfig} from './Navigation/linkingConfig';
import Navigation, {navigationRef} from './Navigation/Navigation';
import type {MoneyRequestNavigatorParamList, ReportsSplitNavigatorParamList} from './Navigation/types';
import {rand64} from './NumberUtils';
import Parser from './Parser';
import {getParsedMessageWithShortMentions} from './ParsingUtils';
Expand Down Expand Up @@ -9974,18 +9975,24 @@ function isReportOutstanding(
iouReport: OnyxInputOrEntry<Report>,
policyID: string | undefined,
reportNameValuePairs: OnyxCollection<ReportNameValuePairs> = allReportNameValuePair,
allowSubmitted = true,
Comment thread
daledah marked this conversation as resolved.
Resolved
): boolean {
if (!iouReport || isEmptyObject(iouReport)) {
return false;
}
const currentRoute = navigationRef.getCurrentRoute();
const params = currentRoute?.params as MoneyRequestNavigatorParamList[typeof SCREENS.MONEY_REQUEST.STEP_CONFIRMATION] | ReportsSplitNavigatorParamList[typeof SCREENS.REPORT];
const activeReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${params?.reportID}`];
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`];
const reportNameValuePair = reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${iouReport.reportID}`];
const shouldAllowSubmittedReport = allowSubmitted || isInstantSubmitEnabled(policy) || isProcessingReport(activeReport);
return (
isExpenseReport(iouReport) &&
iouReport?.stateNum !== undefined &&
iouReport?.statusNum !== undefined &&
iouReport?.policyID === policyID &&
iouReport?.stateNum <= CONST.REPORT.STATE_NUM.SUBMITTED &&
iouReport?.statusNum <= CONST.REPORT.STATUS_NUM.SUBMITTED &&
(shouldAllowSubmittedReport ? iouReport?.stateNum <= CONST.REPORT.STATE_NUM.SUBMITTED : iouReport?.stateNum < CONST.REPORT.STATE_NUM.SUBMITTED) &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Coming from #77661, we should use canAddTransaction to detect whether the report is outstanding

(shouldAllowSubmittedReport ? iouReport?.statusNum <= CONST.REPORT.STATE_NUM.SUBMITTED : iouReport?.statusNum < CONST.REPORT.STATE_NUM.SUBMITTED) &&
!hasForwardedAction(iouReport.reportID) &&
!isArchivedReport(reportNameValuePair)
);
Expand All @@ -10003,6 +10010,7 @@ function getOutstandingReportsForUser(
reportOwnerAccountID: number | undefined,
reports: OnyxCollection<Report> = allReports,
reportNameValuePairs: OnyxCollection<ReportNameValuePairs> = allReportNameValuePair,
allowSubmitted = true,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the default value of allowSubmitted is different between isReportOutstanding and getOutstandingReportsForUser. Is it intentional?

): Array<OnyxEntry<Report>> {
if (!reports) {
return [];
Expand All @@ -10011,7 +10019,7 @@ function getOutstandingReportsForUser(
.filter(
(report) =>
report?.pendingFields?.preview !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE &&
isReportOutstanding(report, policyID, reportNameValuePairs) &&
isReportOutstanding(report, policyID, reportNameValuePairs, allowSubmitted) &&
report?.ownerAccountID === reportOwnerAccountID,
)
.sort((a, b) => localeCompare(a?.reportName?.toLowerCase() ?? '', b?.reportName?.toLowerCase() ?? ''));
Expand Down
1 change: 1 addition & 0 deletions src/pages/Search/SearchTransactionsChangeReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function SearchTransactionsChangeReport() {
backTo={undefined}
transactionsReports={transactionsReports}
selectReport={selectReport}
isEditing
/>
);
}
Expand Down
4 changes: 3 additions & 1 deletion src/pages/iou/request/step/IOURequestEditReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {ListItem} from '@components/SelectionList/types';
import useOnyx from '@hooks/useOnyx';
import {changeTransactionsReport} from '@libs/actions/Transaction';
import Navigation from '@libs/Navigation/Navigation';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
import IOURequestEditReportCommon from './IOURequestEditReportCommon';
Expand All @@ -18,7 +19,7 @@ type TransactionGroupListItem = ListItem & {
type IOURequestEditReportProps = WithWritableReportOrNotFoundProps<typeof SCREENS.MONEY_REQUEST.EDIT_REPORT>;

function IOURequestEditReport({route}: IOURequestEditReportProps) {
const {backTo, reportID} = route.params;
const {backTo, reportID, action} = route.params;

const {selectedTransactionIDs, clearSelectedTransactions} = useSearchContext();

Expand All @@ -40,6 +41,7 @@ function IOURequestEditReport({route}: IOURequestEditReportProps) {
backTo={backTo}
transactionsReports={transactionReport ? [transactionReport] : []}
selectReport={selectReport}
isEditing={action === CONST.IOU.ACTION.EDIT}
/>
);
}
Expand Down
6 changes: 4 additions & 2 deletions src/pages/iou/request/step/IOURequestEditReportCommon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ type Props = {
transactionsReports: Report[];
policyID?: string;
selectReport: (item: TransactionGroupListItem) => void;
isEditing?: boolean;
};

function IOURequestEditReportCommon({backTo, transactionsReports, selectReport, policyID: policyIDFromProps}: Props) {
function IOURequestEditReportCommon({backTo, transactionsReports, selectReport, policyID: policyIDFromProps, isEditing}: Props) {
const {translate} = useLocalize();
const {options} = useOptionsList();
const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {selector: (reports) => mapOnyxCollectionItems(reports, reportSelector), canBeMissing: true});
Expand All @@ -66,10 +67,11 @@ function IOURequestEditReportCommon({backTo, transactionsReports, selectReport,
transactionsReports.at(0)?.ownerAccountID ?? currentUserPersonalDetails.accountID,
allReports ?? {},
reportNameValuePairs,
isEditing,
);
return reports;
}),
[allReports, currentUserPersonalDetails.accountID, transactionsReports, allPoliciesID, reportNameValuePairs, policyIDFromProps],
[allReports, currentUserPersonalDetails.accountID, transactionsReports, isEditing, allPoliciesID, reportNameValuePairs, policyIDFromProps],
);

const reportOptions: TransactionGroupListItem[] = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function IOURequestStepConfirmation({
*/
const transactionReport = getReportOrDraftReport(transaction?.reportID);
const shouldUseTransactionReport =
transactionReport && !(isProcessingReport(transactionReport) && !policyReal?.harvesting?.enabled) && isReportOutstanding(transactionReport, policyReal?.id);
transactionReport && !(isProcessingReport(transactionReport) && !policyReal?.harvesting?.enabled) && isReportOutstanding(transactionReport, policyReal?.id, undefined, false);
const report = shouldUseTransactionReport ? transactionReport : (reportReal ?? reportDraft);
const policy = policyReal ?? policyDraft;
const isDraftPolicy = policy === policyDraft;
Expand Down
1 change: 1 addition & 0 deletions src/pages/iou/request/step/IOURequestStepReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ function IOURequestStepReport({route, transaction}: IOURequestStepReportProps) {
transactionsReports={transactionReport ? [transactionReport] : []}
selectReport={selectReport}
policyID={!isEditing && !isFromGlobalCreate ? reportOrDraftReport?.policyID : undefined}
isEditing={isEditing}
/>
);
}
Expand Down
39 changes: 39 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
// Be sure to include the mocked permissions library or else the beta tests won't work
jest.mock('@libs/Permissions');

jest.mock('@libs/Navigation/Navigation', () => ({
setNavigationActionToMicrotaskQueue: jest.fn(),
navigationRef: {
getCurrentRoute: jest.fn(() => ({
params: {
reportID: '2',
},
})),
},
}));

const testDate = DateUtils.getDBTime();
const currentUserEmail = 'bjorn@vikings.net';
const currentUserAccountID = 5;
Expand Down Expand Up @@ -3695,6 +3706,34 @@ describe('ReportUtils', () => {
};
expect(isReportOutstanding(report, policy.id)).toBe(true);
});
it('should return false for submitted reports if we specify it', () => {
const report: Report = {
...createRandomReport(1),
policyID: policy.id,
type: CONST.REPORT.TYPE.EXPENSE,
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED,
};
expect(isReportOutstanding(report, policy.id, undefined, false)).toBe(false);
});
it('should return true for submitted reports if top most report ID is processing', async () => {
const report: Report = {
...createRandomReport(1),
policyID: policy.id,
type: CONST.REPORT.TYPE.EXPENSE,
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED,
};
const activeReport: Report = {
...createRandomReport(2),
policyID: policy.id,
type: CONST.REPORT.TYPE.EXPENSE,
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED,
};
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${activeReport.reportID}`, activeReport);
expect(isReportOutstanding(report, policy.id)).toBe(true);
});
it('should return false for archived report', async () => {
const report: Report = {
...createRandomReport(1),
Expand Down