Skip to content

Commit

Permalink
Get category from transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
yuwenmemon committed Sep 12, 2023
1 parent 9c06510 commit 692a5ad
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,7 @@ function getTransactionDetails(transaction) {
currency: TransactionUtils.getCurrency(transaction),
comment: TransactionUtils.getDescription(transaction),
merchant: TransactionUtils.getMerchant(transaction),
category: TransactionUtils.getCategory(transaction),
};
}

Expand Down
14 changes: 11 additions & 3 deletions src/libs/TransactionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ function getUpdatedTransaction(transaction, transactionChanges, isFromExpenseRep
updatedTransaction.receipt.state = CONST.IOU.RECEIPT_STATE.OPEN;
}

// Always copy over the category for now until we have a way to edit it (Will be implemented in https://github.com/Expensify/App/issues/24464)
updatedTransaction.category = transaction.category;

updatedTransaction.pendingFields = {
...(_.has(transactionChanges, 'comment') && {comment: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}),
...(_.has(transactionChanges, 'created') && {created: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}),
Expand Down Expand Up @@ -231,6 +228,16 @@ function getMerchant(transaction) {
return lodashGet(transaction, 'modifiedMerchant', null) || lodashGet(transaction, 'merchant', '');
}

/**
* Return the category from the transaction. The "created" field has no "modified" complement.
*
* @param {Object} transaction
* @return {*}
*/
function getCategory(transaction) {
return lodashGet(transaction, 'category', null);
}

/**
* Return the created field from the transaction, return the modifiedCreated if present.
*
Expand Down Expand Up @@ -365,6 +372,7 @@ export {
getCurrency,
getMerchant,
getCreated,
getCategory,
getLinkedTransaction,
getAllReportTransactions,
hasReceipt,
Expand Down
3 changes: 2 additions & 1 deletion src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC
];

// STEP 6: Call the API endpoint
const {created, amount, currency, comment, merchant} = ReportUtils.getTransactionDetails(updatedTransaction);
const {created, amount, currency, comment, merchant, category} = ReportUtils.getTransactionDetails(updatedTransaction);
API.write(
'EditMoneyRequest',
{
Expand All @@ -1066,6 +1066,7 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC
currency,
comment,
merchant,
category,
},
{optimisticData, successData, failureData},
);
Expand Down

0 comments on commit 692a5ad

Please sign in to comment.