Skip to content

Commit 119361a

Browse files
authored
Merge pull request Expensify#65554 from ryntgh/issue-65402
Fix: Unreported per diem expense can be added to workspace chat without per diem
2 parents eb438cf + ce85ef8 commit 119361a

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

src/pages/AddUnreportedExpense.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ import useThemeStyles from '@hooks/useThemeStyles';
1717
import {fetchUnreportedExpenses} from '@libs/actions/UnreportedExpenses';
1818
import interceptAnonymousUser from '@libs/interceptAnonymousUser';
1919
import type {AddUnreportedExpensesParamList} from '@libs/Navigation/types';
20+
import {canSubmitPerDiemExpenseFromWorkspace, getPerDiemCustomUnit} from '@libs/PolicyUtils';
2021
import {isIOUReport} from '@libs/ReportUtils';
2122
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
22-
import {createUnreportedExpenseSections} from '@libs/TransactionUtils';
23+
import {createUnreportedExpenseSections, isPerDiemRequest} from '@libs/TransactionUtils';
2324
import Navigation from '@navigation/Navigation';
2425
import type {PlatformStackScreenProps} from '@navigation/PlatformStackNavigation/types';
2526
import {convertBulkTrackedExpensesToIOU, startMoneyRequest} from '@userActions/IOU';
@@ -53,7 +54,22 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {
5354
if (!transactions) {
5455
return [];
5556
}
56-
return Object.values(transactions || {}).filter((item) => item?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID || item?.reportID === '');
57+
return Object.values(transactions || {}).filter((item) => {
58+
const isUnreported = item?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID || item?.reportID === '';
59+
if (!isUnreported) {
60+
return false;
61+
}
62+
63+
if (isPerDiemRequest(item)) {
64+
// Only show per diem expenses if the target workspace has per diem enabled and the per diem expense was created in the same workspace
65+
const workspacePerDiemUnit = getPerDiemCustomUnit(policy);
66+
const perDiemCustomUnitID = item?.comment?.customUnit?.customUnitID;
67+
68+
return canSubmitPerDiemExpenseFromWorkspace(policy) && (!perDiemCustomUnitID || perDiemCustomUnitID === workspacePerDiemUnit?.customUnitID);
69+
}
70+
71+
return true;
72+
});
5773
}
5874

5975
const [transactions = getEmptyArray<Transaction>()] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {

0 commit comments

Comments
 (0)