From 41620f408ad12cbfd2305589e42a98458181752f Mon Sep 17 00:00:00 2001 From: dominictb Date: Mon, 16 Mar 2026 20:20:38 +0700 Subject: [PATCH 1/4] add taxValue to buildOptimisticTransaction --- src/libs/ReportUtils.ts | 2 ++ src/libs/TransactionUtils/index.ts | 3 +++ src/libs/actions/IOU/SendInvoice.ts | 3 ++- src/libs/actions/IOU/Split.ts | 5 +++++ src/libs/actions/IOU/index.ts | 20 +++++++++++++++++++- 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 22eb7007262f..3b3f7c388250 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -767,6 +767,7 @@ type TransactionDetails = { attendees: Attendee[] | string; taxAmount?: number; taxCode?: string; + taxValue?: string; currency: string; merchant: string; waypoints?: WaypointCollection | string; @@ -4664,6 +4665,7 @@ function getTransactionDetails( attendees: getAttendees(transaction, currentUserDetails), taxAmount: getTaxAmount(transaction, isFromExpenseReport), taxCode: getTaxCode(transaction), + taxValue: transaction.taxValue, currency: getCurrency(transaction), comment: getDescription(transaction), merchant: getMerchant(transaction), diff --git a/src/libs/TransactionUtils/index.ts b/src/libs/TransactionUtils/index.ts index f5712fd33755..0946fc559c31 100644 --- a/src/libs/TransactionUtils/index.ts +++ b/src/libs/TransactionUtils/index.ts @@ -101,6 +101,7 @@ type TransactionParams = { tag?: string; taxCode?: string; taxAmount?: number; + taxValue?: string; billable?: boolean; pendingFields?: Partial>>; reimbursable?: boolean; @@ -437,6 +438,7 @@ function buildOptimisticTransaction(params: BuildOptimisticTransactionParams): T tag = '', taxCode = '', taxAmount = 0, + taxValue, billable = false, pendingFields, reimbursable = true, @@ -550,6 +552,7 @@ function buildOptimisticTransaction(params: BuildOptimisticTransactionParams): T tag, taxCode, taxAmount, + taxValue, modifiedAmount, billable, reimbursable, diff --git a/src/libs/actions/IOU/SendInvoice.ts b/src/libs/actions/IOU/SendInvoice.ts index 29a2c298297c..19ce3984f710 100644 --- a/src/libs/actions/IOU/SendInvoice.ts +++ b/src/libs/actions/IOU/SendInvoice.ts @@ -597,7 +597,7 @@ function getSendInvoiceInformation({ policyRecentlyUsedCategories, policyRecentlyUsedTags, }: SendInvoiceOptions): SendInvoiceInformation { - const {amount = 0, currency = '', created = '', merchant = '', category = '', tag = '', taxCode = '', taxAmount = 0, billable, comment, participants} = transaction ?? {}; + const {amount = 0, currency = '', created = '', merchant = '', category = '', tag = '', taxCode = '', taxAmount = 0, taxValue, billable, comment, participants} = transaction ?? {}; const trimmedComment = (comment?.comment ?? '').trim(); const senderWorkspaceID = participants?.find((participant) => participant?.isSender)?.policyID; const receiverParticipant: Participant | InvoiceReceiver | undefined = @@ -644,6 +644,7 @@ function getSendInvoiceInformation({ tag, taxCode, taxAmount, + taxValue, billable, reimbursable: true, }, diff --git a/src/libs/actions/IOU/Split.ts b/src/libs/actions/IOU/Split.ts index 530e6ffdfeeb..4c38f5ad2a00 100644 --- a/src/libs/actions/IOU/Split.ts +++ b/src/libs/actions/IOU/Split.ts @@ -359,6 +359,7 @@ function startSplitBill({ currency, taxCode = '', taxAmount = 0, + taxValue, shouldPlaySound = true, policyRecentlyUsedCategories, policyRecentlyUsedTags, @@ -385,6 +386,7 @@ function startSplitBill({ tag, taxCode, taxAmount, + taxValue, billable, reimbursable, }, @@ -907,6 +909,7 @@ function completeSplitBill( tag: updatedTransaction?.tag, taxCode: updatedTransaction?.taxCode, taxAmount: isPolicyExpenseChat ? -splitTaxAmount : splitAmount, + taxValue: updatedTransaction?.taxValue, billable: updatedTransaction?.billable, reimbursable: updatedTransaction?.reimbursable, source: CONST.IOU.TYPE.SPLIT, @@ -1183,6 +1186,7 @@ function updateSplitTransactions({ reimbursable: originalTransactionDetails?.reimbursable, taxCode: originalTransactionDetails?.taxCode, taxAmount: calculateIOUAmount(splitExpenses.length - 1, originalTransactionDetails?.taxAmount ?? 0, originalTransactionDetails?.currency ?? CONST.CURRENCY.USD, false), + taxValue: originalTransactionDetails?.taxValue, billable: originalTransactionDetails?.billable, waypoints: splitExpense.waypoints, customUnit: splitExpense.customUnit, @@ -1216,6 +1220,7 @@ function updateSplitTransactions({ linkedTrackedExpenseReportAction: currentReportAction, taxCode: originalTransactionDetails?.taxCode, taxAmount: calculateIOUAmount(splitExpenses.length - 1, originalTransactionDetails?.taxAmount ?? 0, originalTransactionDetails?.currency ?? CONST.CURRENCY.USD, false), + taxValue: originalTransactionDetails?.taxValue, billable: originalTransactionDetails?.billable, waypoints: splitExpense.waypoints, customUnit: splitExpense.customUnit, diff --git a/src/libs/actions/IOU/index.ts b/src/libs/actions/IOU/index.ts index 99cd0f4e1871..6dbd651283f2 100644 --- a/src/libs/actions/IOU/index.ts +++ b/src/libs/actions/IOU/index.ts @@ -278,6 +278,7 @@ type BaseTransactionParams = { tag?: string; taxCode?: string; taxAmount?: number; + taxValue?: string; billable?: boolean; reimbursable?: boolean; customUnitRateID?: string; @@ -380,13 +381,14 @@ type TrackExpenseInformation = { onyxData: OnyxData; }; -type TrackedExpenseTransactionParams = Omit & { +type TrackedExpenseTransactionParams = Omit & { waypoints?: string; distance?: number; transactionID: string | undefined; receipt?: Receipt; taxCode: string; taxAmount: number; + taxValue?: string; attendees?: Attendee[]; }; @@ -681,6 +683,7 @@ type TrackExpenseTransactionParams = { tag?: string; taxCode?: string; taxAmount?: number; + taxValue?: string; billable?: boolean; reimbursable?: boolean; validWaypoints?: WaypointCollection; @@ -736,6 +739,7 @@ type GetTrackExpenseInformationTransactionParams = { tag?: string; taxCode?: string; taxAmount?: number; + taxValue?: string; billable?: boolean; reimbursable?: boolean; linkedTrackedExpenseReportAction?: OnyxTypes.ReportAction; @@ -793,6 +797,7 @@ type StartSplitBilActionParams = { currency: string; taxCode: string; taxAmount: number; + taxValue?: string; shouldPlaySound?: boolean; policyRecentlyUsedCategories?: OnyxEntry; policyRecentlyUsedTags: OnyxEntry; @@ -3276,6 +3281,7 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma tag, taxCode, taxAmount, + taxValue, billable, reimbursable = true, linkedTrackedExpenseReportAction, @@ -3439,6 +3445,7 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma taxCode, source, taxAmount: isExpenseReport(iouReport) ? -(taxAmount ?? 0) : taxAmount, + taxValue, billable, pendingAction, pendingFields: isDistanceRequest && !isManualDistanceRequest ? {waypoints: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, ...pendingFields} : pendingFields, @@ -3706,6 +3713,7 @@ function getTrackExpenseInformation(params: GetTrackExpenseInformationParams): T tag, taxCode, taxAmount, + taxValue, billable, reimbursable, linkedTrackedExpenseReportAction, @@ -3916,6 +3924,7 @@ function getTrackExpenseInformation(params: GetTrackExpenseInformationParams): T tag, taxCode, taxAmount: taxAmount ? -taxAmount : undefined, + taxValue, billable, pendingFields: isDistanceRequest && !isManualDistanceRequest ? {waypoints: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD} : undefined, reimbursable, @@ -6630,6 +6639,7 @@ function trackExpense(params: CreateTrackExpenseParams) { tag, taxCode = '', taxAmount = 0, + taxValue, billable, reimbursable, gpsPoint, @@ -6675,6 +6685,7 @@ function trackExpense(params: CreateTrackExpenseParams) { tag, taxCode, taxAmount, + taxValue, billable, reimbursable, validWaypoints, @@ -6728,6 +6739,7 @@ function trackExpense(params: CreateTrackExpenseParams) { tag, taxCode, taxAmount, + taxValue, billable, reimbursable, linkedTrackedExpenseReportAction, @@ -7032,6 +7044,7 @@ function createSplitsAndOnyxData({ iouRequestType = CONST.IOU.REQUEST_TYPE.MANUAL, taxCode = '', taxAmount = 0, + taxValue, attendees, }, policyRecentlyUsedCategories, @@ -7069,6 +7082,7 @@ function createSplitsAndOnyxData({ tag, taxCode, taxAmount, + taxValue, billable, reimbursable, pendingFields: isDistanceRequest ? {waypoints: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD} : undefined, @@ -7373,6 +7387,7 @@ function createSplitsAndOnyxData({ tag, taxCode, taxAmount: isExpenseReport(oneOnOneIOUReport) ? -splitTaxAmount : splitTaxAmount, + taxValue, billable, source: CONST.IOU.TYPE.SPLIT, }, @@ -7569,6 +7584,7 @@ function createDistanceRequest(distanceRequestInformation: CreateDistanceRequest tag, taxAmount, taxCode, + taxValue, merchant, billable, reimbursable, @@ -7622,6 +7638,7 @@ function createDistanceRequest(distanceRequestInformation: CreateDistanceRequest iouRequestType: CONST.IOU.REQUEST_TYPE.DISTANCE, taxCode, taxAmount, + taxValue, attendees, }, policyRecentlyUsedCategories, @@ -7703,6 +7720,7 @@ function createDistanceRequest(distanceRequestInformation: CreateDistanceRequest tag, taxCode, taxAmount, + taxValue, billable, reimbursable, attendees, From 2549f2c9d967dd8d64e8674ad326168fd3ec1bdb Mon Sep 17 00:00:00 2001 From: dominictb Date: Mon, 16 Mar 2026 21:18:40 +0700 Subject: [PATCH 2/4] pass taxValue to buildOptimisticTransaction --- src/libs/actions/IOU/MoneyRequest.ts | 2 ++ src/libs/actions/IOU/Split.ts | 6 ++++++ src/pages/Share/SubmitDetailsPage.tsx | 3 +++ .../iou/request/step/IOURequestStepConfirmation.tsx | 10 ++++++++++ .../step/IOURequestStepScan/hooks/useReceiptScan.ts | 1 + 5 files changed, 22 insertions(+) diff --git a/src/libs/actions/IOU/MoneyRequest.ts b/src/libs/actions/IOU/MoneyRequest.ts index ff4beeef4048..cad9f5e54f32 100644 --- a/src/libs/actions/IOU/MoneyRequest.ts +++ b/src/libs/actions/IOU/MoneyRequest.ts @@ -88,6 +88,7 @@ type InitialTransactionParams = { reportID?: string; taxCode: string; taxAmount: number; + taxValue?: string; isFromGlobalCreate?: boolean; currency?: string; participants?: Participant[]; @@ -400,6 +401,7 @@ function handleMoneyRequestStepScanParticipants({ currency: initialTransaction?.currency ?? 'USD', taxCode: initialTransaction.taxCode, taxAmount: initialTransaction.taxAmount, + taxValue: initialTransaction.taxValue, quickAction, policyRecentlyUsedCurrencies: policyRecentlyUsedCurrencies ?? [], // No need to update recently used tags because no tags are used when the confirmation step is skipped diff --git a/src/libs/actions/IOU/Split.ts b/src/libs/actions/IOU/Split.ts index 4c38f5ad2a00..b4e4a45adc78 100644 --- a/src/libs/actions/IOU/Split.ts +++ b/src/libs/actions/IOU/Split.ts @@ -143,6 +143,7 @@ type SplitBillActionsParams = { splitShares?: SplitShares; taxCode?: string; taxAmount?: number; + taxValue?: string; isRetry?: boolean; policyRecentlyUsedCategories?: OnyxEntry; policyRecentlyUsedTags: OnyxEntry; @@ -176,6 +177,7 @@ function splitBill({ splitShares = {}, taxCode = '', taxAmount = 0, + taxValue, policyRecentlyUsedCategories, isASAPSubmitBetaEnabled, transactionViolations, @@ -205,6 +207,7 @@ function splitBill({ iouRequestType, taxCode, taxAmount, + taxValue, }, policyRecentlyUsedCategories, policyRecentlyUsedTags, @@ -268,6 +271,7 @@ function splitBillAndOpenReport({ splitShares = {}, taxCode = '', taxAmount = 0, + taxValue, existingSplitChatReportID, policyRecentlyUsedCategories, policyRecentlyUsedTags, @@ -299,6 +303,7 @@ function splitBillAndOpenReport({ iouRequestType, taxCode, taxAmount, + taxValue, }, policyRecentlyUsedCategories, policyRecentlyUsedTags, @@ -547,6 +552,7 @@ function startSplitBill({ currency, taxCode, taxAmount, + taxValue, quickAction, policyRecentlyUsedCurrencies, policyRecentlyUsedTags, diff --git a/src/pages/Share/SubmitDetailsPage.tsx b/src/pages/Share/SubmitDetailsPage.tsx index 02a178f3e86e..b7c5c11ce42c 100644 --- a/src/pages/Share/SubmitDetailsPage.tsx +++ b/src/pages/Share/SubmitDetailsPage.tsx @@ -131,6 +131,7 @@ function SubmitDetailsPage({ const transactionTaxAmount = transaction?.taxAmount ?? 0; const defaultTaxCode = getDefaultTaxCode(policy, transaction); const transactionTaxCode = (transaction?.taxCode ? transaction?.taxCode : defaultTaxCode) ?? ''; + const transactionTaxValue = transaction?.taxValue; const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); const [recentWaypoints] = useOnyx(ONYXKEYS.NVP_RECENT_WAYPOINTS); @@ -155,6 +156,7 @@ function SubmitDetailsPage({ tag: transaction.tag, taxCode: transactionTaxCode, taxAmount: transactionTaxAmount, + taxValue: transactionTaxValue, billable: transaction.billable, reimbursable: transaction.reimbursable, merchant: transaction.merchant ?? '', @@ -195,6 +197,7 @@ function SubmitDetailsPage({ tag: transaction.tag, taxCode: transactionTaxCode, taxAmount: transactionTaxAmount, + taxValue: transactionTaxValue, billable: transaction.billable, reimbursable: transaction.reimbursable, merchant: transaction.merchant ?? '', diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index e365203ac468..8207abc7bee5 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -277,6 +277,7 @@ function IOURequestStepConfirmation({ const defaultTaxCode = getDefaultTaxCode(policy, transaction); const transactionTaxCode = (transaction?.taxCode ? transaction?.taxCode : defaultTaxCode) ?? ''; const transactionTaxAmount = transaction?.taxAmount ?? 0; + const transactionTaxValue = transaction?.taxValue; const isSharingTrackExpense = action === CONST.IOU.ACTION.SHARE; const isCategorizingTrackExpense = action === CONST.IOU.ACTION.CATEGORIZE; const isMovingTransactionFromTrackExpense = isMovingTransactionFromTrackExpenseIOUUtils(action); @@ -665,6 +666,7 @@ function IOURequestStepConfirmation({ tag: item.tag, taxCode: transactionTaxCode, taxAmount: transactionTaxAmount, + taxValue: transactionTaxValue, billable: item.billable, reimbursable: item.reimbursable, actionableWhisperReportActionID: item.actionableWhisperReportActionID, @@ -717,6 +719,7 @@ function IOURequestStepConfirmation({ isManualDistanceRequest, transactionTaxCode, transactionTaxAmount, + transactionTaxValue, customUnitRateID, isTimeRequest, shouldGenerateTransactionThreadReport, @@ -874,6 +877,7 @@ function IOURequestStepConfirmation({ tag: item.tag, taxCode: transactionTaxCode, taxAmount: transactionTaxAmount, + taxValue: transactionTaxValue, billable: item.billable, reimbursable: item.reimbursable, gpsPoint, @@ -923,6 +927,7 @@ function IOURequestStepConfirmation({ receiptFiles, transactionTaxCode, transactionTaxAmount, + transactionTaxValue, customUnitRateID, gpsDraftDetails, isASAPSubmitBetaEnabled, @@ -967,6 +972,7 @@ function IOURequestStepConfirmation({ tag: transaction.tag, taxCode: transactionTaxCode, taxAmount: transactionTaxAmount, + taxValue: transactionTaxValue, customUnitRateID, splitShares: transaction.splitShares, validWaypoints: getValidWaypoints(transaction.comment?.waypoints, true, isGPSDistanceRequest), @@ -1003,6 +1009,7 @@ function IOURequestStepConfirmation({ transactionDistance, transactionTaxCode, transactionTaxAmount, + transactionTaxValue, customUnitRateID, isManualDistanceRequest, isOdometerDistanceRequest, @@ -1126,6 +1133,7 @@ function IOURequestStepConfirmation({ currency: item.currency, taxCode: transactionTaxCode, taxAmount: transactionTaxAmount, + taxValue: transactionTaxValue, shouldPlaySound: index === transactions.length - 1, policyRecentlyUsedCategories, policyRecentlyUsedTags, @@ -1161,6 +1169,7 @@ function IOURequestStepConfirmation({ splitShares: transaction.splitShares, taxCode: transactionTaxCode, taxAmount: transactionTaxAmount, + taxValue: transactionTaxValue, policyRecentlyUsedCategories, policyRecentlyUsedTags, isASAPSubmitBetaEnabled, @@ -1195,6 +1204,7 @@ function IOURequestStepConfirmation({ splitShares: transaction.splitShares, taxCode: transactionTaxCode, taxAmount: transactionTaxAmount, + taxValue: transactionTaxValue, policyRecentlyUsedCategories, policyRecentlyUsedTags, isASAPSubmitBetaEnabled, diff --git a/src/pages/iou/request/step/IOURequestStepScan/hooks/useReceiptScan.ts b/src/pages/iou/request/step/IOURequestStepScan/hooks/useReceiptScan.ts index ae67e2a60ead..bca587be75c8 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/hooks/useReceiptScan.ts +++ b/src/pages/iou/request/step/IOURequestStepScan/hooks/useReceiptScan.ts @@ -115,6 +115,7 @@ function useReceiptScan({ reportID: initialTransaction?.reportID, taxCode: transactionTaxCode, taxAmount: transactionTaxAmount, + taxValue: initialTransaction?.taxValue, currency: initialTransaction?.currency, isFromGlobalCreate: initialTransaction?.isFromGlobalCreate, participants: initialTransaction?.participants, From 40205cea5be627a96e7040b07ca2036bd3dcb861 Mon Sep 17 00:00:00 2001 From: dominictb Date: Mon, 16 Mar 2026 22:21:32 +0700 Subject: [PATCH 3/4] add default tax as fallback for taxValue --- src/pages/Share/SubmitDetailsPage.tsx | 4 ++-- src/pages/iou/request/step/IOURequestStepConfirmation.tsx | 4 +++- .../request/step/IOURequestStepScan/hooks/useReceiptScan.ts | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/pages/Share/SubmitDetailsPage.tsx b/src/pages/Share/SubmitDetailsPage.tsx index b7c5c11ce42c..d38be5367968 100644 --- a/src/pages/Share/SubmitDetailsPage.tsx +++ b/src/pages/Share/SubmitDetailsPage.tsx @@ -32,7 +32,7 @@ import {getParticipantsOption, getReportOption} from '@libs/OptionsListUtils'; import {hasOnlyPersonalPolicies as hasOnlyPersonalPoliciesUtil} from '@libs/PolicyUtils'; import {shouldValidateFile} from '@libs/ReceiptUtils'; import {getReportOrDraftReport, isSelfDM} from '@libs/ReportUtils'; -import {getDefaultTaxCode} from '@libs/TransactionUtils'; +import {getDefaultTaxCode, getTaxValue} from '@libs/TransactionUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; @@ -131,7 +131,7 @@ function SubmitDetailsPage({ const transactionTaxAmount = transaction?.taxAmount ?? 0; const defaultTaxCode = getDefaultTaxCode(policy, transaction); const transactionTaxCode = (transaction?.taxCode ? transaction?.taxCode : defaultTaxCode) ?? ''; - const transactionTaxValue = transaction?.taxValue; + const transactionTaxValue = transaction?.taxValue ?? getTaxValue(policy, transaction, transactionTaxCode) ?? ''; const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); const [recentWaypoints] = useOnyx(ONYXKEYS.NVP_RECENT_WAYPOINTS); diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index 8207abc7bee5..ba94e506a6b0 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -73,6 +73,7 @@ import { getDefaultTaxCode, getRateID, getRequestType, + getTaxValue, getValidWaypoints, hasReceipt, isDistanceRequest as isDistanceRequestTransactionUtils, @@ -277,7 +278,7 @@ function IOURequestStepConfirmation({ const defaultTaxCode = getDefaultTaxCode(policy, transaction); const transactionTaxCode = (transaction?.taxCode ? transaction?.taxCode : defaultTaxCode) ?? ''; const transactionTaxAmount = transaction?.taxAmount ?? 0; - const transactionTaxValue = transaction?.taxValue; + const transactionTaxValue = transaction?.taxValue ?? getTaxValue(policy, transaction, transactionTaxCode) ?? ''; const isSharingTrackExpense = action === CONST.IOU.ACTION.SHARE; const isCategorizingTrackExpense = action === CONST.IOU.ACTION.CATEGORIZE; const isMovingTransactionFromTrackExpense = isMovingTransactionFromTrackExpenseIOUUtils(action); @@ -1351,6 +1352,7 @@ function IOURequestStepConfirmation({ report, transactionTaxCode, transactionTaxAmount, + transactionTaxValue, policyRecentlyUsedCategories, policyRecentlyUsedTags, quickAction, diff --git a/src/pages/iou/request/step/IOURequestStepScan/hooks/useReceiptScan.ts b/src/pages/iou/request/step/IOURequestStepScan/hooks/useReceiptScan.ts index bca587be75c8..71dc5685589b 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/hooks/useReceiptScan.ts +++ b/src/pages/iou/request/step/IOURequestStepScan/hooks/useReceiptScan.ts @@ -16,7 +16,7 @@ import {handleMoneyRequestStepScanParticipants} from '@libs/actions/IOU/MoneyReq import setTestReceipt from '@libs/actions/setTestReceipt'; import {isArchivedReport, isPolicyExpenseChat} from '@libs/ReportUtils'; import {getSpan, startSpan} from '@libs/telemetry/activeSpans'; -import {getDefaultTaxCode, hasReceipt, shouldReuseInitialTransaction} from '@libs/TransactionUtils'; +import {getDefaultTaxCode, getTaxValue, hasReceipt, shouldReuseInitialTransaction} from '@libs/TransactionUtils'; import type {ReceiptFile, UseReceiptScanParams} from '@pages/iou/request/step/IOURequestStepScan/types'; import {setMoneyRequestReceipt} from '@userActions/IOU'; import {buildOptimisticTransactionAndCreateDraft, removeDraftTransactions} from '@userActions/TransactionEdit'; @@ -76,6 +76,7 @@ function useReceiptScan({ const defaultTaxCode = getDefaultTaxCode(policy, initialTransaction); const transactionTaxCode = (initialTransaction?.taxCode ? initialTransaction?.taxCode : defaultTaxCode) ?? ''; const transactionTaxAmount = initialTransaction?.taxAmount ?? 0; + const transactionTaxValue = initialTransaction?.taxValue ?? getTaxValue(policy, initialTransaction, transactionTaxCode) ?? ''; // For quick button actions, we'll skip the confirmation page unless the report is archived or this is a workspace // request and the workspace requires a category or a tag @@ -115,7 +116,7 @@ function useReceiptScan({ reportID: initialTransaction?.reportID, taxCode: transactionTaxCode, taxAmount: transactionTaxAmount, - taxValue: initialTransaction?.taxValue, + taxValue: transactionTaxValue, currency: initialTransaction?.currency, isFromGlobalCreate: initialTransaction?.isFromGlobalCreate, participants: initialTransaction?.participants, From 69aa29aeddc2d11386db12b23aaa890f915e53bf Mon Sep 17 00:00:00 2001 From: dominictb Date: Mon, 16 Mar 2026 23:11:21 +0700 Subject: [PATCH 4/4] improve code coverage by adding more tests --- tests/unit/ReportUtilsTest.ts | 59 ++++++++++++++++++++++++++++++ tests/unit/TransactionUtilsTest.ts | 26 +++++++++++++ 2 files changed, 85 insertions(+) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 2924aad985fb..7c8c8b753e17 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -96,6 +96,7 @@ import { getReportPreviewMessage, getReportStatusTranslation, getReportSubtitlePrefix, + getTransactionDetails, getWorkspaceIcon, getWorkspaceNameUpdatedMessage, hasActionWithErrorsForTransaction, @@ -14261,4 +14262,62 @@ describe('ReportUtils', () => { }); }); }); + + describe('getTransactionDetails', () => { + it('should return taxValue from the transaction', () => { + const transaction = buildOptimisticTransaction({ + transactionParams: { + amount: 1000, + currency: 'USD', + reportID: '1', + comment: '', + created: '2024-01-01', + taxCode: 'id_TAX_RATE_1', + taxAmount: 0, + taxValue: '0%', + }, + }); + + const details = getTransactionDetails(transaction); + + expect(details?.taxValue).toBe('0%'); + expect(details?.taxCode).toBe('id_TAX_RATE_1'); + expect(details?.taxAmount).toBe(0); + }); + + it('should return undefined taxValue when not set on the transaction', () => { + const transaction = buildOptimisticTransaction({ + transactionParams: { + amount: 500, + currency: 'USD', + reportID: '1', + comment: '', + created: '2024-01-01', + }, + }); + + const details = getTransactionDetails(transaction); + + expect(details?.taxValue).toBeUndefined(); + }); + + it('should return non-zero taxValue from the transaction', () => { + const transaction = buildOptimisticTransaction({ + transactionParams: { + amount: 1000, + currency: 'USD', + reportID: '1', + comment: '', + created: '2024-01-01', + taxCode: 'id_TAX_RATE_1', + taxAmount: 100, + taxValue: '10%', + }, + }); + + const details = getTransactionDetails(transaction); + + expect(details?.taxValue).toBe('10%'); + }); + }); }); diff --git a/tests/unit/TransactionUtilsTest.ts b/tests/unit/TransactionUtilsTest.ts index c1d15d598490..3c21b6e2d7fb 100644 --- a/tests/unit/TransactionUtilsTest.ts +++ b/tests/unit/TransactionUtilsTest.ts @@ -450,6 +450,32 @@ describe('TransactionUtils', () => { expect(updatedTransaction.modifiedAmount).toBe(newAmount); }); + + it('should update taxValue when taxValue and taxCode are both in transactionChanges', () => { + const transaction = generateTransaction(); + + const updatedTransaction = TransactionUtils.getUpdatedTransaction({ + transaction, + isFromExpenseReport: true, + transactionChanges: {taxCode: 'id_TAX_RATE_1', taxAmount: 50, taxValue: '5%'}, + }); + + expect(updatedTransaction.taxValue).toBe('5%'); + expect(updatedTransaction.taxCode).toBe('id_TAX_RATE_1'); + expect(updatedTransaction.taxAmount).toBe(-50); + }); + + it('should not update taxValue when taxCode is not in transactionChanges', () => { + const transaction = generateTransaction({taxValue: '10%'}); + + const updatedTransaction = TransactionUtils.getUpdatedTransaction({ + transaction, + isFromExpenseReport: false, + transactionChanges: {taxValue: '5%'}, + }); + + expect(updatedTransaction.taxValue).toBe('10%'); + }); }); describe('isScanning', () => {