Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1472,6 +1472,9 @@ const CONST = {
},
MAX_COUNT_BEFORE_FOCUS_UPDATE: 30,
MIN_INITIAL_REPORT_ACTION_COUNT: 15,
// The backend rejects moving an expense into a report that already holds this many transactions, so the App
// blocks the move up front with a warning instead of letting it fail silently.
MAX_TRANSACTIONS: 500,
UNREPORTED_REPORT_ID: '0',
TRASH_REPORT_ID: '-1',
SPLIT_REPORT_ID: '-2',
Expand Down
1 change: 1 addition & 0 deletions src/languages/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,7 @@ const translations: TranslationDeepObject<typeof en> = {
couldNotReject: 'Der Bericht konnte nicht abgelehnt werden. Bitte versuchen Sie es erneut.',
},
moveExpenses: 'Zum Bericht verschieben',
moveExpensesMaxTransactionsError: `Berichte sind auf ${CONST.REPORT.MAX_TRANSACTIONS} Ausgaben begrenzt. Bitte verschiebe einige in einen anderen Bericht.`,
moveExpensesError: 'Sie können Pauschalspesen nicht in Berichte anderer Arbeitsbereiche verschieben, da die Pauschalsätze je nach Arbeitsbereich unterschiedlich sein können.',
submitReportTo: {
sendExpense: 'Senden Sie Ihre Ausgabe an jede beliebige Person',
Expand Down
1 change: 1 addition & 0 deletions src/languages/el.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1750,6 +1750,7 @@ const translations: TranslationDeepObject<typeof en> = {
couldNotReject: 'Η αναφορά δεν μπόρεσε να απορριφθεί. Παρακαλούμε προσπαθήστε ξανά.',
},
moveExpenses: 'Μετακίνηση στην αναφορά',
moveExpensesMaxTransactionsError: `Οι αναφορές περιορίζονται σε ${CONST.REPORT.MAX_TRANSACTIONS} έξοδα. Μετακινήστε ορισμένα σε άλλη αναφορά.`,
moveExpensesError:
'Δεν μπορείτε να μετακινήσετε έξοδα ημερήσιας αποζημίωσης σε αναφορές άλλων χώρων εργασίας, επειδή οι τιμές ημερήσιας αποζημίωσης μπορεί να διαφέρουν μεταξύ των χώρων εργασίας.',
submitReportTo: {
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1776,6 +1776,7 @@ const translations = {
},
moveExpenses: 'Move to report',
moveExpensesError: "You can't move per diem expenses to reports on other workspaces, because the per diem rates may differ between workspaces.",
moveExpensesMaxTransactionsError: `Reports are limited to ${CONST.REPORT.MAX_TRANSACTIONS} expenses. Please move some to another report.`,
submitReportTo: {
sendExpense: 'Send your expense to anyone',
sendExpenseSubtitle: 'Invite anyone to Expensify by using their email address or phone number.',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,7 @@ const translations: TranslationDeepObject<typeof en> = {
couldNotReject: 'No se pudo rechazar el informe. Por favor, inténtalo de nuevo.',
},
moveExpenses: 'Mover a informe',
moveExpensesMaxTransactionsError: `Los informes están limitados a ${CONST.REPORT.MAX_TRANSACTIONS} gastos. Por favor, mueve algunos a otro informe.`,
moveExpensesError: 'No puedes mover gastos per diem a informes de otros espacios de trabajo, porque las tarifas de dietas pueden diferir entre espacios de trabajo.',
submitReportTo: {
sendExpense: 'Envía tu gasto a cualquier persona',
Expand Down
1 change: 1 addition & 0 deletions src/languages/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,7 @@ const translations: TranslationDeepObject<typeof en> = {
couldNotReject: 'La note de frais n’a pas pu être rejetée. Veuillez réessayer.',
},
moveExpenses: 'Déplacer vers le rapport',
moveExpensesMaxTransactionsError: `Les rapports sont limités à ${CONST.REPORT.MAX_TRANSACTIONS} dépenses. Veuillez en déplacer certaines vers un autre rapport.`,
moveExpensesError:
'Vous ne pouvez pas déplacer des frais de per diem vers des notes de frais d’autres espaces de travail, car les taux de per diem peuvent varier d’un espace de travail à l’autre.',
submitReportTo: {
Expand Down
1 change: 1 addition & 0 deletions src/languages/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,7 @@ const translations: TranslationDeepObject<typeof en> = {
couldNotReject: 'Non è stato possibile rifiutare il report. Riprova.',
},
moveExpenses: 'Sposta nel report',
moveExpensesMaxTransactionsError: `I report sono limitati a ${CONST.REPORT.MAX_TRANSACTIONS} spese. Spostane alcune in un altro report.`,
moveExpensesError: 'Non puoi spostare le spese di diaria nei report di altri spazi di lavoro, perché le tariffe di diaria possono variare tra gli spazi di lavoro.',
submitReportTo: {
sendExpense: 'Invia la tua spesa a chiunque',
Expand Down
1 change: 1 addition & 0 deletions src/languages/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,7 @@ const translations: TranslationDeepObject<typeof en> = {
couldNotReject: 'レポートを拒否できませんでした。もう一度お試しください。',
},
moveExpenses: 'レポートに移動',
moveExpensesMaxTransactionsError: `レポートは${CONST.REPORT.MAX_TRANSACTIONS}件の経費までに制限されています。一部を別のレポートに移動してください。`,
moveExpensesError: '日当経費は、ワークスペースごとに日当レートが異なる場合があるため、他のワークスペースのレポートに移動することはできません。',
submitReportTo: {
sendExpense: '経費を誰にでも送信できます',
Expand Down
1 change: 1 addition & 0 deletions src/languages/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,7 @@ const translations: TranslationDeepObject<typeof en> = {
couldNotReject: 'Het rapport kon niet worden afgewezen. Probeer het opnieuw.',
},
moveExpenses: 'Verplaatsen naar rapport',
moveExpensesMaxTransactionsError: `Rapporten zijn beperkt tot ${CONST.REPORT.MAX_TRANSACTIONS} uitgaven. Verplaats er enkele naar een ander rapport.`,
moveExpensesError: 'Je kunt dagvergoedingdeclaraties niet naar rapporten in andere werkruimten verplaatsen, omdat de dagvergoedingsbedragen per werkruimte kunnen verschillen.',
submitReportTo: {
sendExpense: 'Stuur je uitgave naar iedereen',
Expand Down
1 change: 1 addition & 0 deletions src/languages/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,7 @@ const translations: TranslationDeepObject<typeof en> = {
couldNotReject: 'Nie udało się odrzucić raportu. Spróbuj ponownie.',
},
moveExpenses: 'Przenieś do raportu',
moveExpensesMaxTransactionsError: `Raporty są ograniczone do ${CONST.REPORT.MAX_TRANSACTIONS} wydatków. Przenieś część z nich do innego raportu.`,
moveExpensesError: 'Nie możesz przenosić diet do raportów w innych przestrzeniach roboczych, ponieważ stawki diet mogą się różnić między przestrzeniami roboczymi.',
submitReportTo: {
sendExpense: 'Wyślij swój wydatek do dowolnej osoby',
Expand Down
1 change: 1 addition & 0 deletions src/languages/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1689,6 +1689,7 @@ const translations: TranslationDeepObject<typeof en> = {
couldNotReject: 'Não foi possível rejeitar o relatório. Tente novamente.',
},
moveExpenses: 'Mover para relatório',
moveExpensesMaxTransactionsError: `Os relatórios são limitados a ${CONST.REPORT.MAX_TRANSACTIONS} despesas. Mova algumas para outro relatório.`,
moveExpensesError: 'Você não pode mover despesas de diária para relatórios em outros workspaces, porque as tarifas de diária podem ser diferentes entre os workspaces.',
submitReportTo: {
sendExpense: 'Envie sua despesa para qualquer pessoa',
Expand Down
1 change: 1 addition & 0 deletions src/languages/zh-hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,7 @@ const translations: TranslationDeepObject<typeof en> = {
couldNotReject: '无法拒绝该报表。请重试。',
},
moveExpenses: '移动到报告',
moveExpensesMaxTransactionsError: `每个报告最多可包含 ${CONST.REPORT.MAX_TRANSACTIONS} 笔支出。请将部分支出移动到其他报告。`,
moveExpensesError: '您无法将每日津贴报销移动到其他工作区的报表中,因为不同工作区的每日津贴标准可能不同。',
submitReportTo: {
sendExpense: '将你的报销发送给任何人',
Expand Down
15 changes: 13 additions & 2 deletions src/libs/actions/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,9 @@ function getChangeTransactionsReportOnyxData({
}

let transactionsMoved = false;
// The transactions that are actually moved to the destination report. Transactions already in the destination are
// skipped below, so this excludes them from the transactionList sent to the backend (which does not filter them out).
const movedTransactionIDs: string[] = [];
let shouldFixViolations = false;

const policyHasDependentTags = hasDependentTags(policy, policyTagList);
Expand Down Expand Up @@ -1104,6 +1107,7 @@ function getChangeTransactionsReportOnyxData({
}

transactionsMoved = true;
movedTransactionIDs.push(transaction.transactionID);

const oldReportID = isUnreportedExpense ? CONST.REPORT.UNREPORTED_REPORT_ID : transaction.reportID;
const oldReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${oldReportID}`];
Expand Down Expand Up @@ -1987,6 +1991,7 @@ function getChangeTransactionsReportOnyxData({
updatedReportUnheldNonReimbursableTotals,
updatedReportReimbursableTotals,
updatedReportUnheldReimbursableTotals,
movedTransactionIDs,
};
}

Expand All @@ -1995,12 +2000,18 @@ function changeTransactionsReport(props: ChangeTransactionsReportProps) {
if (!changeTransactionsReportOnyxData) {
return;
}
const {optimisticData, successData, failureData, transactionIDToReportActionAndThreadData, transactionIDToUpdatedCustomUnitRateID} = changeTransactionsReportOnyxData;
const {optimisticData, successData, failureData, transactionIDToReportActionAndThreadData, transactionIDToUpdatedCustomUnitRateID, movedTransactionIDs} =
changeTransactionsReportOnyxData;

// If every selected transaction is already in the destination report, there is nothing to move, so skip the API call.
if (movedTransactionIDs.length === 0) {
return;
}

const reportID = props.newReport?.reportID ?? CONST.REPORT.UNREPORTED_REPORT_ID;

const parameters: ChangeTransactionsReportParams = {
transactionList: props.transactionIDs.join(','),
transactionList: movedTransactionIDs.join(','),
reportID,
transactionIDToReportActionAndThreadData: JSON.stringify(transactionIDToReportActionAndThreadData),
...(Object.keys(transactionIDToUpdatedCustomUnitRateID).length > 0 && {
Expand Down
21 changes: 21 additions & 0 deletions src/pages/iou/request/step/IOURequestEditReportCommon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {BaseTextInputRef} from '@components/TextInput/BaseTextInput/types';

import useAutoFocusInput from '@hooks/useAutoFocusInput';
import useCommuterExclusionGuard from '@hooks/useCommuterExclusionGuard';
import useConfirmModal from '@hooks/useConfirmModal';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useDebouncedState from '@hooks/useDebouncedState';
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
Expand Down Expand Up @@ -110,6 +111,7 @@ function IOURequestEditReportCommon({
const {policyForMovingExpenses} = usePolicyForMovingExpenses(isPerDiemRequest, isTimeRequest, transactionPolicyID, isUnreportedManagedCardTransaction);

const [perDiemWarningModalVisible, setPerDiemWarningModalVisible] = useState(false);
const {showConfirmModal} = useConfirmModal();
const blockManualOrOdometerDistanceRequestIfNeeded = useCommuterExclusionGuard({
isManualDistanceRequest,
isOdometerDistanceRequest,
Expand Down Expand Up @@ -269,6 +271,25 @@ function IOURequestEditReportCommon({
return;
}

// Reports can only hold up to CONST.REPORT.MAX_TRANSACTIONS transactions. The backend rejects a move that would push
// the destination past the limit, so prevent it up front with an explanatory warning instead of failing silently.
// Only count expenses that will actually be added to the destination: the move action skips transactions that are
// already in the destination report (see changeTransactionsReport in Transaction.ts), so a bulk selection that
// includes expenses already in that report must not inflate the projected count (e.g. moving 5 new expenses into a
// report that already holds 490 lands at 495, even if 15 of the selected expenses are already there).
const destinationReport = outstandingReports.find((report) => report?.reportID === item.value);
const numberOfTransactionsToMove =
transactionIDs?.filter((transactionID) => allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]?.reportID !== item.value).length ?? 1;
if ((destinationReport?.transactionCount ?? 0) + numberOfTransactionsToMove > CONST.REPORT.MAX_TRANSACTIONS) {
showConfirmModal({

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.

This guard only blocks reports that are already at the limit — it ignores how many expenses are being moved in.

Example: destination has transactionCount = 490 and the user moves 12. 490 >= 500 is false, so the move proceeds and lands at 502, over the limit.

@MelvinBot please fix this

title: translate('iou.moveExpenses'),
prompt: translate('iou.moveExpensesMaxTransactionsError'),
confirmText: translate('common.buttonConfirm'),
shouldShowCancelButton: false,
});
return;
}

if (!validatePerDiemMove(item.policyID)) {
return;
}
Expand Down
Loading