Skip to content

Commit 4d73ec6

Browse files
authored
Merge pull request Expensify#61602 from nkdengineer/fix/61134
After deleting tax rate, tax no longer valid is displayed but tax rate is not shown
2 parents 2c1e107 + c764fc3 commit 4d73ec6

5 files changed

Lines changed: 29 additions & 2 deletions

File tree

src/components/ReportActionItem/MoneyRequestView.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ function MoneyRequestView({allReports, report, policy, shouldShowAnimatedBackgro
196196
const taxRatesDescription = taxRates?.name;
197197
const taxRateTitle = updatedTransaction ? getTaxName(policy, updatedTransaction) : getTaxName(policy, transaction);
198198

199+
const fallbackTaxRateTitle = transaction?.taxValue;
200+
199201
const isSettled = isSettledReportUtils(moneyRequestReport?.reportID);
200202
const isCancelled = moneyRequestReport && moneyRequestReport?.isCancelledIOU;
201203
const isChatReportArchived = useReportIsArchived(moneyRequestReport?.chatReportID);
@@ -776,7 +778,7 @@ function MoneyRequestView({allReports, report, policy, shouldShowAnimatedBackgro
776778
{shouldShowTax && (
777779
<OfflineWithFeedback pendingAction={getPendingFieldAction('taxCode')}>
778780
<MenuItemWithTopDescription
779-
title={taxRateTitle ?? ''}
781+
title={taxRateTitle ?? fallbackTaxRateTitle}
780782
description={taxRatesDescription}
781783
interactive={canEditTaxFields}
782784
shouldShowRightIcon={canEditTaxFields}

src/libs/DebugUtils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,7 @@ function validateTransactionDraftProperty(key: keyof Transaction, value: string)
943943
case 'bank':
944944
case 'cardName':
945945
case 'cardNumber':
946+
case 'taxValue':
946947
return validateString(value);
947948
case 'created':
948949
case 'modifiedCreated':
@@ -1080,6 +1081,7 @@ function validateTransactionDraftProperty(key: keyof Transaction, value: string)
10801081
accountant: CONST.RED_BRICK_ROAD_PENDING_ACTION,
10811082
splitExpenses: CONST.RED_BRICK_ROAD_PENDING_ACTION,
10821083
isDemoTransaction: CONST.RED_BRICK_ROAD_PENDING_ACTION,
1084+
taxValue: CONST.RED_BRICK_ROAD_PENDING_ACTION,
10831085
},
10841086
'string',
10851087
);

src/libs/Violations/ViolationsUtils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ const ViolationsUtils = {
304304
// const hasOverTripLimitViolation = transactionViolations.some((violation) => violation.name === CONST.VIOLATIONS.OVER_TRIP_LIMIT);
305305
const hasCategoryOverLimitViolation = transactionViolations.some((violation) => violation.name === CONST.VIOLATIONS.OVER_CATEGORY_LIMIT);
306306
const hasMissingCommentViolation = transactionViolations.some((violation) => violation.name === CONST.VIOLATIONS.MISSING_COMMENT);
307+
const hasTaxOutOfPolicyViolation = transactionViolations.some((violation) => violation.name === CONST.VIOLATIONS.TAX_OUT_OF_POLICY);
308+
const isPolicyTrackTaxEnabled = !!policy?.tax?.trackingEnabled;
309+
const isTaxInPolicy = Object.keys(policy.taxRates?.taxes ?? {}).some((key) => key === updatedTransaction.taxCode);
310+
307311
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
308312
const amount = updatedTransaction.modifiedAmount || updatedTransaction.amount;
309313
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
@@ -425,6 +429,13 @@ const ViolationsUtils = {
425429
newTransactionViolations = reject(newTransactionViolations, {name: CONST.VIOLATIONS.MISSING_COMMENT});
426430
}
427431

432+
if (isPolicyTrackTaxEnabled && !hasTaxOutOfPolicyViolation && !isTaxInPolicy) {
433+
newTransactionViolations.push({name: CONST.VIOLATIONS.TAX_OUT_OF_POLICY, type: CONST.VIOLATION_TYPES.VIOLATION});
434+
}
435+
436+
if (isPolicyTrackTaxEnabled && hasTaxOutOfPolicyViolation && isTaxInPolicy) {
437+
newTransactionViolations = reject(newTransactionViolations, {name: CONST.VIOLATIONS.TAX_OUT_OF_POLICY});
438+
}
428439
return {
429440
onyxMethod: Onyx.METHOD.SET,
430441
key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${updatedTransaction.transactionID}`,

src/libs/actions/IOU.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4338,6 +4338,7 @@ function getUpdateMoneyRequestParams(
43384338

43394339
const hasModifiedCurrency = 'currency' in transactionChanges;
43404340
const hasModifiedComment = 'comment' in transactionChanges;
4341+
const hasModifiedTaxCode = 'taxCode' in transactionChanges;
43414342
const hasModifiedDate = 'date' in transactionChanges;
43424343

43434344
const isInvoice = isInvoiceReportReportUtils(iouReport);
@@ -4346,7 +4347,15 @@ function getUpdateMoneyRequestParams(
43464347
isPaidGroupPolicy(policy) &&
43474348
!isInvoice &&
43484349
updatedTransaction &&
4349-
(hasModifiedTag || hasModifiedCategory || hasModifiedComment || hasModifiedDistanceRate || hasModifiedDate || hasModifiedCurrency || hasModifiedAmount || hasModifiedCreated)
4350+
(hasModifiedTag ||
4351+
hasModifiedCategory ||
4352+
hasModifiedComment ||
4353+
hasModifiedDistanceRate ||
4354+
hasModifiedDate ||
4355+
hasModifiedCurrency ||
4356+
hasModifiedAmount ||
4357+
hasModifiedCreated ||
4358+
hasModifiedTaxCode)
43504359
) {
43514360
const currentTransactionViolations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`] ?? [];
43524361
// If the amount, currency or date have been modified, we remove the duplicate violations since they would be out of date as the transaction has changed

src/types/onyx/Transaction.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,9 @@ type Transaction = OnyxCommon.OnyxValueWithOfflineFeedback<
406406
/** The transaction tax code */
407407
taxCode?: string;
408408

409+
/** The transaction tax value */
410+
taxValue?: string | undefined;
411+
409412
/** Whether the expense is billable */
410413
billable?: boolean;
411414

0 commit comments

Comments
 (0)