Skip to content

Commit

Permalink
Build optimistic receipt for distance split, and move it inside optim…
Browse files Browse the repository at this point in the history
…istic transaction function
  • Loading branch information
neil-marcellini committed Jul 2, 2024
1 parent 261d191 commit 29a01f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/libs/TransactionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ function buildOptimisticTransaction(
merchant: merchant || CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT,
created: created || DateUtils.getDBTime(),
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
receipt,
filename,
receipt: receipt?.source ? {source: receipt.source, state: receipt.state ?? CONST.IOU.RECEIPT_STATE.SCANREADY} : {},
filename: receipt?.source ?? receipt?.name ?? filename,
category,
tag,
taxCode,
Expand Down
19 changes: 8 additions & 11 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1955,14 +1955,8 @@ function getMoneyRequestInformation(
} else {
iouReport = IOUUtils.updateIOUOwnerAndTotal(iouReport, payeeAccountID, amount, currency);
}
// STEP 3: Build optimistic receipt and transaction
const receiptObject: Receipt = {};
let filename;
if (receipt?.source) {
receiptObject.source = receipt.source;
receiptObject.state = receipt.state ?? CONST.IOU.RECEIPT_STATE.SCANREADY;
filename = receipt.name;
}

// STEP 3: Build an optimistic transaction with the receipt
const existingTransaction = allTransactionDrafts[`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${existingTransactionID ?? CONST.IOU.OPTIMISTIC_TRANSACTION_ID}`];
const isDistanceRequest = existingTransaction && existingTransaction.iouRequestType === CONST.IOU.REQUEST_TYPE.DISTANCE;
let optimisticTransaction = TransactionUtils.buildOptimisticTransaction(
Expand All @@ -1974,8 +1968,8 @@ function getMoneyRequestInformation(
'',
'',
merchant,
receiptObject,
filename,
receipt,
'',
existingTransactionID,
category,
tag,
Expand Down Expand Up @@ -3758,6 +3752,9 @@ function createSplitsAndOnyxData(
const {splitChatReport, existingSplitChatReport} = getOrCreateOptimisticSplitChatReport(existingSplitChatReportID, participants, participantAccountIDs, currentUserAccountID);
const isOwnPolicyExpenseChat = !!splitChatReport.isOwnPolicyExpenseChat;

// Pass an open receipt so the distance expense will show a map with the route optimistically
const receipt: Receipt|undefined = (iouRequestType === CONST.IOU.REQUEST_TYPE.DISTANCE) ? {source: ReceiptGeneric as ReceiptSource, state: CONST.IOU.RECEIPT_STATE.OPEN} : undefined;

const splitTransaction = TransactionUtils.buildOptimisticTransaction(
amount,
currency,
Expand All @@ -3767,7 +3764,7 @@ function createSplitsAndOnyxData(
'',
'',
merchant || Localize.translateLocal('iou.expense'),
undefined,
receipt,
undefined,
undefined,
category,
Expand Down

0 comments on commit 29a01f3

Please sign in to comment.