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

(cherry picked from commit 09bcd1e)
  • Loading branch information
lakchote authored and OSBotify committed Apr 5, 2024
1 parent fc9b9f8 commit 2b8dc25
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 @@ -2778,7 +2778,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 2b8dc25

Please sign in to comment.