diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index d3195193c742..d86323cf915e 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -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); @@ -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();