@@ -75,22 +75,24 @@ function IOURequestStepReport({route, transaction}: IOURequestStepReportProps) {
7575 ? iouActions ?. find ( ( iouAction ) => getOriginalMessage ( iouAction as ReportAction < typeof CONST . REPORT . ACTIONS . TYPE . IOU > ) ?. IOUTransactionID === transaction . transactionID ) ?. actorAccountID
7676 : selectedReport ?. ownerAccountID ;
7777 const ownerPersonalDetails = getPersonalDetailsForAccountID ( ownerAccountID , personalDetails ) as PersonalDetails ;
78+ const isPerDiemTransaction = isPerDiemRequest ( transaction ) ;
7879
7980 const transactionPolicyID = transaction ?. participants ?. at ( 0 ) ?. isPolicyExpenseChat ? transaction ?. participants . at ( 0 ) ?. policyID : undefined ;
81+ // When moving an expense that belongs to another user, or when the selection includes per diem
82+ // transactions, use the policy of their report (or the transaction's policy as fallback) so the
83+ // selected workspace is preserved.
84+ // For the current user's own non-per-diem expenses, fall back to undefined to let the default workspace apply.
85+ const targetExpensePolicyID = ownerAccountID !== session ?. accountID || isPerDiemTransaction ? ( selectedReport ?. policyID ?? transactionPolicyID ) : undefined ;
86+
8087 // we need to fall back to transactionPolicyID because for a new workspace there is no report created yet
8188 // and if we choose this workspace as participant we want to create a new report in the chosen workspace
82- const { policyForMovingExpensesID, shouldSelectPolicy} = usePolicyForMovingExpenses (
83- isPerDiemRequest ( transaction ) ,
84- isTimeRequestUtil ( transaction ) ,
85- selectedReport ?. policyID ?? transactionPolicyID ,
86- ) ;
89+ const { policyForMovingExpensesID, shouldSelectPolicy} = usePolicyForMovingExpenses ( isPerDiemTransaction , isTimeRequestUtil ( transaction ) , targetExpensePolicyID ) ;
8790
8891 const [ transactionViolations ] = useOnyx ( ONYXKEYS . COLLECTION . TRANSACTION_VIOLATIONS ) ;
8992 const [ allTransactions ] = useOnyx ( ONYXKEYS . COLLECTION . TRANSACTION ) ;
9093 const hasViolations = hasViolationsReportUtils ( undefined , transactionViolations , session ?. accountID ?? CONST . DEFAULT_NUMBER_ID , session ?. email ?? '' ) ;
9194 const policyForMovingExpenses = policyForMovingExpensesID ? allPolicies ?. [ `${ ONYXKEYS . COLLECTION . POLICY } ${ policyForMovingExpensesID } ` ] : undefined ;
9295 useRestartOnReceiptFailure ( transaction , reportIDFromRoute , iouType , action ) ;
93- const isPerDiemTransaction = isPerDiemRequest ( transaction ) ;
9496 const perDiemOriginalPolicy = getPolicyByCustomUnitID ( transaction , allPolicies ) ;
9597 const [ transactions ] = useOptimisticDraftTransactions ( transaction ) ;
9698 const [ betas ] = useOnyx ( ONYXKEYS . BETAS ) ;
@@ -293,12 +295,12 @@ function IOURequestStepReport({route, transaction}: IOURequestStepReportProps) {
293295 transactionIDs = { transaction ? [ transaction . transactionID ] : [ ] }
294296 selectedReportID = { selectedReportID }
295297 selectedPolicyID = { selectedPolicyID }
296- transactionPolicyID = { selectedReport ?. policyID ?? transactionPolicyID }
298+ transactionPolicyID = { targetExpensePolicyID }
297299 removeFromReport = { removeFromReport }
298300 isEditing = { isEditing }
299301 isUnreported = { isUnreported }
300302 shouldShowNotFoundPage = { shouldShowNotFoundPage }
301- isPerDiemRequest = { transaction ? isPerDiemRequest ( transaction ) : false }
303+ isPerDiemRequest = { transaction ? isPerDiemTransaction : false }
302304 isTimeRequest = { transaction ? isTimeRequestUtil ( transaction ) : false }
303305 createReport = { policyForMovingExpensesID || shouldSelectPolicy || isPerDiemTransaction ? createReport : undefined }
304306 targetOwnerAccountID = { ownerAccountID }
0 commit comments