Skip to content
Merged
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 @@ -17,9 +17,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 @@ -53,7 +54,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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@ryntgh Why are we checking for the per diem expense was created in the same workspace?

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.

We check if the per diem expense was created in the same workspace because user can't transfer per diem expenses between workspaces, even if both workspaces have the same per diem rates. BE doesn’t accept the transfer and returns the following response

image
Heads up! You can't transfer Per Diem International expenses between workspaces, as the Per Diem International rates may differ on each workspace. Please select a report on the A Workspace workspace, or create a new expense in the desired workspace to continue.

}

return true;
});
}

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