Skip to content

Fix: Unreported per diem expense can be added to workspace chat without per diem #65554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
20 changes: 18 additions & 2 deletions src/pages/AddUnreportedExpense.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import useThemeStyles from '@hooks/useThemeStyles';
import {fetchUnreportedExpenses} from '@libs/actions/UnreportedExpenses';
import interceptAnonymousUser from '@libs/interceptAnonymousUser';
import type {AddUnreportedExpensesParamList} from '@libs/Navigation/types';
import {canSubmitPerDiemExpenseFromWorkspace, getPerDiemCustomUnit} from '@libs/PolicyUtils';
import {isIOUReport} from '@libs/ReportUtils';
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
import {createUnreportedExpenseSections} from '@libs/TransactionUtils';
import {createUnreportedExpenseSections, isPerDiemRequest} from '@libs/TransactionUtils';
import Navigation from '@navigation/Navigation';
import type {PlatformStackScreenProps} from '@navigation/PlatformStackNavigation/types';
import {convertBulkTrackedExpensesToIOU, startMoneyRequest} from '@userActions/IOU';
Expand Down Expand Up @@ -51,7 +52,22 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {
if (!transactions) {
return [];
}
return Object.values(transactions || {}).filter((item) => item?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID || item?.reportID === '');
return Object.values(transactions || {}).filter((item) => {
const isUnreported = item?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID || item?.reportID === '';
if (!isUnreported) {
return false;
}

if (isPerDiemRequest(item)) {
// Only show per diem expenses if the target workspace has per diem enabled and the per diem expense was created in the same workspace
const workspacePerDiemUnit = getPerDiemCustomUnit(policy);
const perDiemCustomUnitID = item?.comment?.customUnit?.customUnitID;

return canSubmitPerDiemExpenseFromWorkspace(policy) && (!perDiemCustomUnitID || perDiemCustomUnitID === workspacePerDiemUnit?.customUnitID);
Copy link
Member

Choose a reason for hiding this comment

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

You method of checking that same workspace does not seem quite right. You should check whether transaction is linked to the same policy not by perdiem unit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unreported transactions don't have a valid policyID/reportID (since unreported transaction is placed in self DM with reportID: "0"), so I don't think we can rely on either of those fields

In this case, the customUnitID likely represents the original workspace where the per diem was created, so IMO it should be treated as the primary identifier for determining which workspace the transaction belongs to

Copy link
Member

Choose a reason for hiding this comment

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

I see, let me check this.

}

return true;
});
}

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