diff --git a/src/components/AddUnreportedExpenseFooter.tsx b/src/components/AddUnreportedExpenseFooter.tsx
index 53c506524f96..dac0a45e6973 100644
--- a/src/components/AddUnreportedExpenseFooter.tsx
+++ b/src/components/AddUnreportedExpenseFooter.tsx
@@ -44,6 +44,7 @@ function AddUnreportedExpenseFooter({selectedIds, report, reportToConfirm, repor
const [allTransactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {canBeMissing: true});
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true});
const [policyRecentlyUsedCurrencies] = useOnyx(ONYXKEYS.RECENTLY_USED_CURRENCIES, {canBeMissing: true});
+ const [allSnapshots] = useOnyx(ONYXKEYS.COLLECTION.SNAPSHOT, {canBeMissing: true});
const [quickAction] = useOnyx(ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, {canBeMissing: true});
const handleConfirm = () => {
@@ -73,6 +74,7 @@ function AddUnreportedExpenseFooter({selectedIds, report, reportToConfirm, repor
email: session?.email ?? '',
newReport: reportToConfirm,
policy,
+ allSnapshots,
reportNextStep,
policyCategories,
allTransactions,
diff --git a/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx b/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx
index 4a9598349e7c..3e9a5c4f20fe 100644
--- a/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx
+++ b/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx
@@ -641,12 +641,14 @@ function MoneyRequestReportTransactionList({
)}
-
+
+
+
) {
+ if (!allSnapshots) {
+ return [];
+ }
+
+ return Object.keys(allSnapshots || {}) as OnyxSnapshotKey[];
+}
+
export {
getSuggestedSearches,
getDefaultActionableSearchMenuItem,
@@ -3556,6 +3566,7 @@ export {
getSettlementStatus,
getSettlementStatusBadgeProps,
getTransactionFromTransactionListItem,
+ getSnapshotKeys,
getSearchColumnTranslationKey,
getTableMinWidth,
getCustomColumns,
diff --git a/src/libs/actions/Transaction.ts b/src/libs/actions/Transaction.ts
index 1382bd5d0a09..a88cf4f86e57 100644
--- a/src/libs/actions/Transaction.ts
+++ b/src/libs/actions/Transaction.ts
@@ -35,6 +35,7 @@ import {
hasViolations as hasViolationsReportUtils,
shouldEnableNegative,
} from '@libs/ReportUtils';
+import {getSnapshotKeys} from '@libs/SearchUIUtils';
import {isManagedCardTransaction, isOnHold, shouldClearConvertedAmount, waypointHasValidAddress} from '@libs/TransactionUtils';
import ViolationsUtils from '@libs/Violations/ViolationsUtils';
import CONST from '@src/CONST';
@@ -48,6 +49,7 @@ import type {
ReportAction,
ReportNextStepDeprecated,
ReviewDuplicates,
+ SearchResults,
Transaction,
TransactionViolation,
TransactionViolations,
@@ -701,6 +703,7 @@ type ChangeTransactionsReportProps = {
isASAPSubmitBetaEnabled: boolean;
accountID: number;
email: string;
+ allSnapshots: OnyxCollection;
newReport?: OnyxEntry;
policy?: OnyxEntry;
reportNextStep?: OnyxEntry;
@@ -715,6 +718,7 @@ function changeTransactionsReport({
email,
newReport,
policy,
+ allSnapshots,
reportNextStep,
policyCategories,
allTransactions,
@@ -742,6 +746,7 @@ function changeTransactionsReport({
| typeof ONYXKEYS.COLLECTION.TRANSACTION
| typeof ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS
| typeof ONYXKEYS.COLLECTION.NEXT_STEP
+ | typeof ONYXKEYS.COLLECTION.SNAPSHOT
>
> = [];
const successData: Array<
@@ -751,6 +756,7 @@ function changeTransactionsReport({
| typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS
| typeof ONYXKEYS.COLLECTION.TRANSACTION
| typeof ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS
+ | typeof ONYXKEYS.COLLECTION.SNAPSHOT
>
> = [];
@@ -1006,16 +1012,122 @@ function changeTransactionsReport({
const targetReportID = isUnreported ? selfDMReportID : reportID;
const {amount: transactionAmount = 0, currency: transactionCurrency} = getTransactionDetails(transaction, undefined, undefined, allowNegative) ?? {};
const oldReportTotal = oldReport?.total ?? 0;
- const updatedReportTotal = transactionAmount < 0 ? oldReportTotal - transactionAmount : oldReportTotal + transactionAmount;
-
- if (oldReport && oldReport.currency === transactionCurrency) {
- updatedReportTotals[oldReportID] = updatedReportTotals[oldReportID] ? updatedReportTotals[oldReportID] : updatedReportTotal;
- updatedReportNonReimbursableTotals[oldReportID] =
- (updatedReportNonReimbursableTotals[oldReportID] ? updatedReportNonReimbursableTotals[oldReportID] : (oldReport?.nonReimbursableTotal ?? 0)) +
- (transaction?.reimbursable ? 0 : transactionAmount);
- updatedReportUnheldNonReimbursableTotals[oldReportID] =
- (updatedReportUnheldNonReimbursableTotals[oldReportID] ? updatedReportUnheldNonReimbursableTotals[oldReportID] : (oldReport?.unheldNonReimbursableTotal ?? 0)) +
- (transaction?.reimbursable && !isOnHold(transaction) ? 0 : transactionAmount);
+
+ if (oldReport) {
+ const oldReportCurrency = oldReport.currency;
+ const remainingTransactions = getReportTransactions(oldReportID).filter(
+ (t) => t.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && !transactionIDs.includes(t.transactionID),
+ );
+
+ const willBeEmpty = remainingTransactions.length === 0;
+
+ if (willBeEmpty) {
+ updatedReportTotals[oldReportID] = 0;
+ updatedReportNonReimbursableTotals[oldReportID] = 0;
+ updatedReportUnheldNonReimbursableTotals[oldReportID] = 0;
+ } else if (oldReportCurrency === transactionCurrency) {
+ const baseTotal = updatedReportTotals[oldReportID] ?? oldReportTotal;
+
+ const baseNonReimb = updatedReportNonReimbursableTotals[oldReportID] ?? oldReport?.nonReimbursableTotal ?? 0;
+
+ const baseUnheld = updatedReportUnheldNonReimbursableTotals[oldReportID] ?? oldReport?.unheldNonReimbursableTotal ?? 0;
+
+ let addToNonReimb = 0;
+ let addToUnheld = 0;
+
+ if (!transaction?.reimbursable) {
+ addToNonReimb = transactionAmount;
+
+ if (!isOnHold(transaction)) {
+ addToUnheld = transactionAmount;
+ }
+ }
+
+ updatedReportTotals[oldReportID] = baseTotal + transactionAmount;
+ updatedReportNonReimbursableTotals[oldReportID] = baseNonReimb + addToNonReimb;
+ updatedReportUnheldNonReimbursableTotals[oldReportID] = baseUnheld + addToUnheld;
+ } else {
+ optimisticData.push({
+ onyxMethod: Onyx.METHOD.MERGE,
+ key: `${ONYXKEYS.COLLECTION.REPORT}${oldReport.reportID}`,
+ value: {
+ pendingFields: {
+ preview: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
+ total: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
+ },
+ },
+ });
+
+ failureData.push({
+ onyxMethod: Onyx.METHOD.MERGE,
+ key: `${ONYXKEYS.COLLECTION.REPORT}${oldReport.reportID}`,
+ value: {
+ pendingFields: {
+ preview: null,
+ total: null,
+ },
+ },
+ });
+
+ successData.push({
+ onyxMethod: Onyx.METHOD.MERGE,
+ key: `${ONYXKEYS.COLLECTION.REPORT}${oldReport.reportID}`,
+ value: {
+ pendingFields: {
+ preview: null,
+ total: null,
+ },
+ },
+ });
+
+ const allSnapshotKeys = getSnapshotKeys(allSnapshots);
+
+ if (allSnapshotKeys?.length && allSnapshotKeys.length > 0) {
+ for (const key of allSnapshotKeys) {
+ optimisticData.push({
+ onyxMethod: Onyx.METHOD.MERGE,
+ key,
+ value: {
+ data: {
+ [`${ONYXKEYS.COLLECTION.REPORT}${oldReport.reportID}`]: {
+ pendingFields: {
+ total: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
+ },
+ },
+ },
+ } as Partial,
+ });
+
+ failureData.push({
+ onyxMethod: Onyx.METHOD.MERGE,
+ key,
+ value: {
+ data: {
+ [`${ONYXKEYS.COLLECTION.REPORT}${oldReport.reportID}`]: {
+ pendingFields: {
+ total: null,
+ },
+ },
+ },
+ } as Partial,
+ });
+
+ successData.push({
+ onyxMethod: Onyx.METHOD.MERGE,
+ key,
+ value: {
+ data: {
+ [`${ONYXKEYS.COLLECTION.REPORT}${oldReport.reportID}`]: {
+ pendingFields: {
+ total: null,
+ },
+ },
+ },
+ } as Partial,
+ });
+ }
+ }
+ }
}
if (targetReportID) {
@@ -1044,6 +1156,89 @@ function changeTransactionsReport({
const currentUnheldNonReimbursableTotal = updatedReportUnheldNonReimbursableTotals[targetReportID] ?? targetReport?.unheldNonReimbursableTotal ?? 0;
updatedReportUnheldNonReimbursableTotals[targetReportID] = currentUnheldNonReimbursableTotal + (transactionReimbursable && !isOnHold(transaction) ? 0 : convertedAmount);
}
+
+ if (transactionCurrency !== targetReport?.currency) {
+ optimisticData.push({
+ onyxMethod: Onyx.METHOD.MERGE,
+ key: `${ONYXKEYS.COLLECTION.REPORT}${targetReportID}`,
+ value: {
+ pendingFields: {
+ preview: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
+ total: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
+ },
+ },
+ });
+
+ failureData.push({
+ onyxMethod: Onyx.METHOD.MERGE,
+ key: `${ONYXKEYS.COLLECTION.REPORT}${targetReportID}`,
+ value: {
+ pendingFields: {
+ preview: null,
+ total: null,
+ },
+ },
+ });
+
+ successData.push({
+ onyxMethod: Onyx.METHOD.MERGE,
+ key: `${ONYXKEYS.COLLECTION.REPORT}${targetReportID}`,
+ value: {
+ pendingFields: {
+ preview: null,
+ total: null,
+ },
+ },
+ });
+
+ const allSnapshotKeys = getSnapshotKeys(allSnapshots);
+
+ if (allSnapshotKeys?.length && allSnapshotKeys.length > 0) {
+ for (const key of allSnapshotKeys) {
+ optimisticData.push({
+ onyxMethod: Onyx.METHOD.MERGE,
+ key,
+ value: {
+ data: {
+ [`${ONYXKEYS.COLLECTION.REPORT}${targetReportID}`]: {
+ pendingFields: {
+ total: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
+ },
+ },
+ },
+ } as Partial,
+ });
+
+ failureData.push({
+ onyxMethod: Onyx.METHOD.MERGE,
+ key,
+ value: {
+ data: {
+ [`${ONYXKEYS.COLLECTION.REPORT}${targetReportID}`]: {
+ pendingFields: {
+ total: null,
+ },
+ },
+ },
+ } as Partial,
+ });
+
+ successData.push({
+ onyxMethod: Onyx.METHOD.MERGE,
+ key,
+ value: {
+ data: {
+ [`${ONYXKEYS.COLLECTION.REPORT}${targetReportID}`]: {
+ pendingFields: {
+ total: null,
+ },
+ },
+ },
+ } as Partial,
+ });
+ }
+ }
+ }
}
// 4. Optimistically update the IOU action reportID
diff --git a/src/pages/NewReportWorkspaceSelectionPage.tsx b/src/pages/NewReportWorkspaceSelectionPage.tsx
index 610d2aaa034b..dae69f50eced 100644
--- a/src/pages/NewReportWorkspaceSelectionPage.tsx
+++ b/src/pages/NewReportWorkspaceSelectionPage.tsx
@@ -68,7 +68,7 @@ function NewReportWorkspaceSelectionPage({route}: NewReportWorkspaceSelectionPag
const hasViolations = hasViolationsReportUtils(undefined, transactionViolations, accountID ?? CONST.DEFAULT_NUMBER_ID, email ?? '');
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: true});
const [hasDismissedEmptyReportsConfirmation] = useOnyx(ONYXKEYS.NVP_EMPTY_REPORTS_CONFIRMATION_DISMISSED, {canBeMissing: true});
-
+ const [allSnapshots] = useOnyx(ONYXKEYS.COLLECTION.SNAPSHOT, {canBeMissing: true});
const [policies, fetchStatus] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true});
const [allTransactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {canBeMissing: true});
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
@@ -136,6 +136,7 @@ function NewReportWorkspaceSelectionPage({route}: NewReportWorkspaceSelectionPag
accountID: currentUserPersonalDetails?.accountID ?? CONST.DEFAULT_NUMBER_ID,
email: currentUserPersonalDetails?.email ?? '',
newReport: optimisticReport,
+ allSnapshots,
policy: policies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`],
reportNextStep,
policyCategories: undefined,
@@ -170,6 +171,7 @@ function NewReportWorkspaceSelectionPage({route}: NewReportWorkspaceSelectionPag
navigateToNewReport,
allReportNextSteps,
backTo,
+ allSnapshots,
allTransactions,
activePolicyID,
clearSelectedTransactions,
diff --git a/src/pages/Search/SearchTransactionsChangeReport.tsx b/src/pages/Search/SearchTransactionsChangeReport.tsx
index 8744ffcf203e..60368b02f82f 100644
--- a/src/pages/Search/SearchTransactionsChangeReport.tsx
+++ b/src/pages/Search/SearchTransactionsChangeReport.tsx
@@ -35,6 +35,7 @@ function SearchTransactionsChangeReport() {
const hasPerDiemTransactions = useHasPerDiemTransactions(selectedTransactionsKeys);
const {policyForMovingExpensesID, shouldSelectPolicy} = usePolicyForMovingExpenses(hasPerDiemTransactions);
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true});
+ const [allSnapshots] = useOnyx(ONYXKEYS.COLLECTION.SNAPSHOT, {canBeMissing: true});
const [allTransactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {canBeMissing: true});
const {isBetaEnabled} = usePermissions();
const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);
@@ -80,6 +81,7 @@ function SearchTransactionsChangeReport() {
changeTransactionsReport({
transactionIDs: selectedTransactionsKeys,
isASAPSubmitBetaEnabled,
+ allSnapshots,
accountID: session?.accountID ?? CONST.DEFAULT_NUMBER_ID,
email: session?.email ?? '',
newReport: optimisticReport,
@@ -125,6 +127,7 @@ function SearchTransactionsChangeReport() {
accountID: session?.accountID ?? CONST.DEFAULT_NUMBER_ID,
email: session?.email ?? '',
newReport: destinationReport,
+ allSnapshots,
policy: allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${item.policyID}`],
reportNextStep,
policyCategories: allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${item.policyID}`],
@@ -145,6 +148,7 @@ function SearchTransactionsChangeReport() {
changeTransactionsReport({
transactionIDs: selectedTransactionsKeys,
isASAPSubmitBetaEnabled,
+ allSnapshots,
accountID: session?.accountID ?? CONST.DEFAULT_NUMBER_ID,
email: session?.email ?? '',
allTransactions,
diff --git a/src/pages/iou/request/step/IOURequestEditReport.tsx b/src/pages/iou/request/step/IOURequestEditReport.tsx
index ea6bd74d7e93..f0b2ff29bade 100644
--- a/src/pages/iou/request/step/IOURequestEditReport.tsx
+++ b/src/pages/iou/request/step/IOURequestEditReport.tsx
@@ -44,6 +44,7 @@ function IOURequestEditReport({route}: IOURequestEditReportProps) {
const session = useSession();
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true});
const [allPolicyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}`, {canBeMissing: true});
+ const [allSnapshots] = useOnyx(ONYXKEYS.COLLECTION.SNAPSHOT, {canBeMissing: true});
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const selectedReportPolicy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${selectedReport?.policyID}`];
@@ -69,6 +70,7 @@ function IOURequestEditReport({route}: IOURequestEditReportProps) {
isASAPSubmitBetaEnabled,
accountID: session?.accountID ?? CONST.DEFAULT_NUMBER_ID,
email: session?.email ?? '',
+ allSnapshots,
newReport,
policy: allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${item.policyID}`],
reportNextStep,
@@ -89,6 +91,7 @@ function IOURequestEditReport({route}: IOURequestEditReportProps) {
changeTransactionsReport({
transactionIDs: selectedTransactionIDs,
isASAPSubmitBetaEnabled,
+ allSnapshots,
accountID: session?.accountID ?? CONST.DEFAULT_NUMBER_ID,
email: session?.email ?? '',
allTransactions,
diff --git a/src/pages/iou/request/step/IOURequestStepReport.tsx b/src/pages/iou/request/step/IOURequestStepReport.tsx
index fe57f6fe497a..6e792e4a42ad 100644
--- a/src/pages/iou/request/step/IOURequestStepReport.tsx
+++ b/src/pages/iou/request/step/IOURequestStepReport.tsx
@@ -48,6 +48,7 @@ function IOURequestStepReport({route, transaction}: IOURequestStepReportProps) {
const selectedReportID = shouldUseTransactionReport ? transactionReport?.reportID : outstandingReportID;
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true});
const [allPolicyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}`, {canBeMissing: true});
+ const [allSnapshots] = useOnyx(ONYXKEYS.COLLECTION.SNAPSHOT, {canBeMissing: true});
const {removeTransaction, setSelectedTransactions} = useSearchContext();
const reportOrDraftReport = getReportOrDraftReport(reportIDFromRoute);
const isEditing = action === CONST.IOU.ACTION.EDIT;
@@ -130,6 +131,7 @@ function IOURequestStepReport({route, transaction}: IOURequestStepReportProps) {
accountID: session?.accountID ?? CONST.DEFAULT_NUMBER_ID,
email: session?.email ?? '',
newReport: report,
+ allSnapshots,
policy: allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${item.policyID}`],
reportNextStep: undefined,
policyCategories: allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${item.policyID}`],
@@ -173,6 +175,7 @@ function IOURequestStepReport({route, transaction}: IOURequestStepReportProps) {
changeTransactionsReport({
transactionIDs: [transaction.transactionID],
isASAPSubmitBetaEnabled,
+ allSnapshots,
accountID: session?.accountID ?? CONST.DEFAULT_NUMBER_ID,
email: session?.email ?? '',
allTransactions,
diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts
index 1f24fd237301..adc7d78cd654 100644
--- a/tests/actions/IOUTest.ts
+++ b/tests/actions/IOUTest.ts
@@ -8931,6 +8931,7 @@ describe('actions/IOU', () => {
accountID: CARLOS_ACCOUNT_ID,
email: CARLOS_EMAIL,
newReport: result.current.report,
+ allSnapshots: {},
allTransactions,
});
diff --git a/tests/unit/TransactionTest.ts b/tests/unit/TransactionTest.ts
index 9e2f37df8b6c..2cbb569e1798 100644
--- a/tests/unit/TransactionTest.ts
+++ b/tests/unit/TransactionTest.ts
@@ -124,6 +124,7 @@ describe('Transaction', () => {
isASAPSubmitBetaEnabled: false,
accountID: CURRENT_USER_ID,
email: 'test@example.com',
+ allSnapshots: {},
newReport: report,
allTransactions,
});
@@ -172,6 +173,7 @@ describe('Transaction', () => {
accountID: CURRENT_USER_ID,
email: 'test@example.com',
newReport: report,
+ allSnapshots: {},
allTransactions,
});
await waitForBatchedUpdates();
@@ -233,6 +235,7 @@ describe('Transaction', () => {
email: 'test@example.com',
newReport: report,
policy: undefined,
+ allSnapshots: {},
reportNextStep: mockReportNextStep,
allTransactions,
});
@@ -297,6 +300,7 @@ describe('Transaction', () => {
email: 'test@example.com',
newReport: report,
policy: undefined,
+ allSnapshots: {},
reportNextStep: mockReportNextStep,
allTransactions,
});
@@ -349,6 +353,7 @@ describe('Transaction', () => {
email: 'test@example.com',
newReport: report,
policy: undefined,
+ allSnapshots: {},
reportNextStep: undefined,
allTransactions,
});
@@ -412,6 +417,7 @@ describe('Transaction', () => {
isASAPSubmitBetaEnabled: false,
accountID: CURRENT_USER_ID,
email: 'test@example.com',
+ allSnapshots: {},
newReport: report,
allTransactions,
});
@@ -468,6 +474,7 @@ describe('Transaction', () => {
accountID: CURRENT_USER_ID,
email: 'test@example.com',
newReport: report,
+ allSnapshots: {},
allTransactions,
});
await waitForBatchedUpdates();
@@ -519,6 +526,7 @@ describe('Transaction', () => {
isASAPSubmitBetaEnabled: false,
accountID: customAccountID,
email: customEmail,
+ allSnapshots: {},
newReport: report,
allTransactions,
});
@@ -578,6 +586,7 @@ describe('Transaction', () => {
accountID: CURRENT_USER_ID,
email: 'test@example.com',
newReport: expenseReport,
+ allSnapshots: {},
allTransactions,
});
await waitForBatchedUpdates();
@@ -635,6 +644,7 @@ describe('Transaction', () => {
isASAPSubmitBetaEnabled: false,
accountID: CURRENT_USER_ID,
email: 'test@example.com',
+ allSnapshots: {},
newReport: expenseReport,
allTransactions,
});
@@ -700,6 +710,7 @@ describe('Transaction', () => {
isASAPSubmitBetaEnabled: false,
accountID: CURRENT_USER_ID,
email: 'test@example.com',
+ allSnapshots: {},
newReport: newExpenseReport,
allTransactions,
});
@@ -765,6 +776,7 @@ describe('Transaction', () => {
accountID: CURRENT_USER_ID,
email: 'test@example.com',
newReport: newExpenseReport,
+ allSnapshots: {},
allTransactions,
});
await waitForBatchedUpdates();
@@ -792,7 +804,7 @@ describe('Transaction', () => {
...generateTransaction({
reportID: oldExpenseReport.reportID,
}),
- amount: -100,
+ amount: -200,
reimbursable: false,
};
const oldIOUAction: OnyxEntry> = {
@@ -821,6 +833,7 @@ describe('Transaction', () => {
isASAPSubmitBetaEnabled: false,
accountID: CURRENT_USER_ID,
email: 'test@example.com',
+ allSnapshots: {},
newReport: fakeReport,
allTransactions,
});
@@ -840,7 +853,7 @@ describe('Transaction', () => {
expect(report?.nonReimbursableTotal).toBe(oldExpenseReport.nonReimbursableTotal - transaction.amount);
});
- it('should not update the old report total when the currency is different', async () => {
+ it('should reset the old report total to 0 when no expenses remain, even if the currencies differ', async () => {
const oldExpenseReport = {
...createRandomReport(1, undefined),
total: -200,
@@ -880,6 +893,7 @@ describe('Transaction', () => {
isASAPSubmitBetaEnabled: false,
accountID: CURRENT_USER_ID,
email: 'test@example.com',
+ allSnapshots: {},
newReport: fakeReport,
allTransactions,
});
@@ -895,8 +909,8 @@ describe('Transaction', () => {
});
});
- expect(report?.total).toBe(oldExpenseReport.total);
- expect(report?.nonReimbursableTotal).toBe(oldExpenseReport.nonReimbursableTotal);
+ expect(report?.total).toBe(0);
+ expect(report?.nonReimbursableTotal).toBe(0);
});
it('should show "waiting for you to submit expense" next step message when moving expense to a new report ', async () => {
@@ -932,6 +946,7 @@ describe('Transaction', () => {
accountID: CURRENT_USER_ID,
email: 'test@gmail.com',
newReport: newOpenReport,
+ allSnapshots: {},
policy,
reportNextStep: undefined,
policyCategories,