From 2bee2ce741923e393503f29d3e0af87a342bc420 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 8 May 2025 00:21:03 +0700 Subject: [PATCH 1/6] After deleting tax rate, tax no longer valid is displayed but tax rate is not shown --- src/libs/TransactionUtils/index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libs/TransactionUtils/index.ts b/src/libs/TransactionUtils/index.ts index e43306352be4..2b6074ba8e20 100644 --- a/src/libs/TransactionUtils/index.ts +++ b/src/libs/TransactionUtils/index.ts @@ -1248,7 +1248,14 @@ function getWorkspaceTaxesSettingsName(policy: OnyxEntry, taxCode: strin */ function getTaxName(policy: OnyxEntry, transaction: OnyxEntry) { const defaultTaxCode = getDefaultTaxCode(policy, transaction); - return Object.values(transformedTaxRates(policy, transaction)).find((taxRate) => taxRate.code === (transaction?.taxCode ?? defaultTaxCode))?.modifiedName; + const taxName = Object.values(transformedTaxRates(policy, transaction)).find((taxRate) => taxRate.code === (transaction?.taxCode ?? defaultTaxCode))?.modifiedName; + if (taxName) { + return taxName; + } + if (transaction?.taxCode) { + return 'Deleted tax'; + } + return undefined; } function getTransaction(transactionID: string | number | undefined): OnyxEntry { From e5a3f913864085a1627131f26c3373a1af8c8e72 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 30 Jul 2025 16:07:57 +0700 Subject: [PATCH 2/6] show the deleted tax value --- src/components/ReportActionItem/MoneyRequestView.tsx | 4 +++- src/libs/TransactionUtils/index.ts | 9 +-------- src/libs/Violations/ViolationsUtils.ts | 10 ++++++++++ src/libs/actions/IOU.ts | 3 ++- src/types/onyx/Transaction.ts | 3 +++ 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 6981a7158c24..e450c8ed1d0a 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -195,6 +195,8 @@ function MoneyRequestView({allReports, report, policy, shouldShowAnimatedBackgro const taxRatesDescription = taxRates?.name; const taxRateTitle = updatedTransaction ? getTaxName(policy, updatedTransaction) : getTaxName(policy, transaction); + const fallbackRateTitle = transaction?.taxValue; + const isSettled = isSettledReportUtils(moneyRequestReport?.reportID); const isCancelled = moneyRequestReport && moneyRequestReport?.isCancelledIOU; const isChatReportArchived = useReportIsArchived(moneyRequestReport?.chatReportID); @@ -759,7 +761,7 @@ function MoneyRequestView({allReports, report, policy, shouldShowAnimatedBackgro {shouldShowTax && ( , taxCode: strin */ function getTaxName(policy: OnyxEntry, transaction: OnyxEntry) { const defaultTaxCode = getDefaultTaxCode(policy, transaction); - const taxName = Object.values(transformedTaxRates(policy, transaction)).find((taxRate) => taxRate.code === (transaction?.taxCode ?? defaultTaxCode))?.modifiedName; - if (taxName) { - return taxName; - } - if (transaction?.taxCode) { - return 'Deleted tax'; - } - return undefined; + return Object.values(transformedTaxRates(policy, transaction)).find((taxRate) => taxRate.code === (transaction?.taxCode ?? defaultTaxCode))?.modifiedName; } function getTransactionOrDraftTransaction(transactionID: string): OnyxEntry { diff --git a/src/libs/Violations/ViolationsUtils.ts b/src/libs/Violations/ViolationsUtils.ts index 5f1f5c5503b1..0a4ffc605f07 100644 --- a/src/libs/Violations/ViolationsUtils.ts +++ b/src/libs/Violations/ViolationsUtils.ts @@ -286,6 +286,9 @@ const ViolationsUtils = { const hasOverLimitViolation = transactionViolations.some((violation) => violation.name === CONST.VIOLATIONS.OVER_LIMIT); const hasCategoryOverLimitViolation = transactionViolations.some((violation) => violation.name === CONST.VIOLATIONS.OVER_CATEGORY_LIMIT); const hasMissingCommentViolation = transactionViolations.some((violation) => violation.name === CONST.VIOLATIONS.MISSING_COMMENT); + const hasTaxOutOfPolicyViolation = transactionViolations.some((violation) => violation.name === CONST.VIOLATIONS.TAX_OUT_OF_POLICY); + const isTaxInPolicy = Object.keys(policy.taxRates?.taxes ?? {}).some((key) => key === updatedTransaction.taxCode); + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const amount = updatedTransaction.modifiedAmount || updatedTransaction.amount; // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing @@ -391,6 +394,13 @@ const ViolationsUtils = { newTransactionViolations = reject(newTransactionViolations, {name: CONST.VIOLATIONS.MISSING_COMMENT}); } + if (!hasTaxOutOfPolicyViolation && !isTaxInPolicy) { + newTransactionViolations.push({name: CONST.VIOLATIONS.TAX_OUT_OF_POLICY, type: CONST.VIOLATION_TYPES.VIOLATION}); + } + + if (hasTaxOutOfPolicyViolation && isTaxInPolicy) { + newTransactionViolations = reject(newTransactionViolations, {name: CONST.VIOLATIONS.TAX_OUT_OF_POLICY}); + } return { onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${updatedTransaction.transactionID}`, diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index c9fbd966312e..ff801ebbcf28 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -4329,6 +4329,7 @@ function getUpdateMoneyRequestParams( }); } const hasModifiedComment = 'comment' in transactionChanges; + const hasModifiedTaxCode = 'taxCode' in transactionChanges; const isInvoice = isInvoiceReportReportUtils(iouReport); if ( @@ -4336,7 +4337,7 @@ function getUpdateMoneyRequestParams( isPaidGroupPolicy(policy) && !isInvoice && updatedTransaction && - (hasModifiedTag || hasModifiedCategory || hasModifiedComment || hasModifiedDistanceRate || hasModifiedAmount || hasModifiedCreated) + (hasModifiedTag || hasModifiedCategory || hasModifiedComment || hasModifiedDistanceRate || hasModifiedAmount || hasModifiedCreated || hasModifiedTaxCode) ) { const currentTransactionViolations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`] ?? []; const violationsOnyxData = ViolationsUtils.getViolationsOnyxData( diff --git a/src/types/onyx/Transaction.ts b/src/types/onyx/Transaction.ts index 0ca2909fcd4a..38459cad2539 100644 --- a/src/types/onyx/Transaction.ts +++ b/src/types/onyx/Transaction.ts @@ -406,6 +406,9 @@ type Transaction = OnyxCommon.OnyxValueWithOfflineFeedback< /** The transaction tax code */ taxCode?: string; + /** The transaction tax value */ + taxValue?: string | undefined; + /** Whether the expense is billable */ billable?: boolean; From 8789166e493d2de544e19bb15fdbc36c7cc92d3e Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 30 Jul 2025 16:23:52 +0700 Subject: [PATCH 3/6] update isPolicyTrackTaxEnabled --- src/libs/Violations/ViolationsUtils.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libs/Violations/ViolationsUtils.ts b/src/libs/Violations/ViolationsUtils.ts index 0a4ffc605f07..f8055f3f6142 100644 --- a/src/libs/Violations/ViolationsUtils.ts +++ b/src/libs/Violations/ViolationsUtils.ts @@ -287,6 +287,7 @@ const ViolationsUtils = { const hasCategoryOverLimitViolation = transactionViolations.some((violation) => violation.name === CONST.VIOLATIONS.OVER_CATEGORY_LIMIT); const hasMissingCommentViolation = transactionViolations.some((violation) => violation.name === CONST.VIOLATIONS.MISSING_COMMENT); const hasTaxOutOfPolicyViolation = transactionViolations.some((violation) => violation.name === CONST.VIOLATIONS.TAX_OUT_OF_POLICY); + const isPolicyTrackTaxEnabled = !!policy?.tax?.trackingEnabled; const isTaxInPolicy = Object.keys(policy.taxRates?.taxes ?? {}).some((key) => key === updatedTransaction.taxCode); // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing @@ -394,11 +395,11 @@ const ViolationsUtils = { newTransactionViolations = reject(newTransactionViolations, {name: CONST.VIOLATIONS.MISSING_COMMENT}); } - if (!hasTaxOutOfPolicyViolation && !isTaxInPolicy) { + if (isPolicyTrackTaxEnabled && !hasTaxOutOfPolicyViolation && !isTaxInPolicy) { newTransactionViolations.push({name: CONST.VIOLATIONS.TAX_OUT_OF_POLICY, type: CONST.VIOLATION_TYPES.VIOLATION}); } - if (hasTaxOutOfPolicyViolation && isTaxInPolicy) { + if (isPolicyTrackTaxEnabled && hasTaxOutOfPolicyViolation && isTaxInPolicy) { newTransactionViolations = reject(newTransactionViolations, {name: CONST.VIOLATIONS.TAX_OUT_OF_POLICY}); } return { From 369ec071b8498cde179763caef892b580dcaa433 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Tue, 5 Aug 2025 10:34:22 +0700 Subject: [PATCH 4/6] lint fix --- src/libs/DebugUtils.ts | 2 ++ src/libs/actions/IOU.ts | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libs/DebugUtils.ts b/src/libs/DebugUtils.ts index 5f4953431f54..4cc3202dd07a 100644 --- a/src/libs/DebugUtils.ts +++ b/src/libs/DebugUtils.ts @@ -943,6 +943,7 @@ function validateTransactionDraftProperty(key: keyof Transaction, value: string) case 'bank': case 'cardName': case 'cardNumber': + case 'taxValue': return validateString(value); case 'created': case 'modifiedCreated': @@ -1080,6 +1081,7 @@ function validateTransactionDraftProperty(key: keyof Transaction, value: string) accountant: CONST.RED_BRICK_ROAD_PENDING_ACTION, splitExpenses: CONST.RED_BRICK_ROAD_PENDING_ACTION, isDemoTransaction: CONST.RED_BRICK_ROAD_PENDING_ACTION, + taxValue: CONST.RED_BRICK_ROAD_PENDING_ACTION, }, 'string', ); diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 55a07d77a8a6..6147b783c38e 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -4340,7 +4340,15 @@ function getUpdateMoneyRequestParams( isPaidGroupPolicy(policy) && !isInvoice && updatedTransaction && - (hasModifiedTag || hasModifiedCategory || hasModifiedComment || hasModifiedDistanceRate || hasModifiedDate || hasModifiedCurrency || hasModifiedAmount || hasModifiedCreated || hasModifiedTaxCode) + (hasModifiedTag || + hasModifiedCategory || + hasModifiedComment || + hasModifiedDistanceRate || + hasModifiedDate || + hasModifiedCurrency || + hasModifiedAmount || + hasModifiedCreated || + hasModifiedTaxCode) ) { const currentTransactionViolations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`] ?? []; // 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 From a86a11d9a67cd44a7bd40c636e1e7e8db2e8bfb9 Mon Sep 17 00:00:00 2001 From: nkdengineer <161821005+nkdengineer@users.noreply.github.com> Date: Thu, 7 Aug 2025 10:00:03 +0700 Subject: [PATCH 5/6] Update src/components/ReportActionItem/MoneyRequestView.tsx Co-authored-by: Dominic <165644294+dominictb@users.noreply.github.com> --- src/components/ReportActionItem/MoneyRequestView.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 6f2d69e10852..ba4f883d6168 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -196,7 +196,7 @@ function MoneyRequestView({allReports, report, policy, shouldShowAnimatedBackgro const taxRatesDescription = taxRates?.name; const taxRateTitle = updatedTransaction ? getTaxName(policy, updatedTransaction) : getTaxName(policy, transaction); - const fallbackRateTitle = transaction?.taxValue; + const fallbackTaxRateTitle = transaction?.taxValue; const isSettled = isSettledReportUtils(moneyRequestReport?.reportID); const isCancelled = moneyRequestReport && moneyRequestReport?.isCancelledIOU; From 9bb63db67ede0da0303e9daa418bd1af493aad64 Mon Sep 17 00:00:00 2001 From: nkdengineer <161821005+nkdengineer@users.noreply.github.com> Date: Thu, 7 Aug 2025 10:00:19 +0700 Subject: [PATCH 6/6] Update src/components/ReportActionItem/MoneyRequestView.tsx Co-authored-by: Dominic <165644294+dominictb@users.noreply.github.com> --- src/components/ReportActionItem/MoneyRequestView.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index ba4f883d6168..273f7581f08c 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -778,7 +778,7 @@ function MoneyRequestView({allReports, report, policy, shouldShowAnimatedBackgro {shouldShowTax && (