Skip to content

Commit

Permalink
Merge pull request #25407 from Expensify/vit-fix24623
Browse files Browse the repository at this point in the history
[CP Staging] Fix the negative amounts showing in IOU reports
  • Loading branch information
luacmartins authored Aug 17, 2023
2 parents e89ea9d + 0acfcb7 commit 9474292
Showing 1 changed file with 18 additions and 5 deletions.
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

0 comments on commit 9474292

Please sign in to comment.