Skip to content

Commit

Permalink
Merge pull request #39638 from Expensify/monil-fixCrashWithZeroTax
Browse files Browse the repository at this point in the history
[CP Staging] Fix crash with zero tax rate and allow tax amount to be zero

(cherry picked from commit 07326c4)
  • Loading branch information
jasperhuangg authored and OSBotify committed Apr 4, 2024
1 parent f4f2cb1 commit 040cbff
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import * as MoneyRequestUtils from '@libs/MoneyRequestUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as PolicyUtils from '@libs/PolicyUtils';
import {isTaxPolicyEnabled} from '@libs/PolicyUtils';
import {isTaxTrackingEnabled} from '@libs/PolicyUtils';
import * as ReceiptUtils from '@libs/ReceiptUtils';
import * as ReportUtils from '@libs/ReportUtils';
import playSound, {SOUNDS} from '@libs/Sound';
Expand Down Expand Up @@ -284,7 +284,7 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
const shouldShowTags = useMemo(() => isPolicyExpenseChat && OptionsListUtils.hasEnabledTags(policyTagLists), [isPolicyExpenseChat, policyTagLists]);

// A flag for showing tax rate
const shouldShowTax = isTaxPolicyEnabled(isPolicyExpenseChat, policy);
const shouldShowTax = isTaxTrackingEnabled(isPolicyExpenseChat, policy);

// A flag for showing the billable field
const shouldShowBillable = !lodashGet(policy, 'disabledFields.defaultBillable', true);
Expand Down
6 changes: 3 additions & 3 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import * as CardUtils from '@libs/CardUtils';
import * as CurrencyUtils from '@libs/CurrencyUtils';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as PolicyUtils from '@libs/PolicyUtils';
import {isTaxPolicyEnabled} from '@libs/PolicyUtils';
import {isTaxTrackingEnabled} from '@libs/PolicyUtils';
import * as ReceiptUtils from '@libs/ReceiptUtils';
import * as ReportUtils from '@libs/ReportUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
Expand Down Expand Up @@ -123,7 +123,7 @@ function MoneyRequestView({
const cardProgramName = isCardTransaction && transactionCardID !== undefined ? CardUtils.getCardDescription(transactionCardID) : '';
const isApproved = ReportUtils.isReportApproved(moneyRequestReport);
const taxRates = policy?.taxRates;
const formattedTaxAmount = transactionTaxAmount ? CurrencyUtils.convertToDisplayString(transactionTaxAmount, transactionCurrency) : '';
const formattedTaxAmount = CurrencyUtils.convertToDisplayString(transactionTaxAmount, transactionCurrency);

const taxRatesDescription = taxRates?.name;
const taxRateTitle =
Expand Down Expand Up @@ -160,7 +160,7 @@ function MoneyRequestView({
const shouldShowBillable = isPolicyExpenseChat && (!!transactionBillable || !(policy?.disabledFields?.defaultBillable ?? true));

// A flag for showing tax rate
const shouldShowTax = isTaxPolicyEnabled(isPolicyExpenseChat, policy) && transactionTaxCode && transactionTaxAmount;
const shouldShowTax = isTaxTrackingEnabled(isPolicyExpenseChat, policy);

const {getViolationsForField} = useViolations(transactionViolations ?? []);
const hasViolations = useCallback(
Expand Down
4 changes: 2 additions & 2 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ function isPaidGroupPolicy(policy: OnyxEntry<Policy> | EmptyObject): boolean {
return policy?.type === CONST.POLICY.TYPE.TEAM || policy?.type === CONST.POLICY.TYPE.CORPORATE;
}

function isTaxPolicyEnabled(isPolicyExpenseChat: boolean, policy: OnyxEntry<Policy>): boolean {
function isTaxTrackingEnabled(isPolicyExpenseChat: boolean, policy: OnyxEntry<Policy>): boolean {
return (isPolicyExpenseChat && (policy?.tax?.trackingEnabled ?? policy?.isTaxTrackingEnabled)) ?? false;
}

Expand Down Expand Up @@ -332,7 +332,7 @@ export {
isInstantSubmitEnabled,
isFreeGroupPolicy,
isPolicyAdmin,
isTaxPolicyEnabled,
isTaxTrackingEnabled,
isSubmitAndClose,
getMemberAccountIDsForWorkspace,
getIneligibleInvitees,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/EditRequestPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as IOUUtils from '@libs/IOUUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as PolicyUtils from '@libs/PolicyUtils';
import {isTaxPolicyEnabled} from '@libs/PolicyUtils';
import {isTaxTrackingEnabled} from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import * as IOU from '@userActions/IOU';
Expand Down Expand Up @@ -106,7 +106,7 @@ function EditRequestPage({report, route, policy, policyCategories, policyTags, p
const shouldShowTags = useMemo(() => isPolicyExpenseChat && (transactionTag || OptionsListUtils.hasEnabledTags(policyTagLists)), [isPolicyExpenseChat, policyTagLists, transactionTag]);

// A flag for showing tax rate
const shouldShowTax = isTaxPolicyEnabled(isPolicyExpenseChat, policy);
const shouldShowTax = isTaxTrackingEnabled(isPolicyExpenseChat, policy);

// Decides whether to allow or disallow editing a money request
useEffect(() => {
Expand Down
3 changes: 2 additions & 1 deletion src/pages/iou/steps/MoneyRequestAmountForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ function MoneyRequestAmountForm(
* Submit amount and navigate to a proper page
*/
const submitAndNavigateToNextPage = useCallback(() => {
if (isAmountInvalid(currentAmount)) {
// Skip the check for tax amount form as 0 is a valid input
if (!isTaxAmountForm && isAmountInvalid(currentAmount)) {
setFormError('iou.error.invalidAmount');
return;
}
Expand Down

0 comments on commit 040cbff

Please sign in to comment.