Skip to content

Commit

Permalink
Fix system messages to only cover direct update
Browse files Browse the repository at this point in the history
  • Loading branch information
MonilBhavsar committed May 14, 2024
1 parent fa95dbb commit 34b27f7
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2982,7 +2982,8 @@ function getModifiedExpenseOriginalMessage(

// The amount is always a combination of the currency and the number value so when one changes we need to store both
// to match how we handle the modified expense action in oldDot
if ('amount' in transactionChanges || 'currency' in transactionChanges) {
const didAmountOrCurrencyChange = 'amount' in transactionChanges || 'currency' in transactionChanges;
if (didAmountOrCurrencyChange) {
originalMessage.oldAmount = TransactionUtils.getAmount(oldTransaction, isFromExpenseReport);
originalMessage.amount = transactionChanges?.amount ?? transactionChanges.oldAmount;
originalMessage.oldCurrency = TransactionUtils.getCurrency(oldTransaction);
Expand All @@ -2999,19 +3000,22 @@ function getModifiedExpenseOriginalMessage(
originalMessage.tag = transactionChanges?.tag;
}

// We only want to display a tax rate update system message when tax rate is updated by user.
// Tax rate can change as a result of currency update. In such cases, we want to skip displaying a system message, as discussed.
const didTaxCodeChange = 'taxCode' in transactionChanges;
if (didTaxCodeChange && !didAmountOrCurrencyChange) {
originalMessage.oldTaxRate = policy?.taxRates?.taxes[TransactionUtils.getTaxCode(oldTransaction)]?.value;
originalMessage.taxRate = transactionChanges?.taxCode && policy?.taxRates?.taxes[transactionChanges?.taxCode].value;
}

// We only want to display a tax amount update system message when tax amount is updated by user.
// Tax amount can change as a result of amount, currency or tax rate update. In such cases, we want to skip displaying a system message, as discussed.
if ('taxAmount' in transactionChanges && !('amount' in transactionChanges || 'currency' in transactionChanges || 'taxCode' in transactionChanges)) {
if ('taxAmount' in transactionChanges && !(didAmountOrCurrencyChange || didTaxCodeChange)) {
originalMessage.oldTaxAmount = TransactionUtils.getTaxAmount(oldTransaction, isFromExpenseReport);
originalMessage.taxAmount = transactionChanges?.taxAmount;
originalMessage.currency = TransactionUtils.getCurrency(oldTransaction);
}

if ('taxCode' in transactionChanges) {
originalMessage.oldTaxRate = policy?.taxRates?.taxes[TransactionUtils.getTaxCode(oldTransaction)]?.value;
originalMessage.taxRate = transactionChanges?.taxCode && policy?.taxRates?.taxes[transactionChanges?.taxCode].value;
}

if ('billable' in transactionChanges) {
const oldBillable = TransactionUtils.getBillable(oldTransaction);
originalMessage.oldBillable = oldBillable ? Localize.translateLocal('common.billable').toLowerCase() : Localize.translateLocal('common.nonBillable').toLowerCase();
Expand Down

0 comments on commit 34b27f7

Please sign in to comment.