Skip to content

Commit c8e05f1

Browse files
authored
Merge pull request #78136 from dmkt9/fix/77699
Fix/77699 - Duplicate Expense Cards Appear in Report When Adding a Single Expense from Empty State
2 parents 68d90e4 + 824bb27 commit c8e05f1

3 files changed

Lines changed: 20 additions & 19 deletions

File tree

src/libs/actions/Transaction.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,23 @@ function changeTransactionsReport(
823823
const oldReportID = isUnreportedExpense ? CONST.REPORT.UNREPORTED_REPORT_ID : transaction.reportID;
824824
const oldReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${oldReportID}`];
825825

826+
const isUnreported = reportID === CONST.REPORT.UNREPORTED_REPORT_ID;
827+
const optimisticMoneyRequestReportActionID = rand64();
828+
829+
const originalMessage = getOriginalMessage(oldIOUAction) as OriginalMessageIOU;
830+
const newIOUAction = {
831+
...oldIOUAction,
832+
originalMessage: {
833+
...originalMessage,
834+
IOUReportID: reportID,
835+
type: isUnreported ? CONST.IOU.REPORT_ACTION_TYPE.TRACK : CONST.IOU.REPORT_ACTION_TYPE.CREATE,
836+
},
837+
reportActionID: optimisticMoneyRequestReportActionID,
838+
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
839+
actionName: oldIOUAction?.actionName ?? CONST.REPORT.ACTIONS.TYPE.MOVED_TRANSACTION,
840+
created: oldIOUAction?.created ?? DateUtils.getDBTime(),
841+
};
842+
826843
// 1. Optimistically change the reportID on the passed transactions
827844
optimisticData.push({
828845
onyxMethod: Onyx.METHOD.MERGE,
@@ -832,6 +849,7 @@ function changeTransactionsReport(
832849
comment: {
833850
hold: null,
834851
},
852+
...(oldIOUAction ? {linkedTrackedExpenseReportAction: newIOUAction} : {}),
835853
},
836854
});
837855

@@ -940,7 +958,6 @@ function changeTransactionsReport(
940958
const allowNegative = shouldEnableNegative(newReport);
941959

942960
// 3. Keep track of the new report totals
943-
const isUnreported = reportID === CONST.REPORT.UNREPORTED_REPORT_ID;
944961
const targetReportID = isUnreported ? selfDMReportID : reportID;
945962
const {amount: transactionAmount = 0, currency: transactionCurrency} = getTransactionDetails(transaction, undefined, undefined, allowNegative) ?? {};
946963
const oldReportTotal = oldReport?.total ?? 0;
@@ -974,22 +991,6 @@ function changeTransactionsReport(
974991
}
975992

976993
// 4. Optimistically update the IOU action reportID
977-
const optimisticMoneyRequestReportActionID = rand64();
978-
979-
const originalMessage = getOriginalMessage(oldIOUAction) as OriginalMessageIOU;
980-
const newIOUAction = {
981-
...oldIOUAction,
982-
originalMessage: {
983-
...originalMessage,
984-
IOUReportID: reportID,
985-
type: isUnreported ? CONST.IOU.REPORT_ACTION_TYPE.TRACK : CONST.IOU.REPORT_ACTION_TYPE.CREATE,
986-
},
987-
reportActionID: optimisticMoneyRequestReportActionID,
988-
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
989-
actionName: oldIOUAction?.actionName ?? CONST.REPORT.ACTIONS.TYPE.MOVED_TRANSACTION,
990-
created: oldIOUAction?.created ?? DateUtils.getDBTime(),
991-
};
992-
993994
const trackExpenseActionableWhisper = isUnreportedExpense ? getTrackExpenseActionableWhisper(transaction.transactionID, selfDMReportID) : undefined;
994995

995996
if (oldIOUAction) {

src/pages/Search/SearchMoneyRequestReportPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ function SearchMoneyRequestReportPage({route}: SearchMoneyRequestPageProps) {
157157
}
158158

159159
const iouAction = getIOUActionForTransactionID(reportActions, transaction.transactionID);
160-
if (iouAction || transaction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
160+
if (iouAction || transaction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD || !!transaction.linkedTrackedExpenseReportAction?.childReportID) {
161161
return;
162162
}
163163

src/pages/home/ReportScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ function ReportScreen({route, navigation, isInSidePanel = false}: ReportScreenPr
903903
// - IOU action already exists (not a legacy transaction)
904904
// - Transaction is pending addition (new transaction, not legacy)
905905
const iouAction = getIOUActionForReportID(reportID, transaction.transactionID);
906-
if (iouAction || transaction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
906+
if (iouAction || transaction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD || !!transaction.linkedTrackedExpenseReportAction?.childReportID) {
907907
return;
908908
}
909909

0 commit comments

Comments
 (0)