From bb293cf0fc9bc62210d75f3df8f76604eda27752 Mon Sep 17 00:00:00 2001 From: Scott Kiener Date: Wed, 22 Oct 2025 09:09:29 -0400 Subject: [PATCH] CASH-1713 | Insurance pricing error (tax refactor) Moved helper function to a helper file Price all line items on payment-method just in case something isn't in serverData yet --- src/helpers/pricing-helper.js | 20 ++++++++++++ src/layouts/payment-method/payment-method.vue | 32 +++++++++---------- src/store/index.js | 21 +----------- 3 files changed, 37 insertions(+), 36 deletions(-) diff --git a/src/helpers/pricing-helper.js b/src/helpers/pricing-helper.js index 9aa317353..1216836d5 100644 --- a/src/helpers/pricing-helper.js +++ b/src/helpers/pricing-helper.js @@ -99,3 +99,23 @@ export async function getPricingByDayPartWithPrice(pageNameToLog) { return pricingResults[0]; } + +export function addPricesToLineItems(lineItems, pricingLineItems) { + lineItems.forEach((lineItem) => { + const lineItemIndex = pricingLineItems.findIndex( + (pricingLineItem) => pricingLineItem.partNumber === lineItem.partNumber + ); + + if (lineItem.childParts) { + addPricesToLineItems(lineItem.childParts, pricingLineItems); + } + + const pricedLineItem = pricingLineItems.splice(lineItemIndex, 1)[0]; + lineItem.laborAmount = pricedLineItem.laborAmount; + lineItem.sellingPrice = pricedLineItem.sellingPrice; + lineItem.kitPrice = pricedLineItem.kitPrice; + lineItem.salesTax = pricedLineItem.salesTax; + }); + + return lineItems; +} \ No newline at end of file diff --git a/src/layouts/payment-method/payment-method.vue b/src/layouts/payment-method/payment-method.vue index ffb3d2353..6767777c8 100644 --- a/src/layouts/payment-method/payment-method.vue +++ b/src/layouts/payment-method/payment-method.vue @@ -155,7 +155,6 @@ import { getNewlyInactivatedPromos, } from "@/helpers/promotions-helper"; import { queryStrings } from "@/constants/query-strings"; -import { getQuerystringParameter } from "@/helpers/querystring-helper"; import { deepClone } from "@/helpers/object-helper"; import { Form } from "vee-validate"; @@ -163,17 +162,12 @@ import { defineRule } from "vee-validate"; import { required } from "@/helpers/validation-rules"; import { errorMessages } from "@/constants/error-messages"; import { AppointmentTypeStrings } from "@/constants/schedule-constants"; -import { partTypeStrings } from "@/constants/part-type-strings"; -import { mapTaxedLineItemsToStoreFormat } from "../../store"; import { coverageStatus } from "@/constants/insurance"; -import { containsLineItemWithPartType } from "@/helpers/service-package-helper"; import { containsRecalParts } from "@/helpers/recal-helper"; import { getBoolFromString } from "@/helpers/boolean-helper"; import { - getDisplayAmountDue, getAmountDue, - getSubTotal, - getSalesTax, + addPricesToLineItems } from "@/helpers/pricing-helper.js"; import { consumeQueryFromStash } from "@/router/methods/helpers/querystring-stash"; import { debugLog } from "@/helpers/debug-log-helper"; @@ -231,21 +225,28 @@ export default { const availableVaps = [resultMap.rainRepel, ...resultMap.wipers]; - const pricedAvailableVaps = await baseMixin.methods.dispatchStoreActionWithLogging( + const lineItemsOnOrderAndAvailableVaps = [ + ...availableVaps, + ...glassParts, + ...supportingItems, + ...vaps, + ]; + + // All line items are already priced except availableVaps + // Price everything again to ensure that serverData has all values + // Specifically this addresses an error where insurance client glass parts are not in serverData + // See CASH-1713 for details + const pricedLineItems = await baseMixin.methods.dispatchStoreActionWithLogging( storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA, { - availableLineItems: availableVaps, + availableLineItems: lineItemsOnOrderAndAvailableVaps, }, "payment-method", false ); - const lineItemsOnOrderAndAvailableVaps = [ - ...pricedAvailableVaps, - ...glassParts, - ...supportingItems, - ...vaps, - ]; + // Add prices to the availableVaps + const pricedAvailableVaps = addPricesToLineItems(availableVaps, pricedLineItems); // Promo logic // Populate the previous state of promos for toast message usage in "next()" @@ -265,7 +266,6 @@ export default { delete lineItemsForCart.serverData; // End of promo logic - // const vapsToAddToCart = getVapsThatNeedToBeAddedToSatisfyPromos( lineItemsForCart.promos ?? [], diff --git a/src/store/index.js b/src/store/index.js index 1fa9b4f14..ef67b84a0 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -59,6 +59,7 @@ import { } from "@/helpers/recal-helper"; import { externalParameterStatus } from "@/constants/external-parameters"; import { experimentSettings } from "@/constants/experiments"; +import { addPricesToLineItems } from "@/helpers/pricing-helper"; // Export State const getDefaultState = () => { @@ -3701,26 +3702,6 @@ function convertGlassPieceNamingFromApi(glassArray) { return glassArray; } -function addPricesToLineItems(lineItems, pricingLineItems) { - lineItems.forEach((lineItem) => { - const lineItemIndex = pricingLineItems.findIndex( - (pricingLineItem) => pricingLineItem.partNumber === lineItem.partNumber - ); - - if (lineItem.childParts) { - addPricesToLineItems(lineItem.childParts, pricingLineItems); - } - - const pricedLineItem = pricingLineItems.splice(lineItemIndex, 1)[0]; - lineItem.laborAmount = pricedLineItem.laborAmount; - lineItem.sellingPrice = pricedLineItem.sellingPrice; - lineItem.kitPrice = pricedLineItem.kitPrice; - lineItem.salesTax = pricedLineItem.salesTax; - }); - - return lineItems; -} - function addTaxesToPricedLineItems(pricedLineItems, taxingLineItems = []) { pricedLineItems.forEach((pricedLineItem) => { const lineItemIndex = taxingLineItems.findIndex(