diff --git a/src/libs/TransactionUtils.js b/src/libs/TransactionUtils.js index a8fd828d07d4..06ad190048c3 100644 --- a/src/libs/TransactionUtils.js +++ b/src/libs/TransactionUtils.js @@ -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; } /**