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 all commits
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
23 changes: 18 additions & 5 deletions src/libs/TransactionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,26 @@ 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;
const amount = lodashGet(transaction, 'modifiedAmount', 0);
// 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
let amount = lodashGet(transaction, 'modifiedAmount', 0);
if (amount) {
return multiplier * amount;
return -amount;
}
return multiplier * lodashGet(transaction, 'amount', 0);

// To avoid -0 being shown, lets only change the sign if the value is other than 0.
amount = lodashGet(transaction, 'amount', 0);
return amount ? -amount : 0;
}

/**
Expand Down