Skip to content

Commit

Permalink
Merge pull request #39707 from Expensify/monil-fixCrashWhenTaxRateDel…
Browse files Browse the repository at this point in the history
…eted

[CP Staging] Fix crash when tax rate is deleted
  • Loading branch information
lakchote authored Apr 5, 2024
2 parents 54db9cc + 17c39e4 commit 09bcd1e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2783,7 +2783,7 @@ function getModifiedExpenseOriginalMessage(
}

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

Expand Down
8 changes: 4 additions & 4 deletions src/libs/TransactionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,17 +625,17 @@ function getEnabledTaxRateCount(options: TaxRates) {
*/
function getDefaultTaxName(taxRates: TaxRatesWithDefault, transaction?: Transaction) {
const defaultTaxKey = taxRates.defaultExternalID;
const defaultTaxName = (defaultTaxKey && `${taxRates.taxes[defaultTaxKey].name} (${taxRates.taxes[defaultTaxKey].value}) • ${Localize.translateLocal('common.default')}`) || '';
const defaultTaxName = (defaultTaxKey && `${taxRates.taxes[defaultTaxKey]?.name} (${taxRates.taxes[defaultTaxKey]?.value}) • ${Localize.translateLocal('common.default')}`) || '';
return transaction?.taxRate?.text ?? defaultTaxName;
}

/**
* Gets the tax name
*/
function getTaxName(taxes: TaxRates, transactionTaxCode: string) {
const taxName = `${taxes[transactionTaxCode].name}`;
const taxValue = `${taxes[transactionTaxCode].value}`;
return transactionTaxCode ? `${taxName} (${taxValue})` : '';
const taxName = taxes[transactionTaxCode]?.name ?? '';
const taxValue = taxes[transactionTaxCode]?.value ?? '';
return transactionTaxCode && taxName && taxValue ? `${taxName} (${taxValue})` : '';
}

export {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/EditRequestPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const defaultProps = {
};

const getTaxAmount = (transactionAmount, transactionTaxCode, taxRates) => {
const percentage = (transactionTaxCode ? taxRates.taxes[transactionTaxCode].value : taxRates.defaultValue) || '';
const percentage = (transactionTaxCode && taxRates.taxes[transactionTaxCode] ? taxRates.taxes[transactionTaxCode].value : taxRates.defaultValue) || '';
return CurrencyUtils.convertToBackendAmount(Number.parseFloat(TransactionUtils.calculateTaxAmount(percentage, transactionAmount)));
};

Expand Down

0 comments on commit 09bcd1e

Please sign in to comment.