Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CP Staging] Fix the negative amounts showing in IOU reports #25407

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Changes from 1 commit
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
18 changes: 14 additions & 4 deletions src/libs/TransactionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,23 @@ function getDescription(transaction) {
* @returns {Number}
*/
function getAmount(transaction, isFromExpenseReport) {
// In case of expense reports, the amounts are stored using an opposite sign
const multiplier = isFromExpenseReport ? -1 : 1;
// IOU requests cannot have negative values but they can be stored as negative values, let's return absolute value
if (!isFromExpenseReport) {
const amount = lodashGet(transaction, 'modifiedAmount', 0);
if (amount) {
return Math.abs(amount);
}
return Math.abs(lodashGet(transaction, 'amount', 0));
}

// Expense report case:
// The amounts are stored using an opposite sign and negative values can be set,
// we need to return an opposite sign than is saved in the transaction object
const amount = lodashGet(transaction, 'modifiedAmount', 0);
if (amount) {
return multiplier * amount;
return -amount;
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
}
return multiplier * lodashGet(transaction, 'amount', 0);
return -lodashGet(transaction, 'amount', 0);
}

/**
Expand Down