From ac5492f6501771feed72b16f4f26f6d32b3ecb18 Mon Sep 17 00:00:00 2001 From: Tae Jung Date: Fri, 3 Jan 2025 22:23:40 +0000 Subject: [PATCH 1/2] fix distance zip and distance for destination SIT --- migrations/app/migrations_manifest.txt | 2 +- .../distance_zip_lookup.go | 64 +++-- .../distance_zip_lookup_test.go | 117 ++++++--- .../service_param_value_lookups.go | 42 ++-- .../service_param_value_lookups_test.go | 229 ++++++++++++++++++ 5 files changed, 362 insertions(+), 92 deletions(-) diff --git a/migrations/app/migrations_manifest.txt b/migrations/app/migrations_manifest.txt index 18c13cdaa73..a5330171a14 100644 --- a/migrations/app/migrations_manifest.txt +++ b/migrations/app/migrations_manifest.txt @@ -1052,9 +1052,9 @@ 20241203024453_add_ppm_max_incentive_column.up.sql 20241204155919_update_ordering_proc.up.sql 20241204210208_retroactive_update_of_ppm_max_and_estimated_incentives_prd.up.sql -20241218201833_add_PPPO_BASE_ELIZABETH.up.sql 20241217163231_update_duty_locations_bad_zips.up.sql 20241217180136_add_AK_zips_to_zip3_distances.up.sql +20241218201833_add_PPPO_BASE_ELIZABETH.up.sql 20241220171035_add_additional_AK_zips_to_zip3_distances.up.sql 20241227153723_remove_empty_string_emplid_values.up.sql 20241230190638_remove_AK_zips_from_zip3.up.sql diff --git a/pkg/payment_request/service_param_value_lookups/distance_zip_lookup.go b/pkg/payment_request/service_param_value_lookups/distance_zip_lookup.go index be5f2515e49..ea66b5ebfb2 100644 --- a/pkg/payment_request/service_param_value_lookups/distance_zip_lookup.go +++ b/pkg/payment_request/service_param_value_lookups/distance_zip_lookup.go @@ -23,6 +23,8 @@ func (r DistanceZipLookup) lookup(appCtx appcontext.AppContext, keyData *Service planner := keyData.planner db := appCtx.DB() var distanceMiles int + var totalDistanceMiles int + hasApprovedDestinationSIT := false // Make sure there's an MTOShipment since that's nullable mtoShipmentID := keyData.mtoShipmentID @@ -41,7 +43,12 @@ func (r DistanceZipLookup) lookup(appCtx appcontext.AppContext, keyData *Service } } - err = appCtx.DB().EagerPreload("DeliveryAddressUpdate", "DeliveryAddressUpdate.OriginalAddress", "DeliveryAddressUpdate.NewAddress", "MTOServiceItems", "Distance").Find(&mtoShipment, mtoShipment.ID) + err = appCtx.DB().EagerPreload( + "MTOServiceItems", + "Distance", + "PickupAddress", + "DestinationAddress", + ).Find(&mtoShipment, mtoShipment.ID) if err != nil { return "", err } @@ -58,53 +65,44 @@ func (r DistanceZipLookup) lookup(appCtx appcontext.AppContext, keyData *Service return "", apperror.NewInvalidInputError(*mtoShipmentID, fmt.Errorf("%s", errorMsgForDestinationZip), nil, errorMsgForDestinationZip) } - serviceCode := keyData.MTOServiceItem.ReService.Code - switch serviceCode { - case models.ReServiceCodeDLH, models.ReServiceCodeDSH, models.ReServiceCodeFSC: - for _, si := range mtoShipment.MTOServiceItems { - siCopy := si - err := appCtx.DB().EagerPreload("ReService", "ApprovedAt").Find(&siCopy, siCopy.ID) - if err != nil { - return "", err - } - - switch siCopy.ReService.Code { - case models.ReServiceCodeDDASIT, models.ReServiceCodeDDDSIT, models.ReServiceCodeDDFSIT, models.ReServiceCodeDDSFSC: - if mtoShipment.DeliveryAddressUpdate != nil && mtoShipment.DeliveryAddressUpdate.Status == models.ShipmentAddressUpdateStatusApproved { - if siCopy.ApprovedAt != nil { - if mtoShipment.DeliveryAddressUpdate.UpdatedAt.After(*siCopy.ApprovedAt) { - destinationZip = mtoShipment.DeliveryAddressUpdate.OriginalAddress.PostalCode - } else { - destinationZip = mtoShipment.DeliveryAddressUpdate.NewAddress.PostalCode - } - } - } - } + for _, si := range mtoShipment.MTOServiceItems { + siCopy := si + err := appCtx.DB().EagerPreload("ReService").Find(&siCopy, siCopy.ID) + if err != nil { + return "", err } - if mtoShipment.DeliveryAddressUpdate != nil && mtoShipment.DeliveryAddressUpdate.Status == models.ShipmentAddressUpdateStatusApproved { - distanceMiles, err = planner.ZipTransitDistance(appCtx, pickupZip, mtoShipment.DeliveryAddressUpdate.NewAddress.PostalCode) - if err != nil { - return "", err + switch siCopy.ReService.Code { + case models.ReServiceCodeDDASIT, models.ReServiceCodeDDDSIT, models.ReServiceCodeDDFSIT, models.ReServiceCodeDDSFSC: + if siCopy.Status == models.MTOServiceItemStatusApproved { + hasApprovedDestinationSIT = true } - return strconv.Itoa(distanceMiles), nil } } - if mtoShipment.Distance != nil && mtoShipment.ShipmentType != models.MTOShipmentTypePPM { - return strconv.Itoa(mtoShipment.Distance.Int()), nil - } - if pickupZip == destinationZip { distanceMiles = 1 + totalDistanceMiles = distanceMiles + } else if hasApprovedDestinationSIT { + // from pickup zip to delivery zip + totalDistanceMiles, err = planner.ZipTransitDistance(appCtx, mtoShipment.PickupAddress.PostalCode, mtoShipment.DestinationAddress.PostalCode) + if err != nil { + return "", err + } + // from pickup zip to Destination SIT zip + distanceMiles, err = planner.ZipTransitDistance(appCtx, pickupZip, destinationZip) + if err != nil { + return "", err + } } else { distanceMiles, err = planner.ZipTransitDistance(appCtx, pickupZip, destinationZip) if err != nil { return "", err } + totalDistanceMiles = distanceMiles } - miles := unit.Miles(distanceMiles) + miles := unit.Miles(totalDistanceMiles) mtoShipment.Distance = &miles err = db.Save(&mtoShipment) if err != nil { diff --git a/pkg/payment_request/service_param_value_lookups/distance_zip_lookup_test.go b/pkg/payment_request/service_param_value_lookups/distance_zip_lookup_test.go index 4f826c52009..2c6917853ae 100644 --- a/pkg/payment_request/service_param_value_lookups/distance_zip_lookup_test.go +++ b/pkg/payment_request/service_param_value_lookups/distance_zip_lookup_test.go @@ -63,6 +63,88 @@ func (suite *ServiceParamValueLookupsSuite) TestDistanceLookup() { suite.Equal(unit.Miles(defaultZipDistance), *mtoShipment.Distance) }) + suite.Run("Calculate transit zip distance with an approved Destination SIT service item", func() { + testdatagen.MakeReContractYear(suite.DB(), testdatagen.Assertions{ + ReContractYear: models.ReContractYear{ + StartDate: time.Now().Add(-24 * time.Hour), + EndDate: time.Now().Add(24 * time.Hour), + }, + }) + now := time.Now() + + destinationAddress := factory.BuildAddress(suite.DB(), []factory.Customization{ + { + Model: models.Address{ + PostalCode: "88101", + }, + }, + }, nil) + + mtoServiceItem := factory.BuildMTOServiceItem(suite.DB(), []factory.Customization{ + { + Model: models.Address{ + PostalCode: "33607", + }, + Type: &factory.Addresses.PickupAddress, + }, + { + Model: models.Address{ + PostalCode: "90210", + }, + Type: &factory.Addresses.DeliveryAddress, + }, + }, []factory.Trait{ + factory.GetTraitAvailableToPrimeMove, + }) + + factory.BuildMTOServiceItem(suite.DB(), []factory.Customization{ + { + Model: models.ReService{ + Code: models.ReServiceCodeDDFSIT, + Name: models.ReServiceCodeDDFSIT.String(), + }, + }, + { + Model: models.MTOServiceItem{ + Status: models.MTOServiceItemStatusApproved, + ApprovedAt: &now, + }, + }, + { + Model: destinationAddress, + LinkOnly: true, + Type: &factory.Addresses.SITDestinationOriginalAddress, + }, + { + Model: mtoServiceItem.MTOShipment, + LinkOnly: true, + }, + }, []factory.Trait{ + factory.GetTraitAvailableToPrimeMove, + }) + + paymentRequest := factory.BuildPaymentRequest(suite.DB(), []factory.Customization{ + { + Model: mtoServiceItem.MoveTaskOrder, + LinkOnly: true, + }, + }, nil) + + paramLookup, err := ServiceParamLookupInitialize(suite.AppContextForTest(), suite.planner, mtoServiceItem, paymentRequest.ID, paymentRequest.MoveTaskOrderID, nil) + suite.FatalNoError(err) + + distanceStr, err := paramLookup.ServiceParamValue(suite.AppContextForTest(), key) + suite.FatalNoError(err) + expected := strconv.Itoa(defaultZipDistance) + suite.Equal(expected, distanceStr) + + var mtoShipment models.MTOShipment + err = suite.DB().Find(&mtoShipment, mtoServiceItem.MTOShipmentID) + suite.NoError(err) + + suite.Equal(unit.Miles(defaultZipDistance), *mtoShipment.Distance) + }) + suite.Run("Calculate zip distance lookup without a saved service item", func() { ppmShipment := factory.BuildPPMShipment(suite.DB(), nil, nil) @@ -88,7 +170,7 @@ func (suite *ServiceParamValueLookupsSuite) TestDistanceLookup() { suite.Equal(unit.Miles(defaultZipDistance), *ppmShipment.Shipment.Distance) }) - suite.Run("Call ZipTransitDistance on non-PPMs with shipments that have a distance", func() { + suite.Run("Call ZipTransitDistance on PPMs with shipments that have a distance", func() { miles := unit.Miles(defaultZipDistance) ppmShipment := factory.BuildPPMShipment(suite.DB(), []factory.Customization{ { @@ -119,39 +201,6 @@ func (suite *ServiceParamValueLookupsSuite) TestDistanceLookup() { suite.Equal(fmt.Sprintf("%d", defaultZipDistance), distance) }) - suite.Run("Do not call ZipTransitDistance on PPMs with shipments that have a distance", func() { - miles := unit.Miles(defaultZipDistance) - shipment := factory.BuildMTOShipment(suite.DB(), []factory.Customization{ - { - Model: models.MTOShipment{ - Distance: &miles, - ShipmentType: models.MTOShipmentTypeHHG, - }, - }, - }, nil) - - distanceZipLookup := DistanceZipLookup{ - PickupAddress: models.Address{PostalCode: shipment.PickupAddress.PostalCode}, - DestinationAddress: models.Address{PostalCode: shipment.DestinationAddress.PostalCode}, - } - - appContext := suite.AppContextForTest() - distance, err := distanceZipLookup.lookup(appContext, &ServiceItemParamKeyData{ - planner: suite.planner, - mtoShipmentID: &shipment.ID, - }) - suite.NoError(err) - - planner := suite.planner.(*mocks.Planner) - planner.AssertNotCalled(suite.T(), "ZipTransitDistance", appContext, shipment.PickupAddress.PostalCode, shipment.DestinationAddress.PostalCode) - - err = suite.DB().Reload(&shipment) - suite.NoError(err) - - suite.Equal(unit.Miles(defaultZipDistance), *shipment.Distance) - suite.Equal(fmt.Sprintf("%d", defaultZipDistance), distance) - }) - suite.Run("Sucessfully updates mtoShipment distance when the pickup and destination zips are the same", func() { testdatagen.MakeReContractYear(suite.DB(), testdatagen.Assertions{ ReContractYear: models.ReContractYear{ diff --git a/pkg/payment_request/service_param_value_lookups/service_param_value_lookups.go b/pkg/payment_request/service_param_value_lookups/service_param_value_lookups.go index 0bb499be70b..5d9a9a941d5 100644 --- a/pkg/payment_request/service_param_value_lookups/service_param_value_lookups.go +++ b/pkg/payment_request/service_param_value_lookups/service_param_value_lookups.go @@ -280,10 +280,8 @@ func InitializeLookups(appCtx appcontext.AppContext, shipment models.MTOShipment MTOShipment: shipment, } - serviceDestinationAddress, err := GetDestinationForDistanceLookup(appCtx, shipment, &serviceItem) - if err != nil { - return nil - } + serviceDestinationAddress := GetDestinationAfterCheckingSIT(appCtx, shipment, &serviceItem) + lookups[models.ServiceItemParamNameDistanceZip] = DistanceZipLookup{ PickupAddress: *shipment.PickupAddress, DestinationAddress: serviceDestinationAddress, @@ -318,7 +316,7 @@ func InitializeLookups(appCtx appcontext.AppContext, shipment models.MTOShipment } lookups[models.ServiceItemParamNameZipDestAddress] = ZipAddressLookup{ - Address: *shipment.DestinationAddress, + Address: serviceDestinationAddress, } lookups[models.ServiceItemParamNameMTOAvailableToPrimeAt] = MTOAvailableToPrimeAtLookup{} @@ -433,43 +431,39 @@ func InitializeLookups(appCtx appcontext.AppContext, shipment models.MTOShipment return lookups } -func GetDestinationForDistanceLookup(appCtx appcontext.AppContext, mtoShipment models.MTOShipment, mtoServiceItem *models.MTOServiceItem) (models.Address, error) { +// check additional conditions to determine the correct destination address to use for HHG shipment DLH, DSH, & FSC. +// we use DeliveryAddressUpdate.SIToriginalAddress if the shipment destination address update was made after Destination SIT was approved. +// if the shipment does not have a Destination SIT and a destination shipment update was made, then we use the new address. +func GetDestinationAfterCheckingSIT(appCtx appcontext.AppContext, mtoShipment models.MTOShipment, mtoServiceItem *models.MTOServiceItem) models.Address { if mtoServiceItem == nil || mtoShipment.ShipmentType != models.MTOShipmentTypeHHG || (mtoServiceItem.ReService.Code != models.ReServiceCodeDLH && mtoServiceItem.ReService.Code != models.ReServiceCodeDSH && mtoServiceItem.ReService.Code != models.ReServiceCodeFSC) { - return *mtoShipment.DestinationAddress, nil + return *mtoShipment.DestinationAddress } shipmentCopy := mtoShipment - err := appCtx.DB().Eager("DeliveryAddressUpdate.Status", "DeliveryAddressUpdate.UpdatedAt", "DeliveryAddressUpdate.OriginalAddress", "DeliveryAddressUpdate.NewAddress", "MTOServiceItems", "DestinationAddress").Find(&shipmentCopy, mtoShipment.ID) + err := appCtx.DB().Eager("MTOServiceItems").Find(&shipmentCopy, mtoShipment.ID) if err != nil { - return models.Address{}, apperror.NewNotFoundError(shipmentCopy.ID, "MTOShipment not found in Destination For Distance Lookup") + return *mtoShipment.DestinationAddress } if len(shipmentCopy.MTOServiceItems) == 0 { - return *mtoShipment.DestinationAddress, nil + return *mtoShipment.DestinationAddress } - var result models.Address + // return SITDestinationOriginalAddress if an approved Destination SIT exists for _, si := range shipmentCopy.MTOServiceItems { siCopy := si - err := appCtx.DB().Eager("ReService").Find(&siCopy, siCopy.ID) + err := appCtx.DB().Eager("ReService", "SITDestinationOriginalAddress").Find(&siCopy, siCopy.ID) if err != nil { - return models.Address{}, apperror.NewNotFoundError(siCopy.ID, "MTOServiceItem not found in Destination For Distance Lookup") + return *mtoShipment.DestinationAddress } switch siCopy.ReService.Code { case models.ReServiceCodeDDASIT, models.ReServiceCodeDDDSIT, models.ReServiceCodeDDFSIT, models.ReServiceCodeDDSFSC: - if shipmentCopy.DeliveryAddressUpdate != nil && shipmentCopy.DeliveryAddressUpdate.Status == models.ShipmentAddressUpdateStatusApproved { - if siCopy.ApprovedAt != nil && shipmentCopy.DeliveryAddressUpdate.UpdatedAt.After(*siCopy.ApprovedAt) { - return shipmentCopy.DeliveryAddressUpdate.OriginalAddress, nil - } - return shipmentCopy.DeliveryAddressUpdate.NewAddress, nil + if siCopy.Status == models.MTOServiceItemStatusApproved && siCopy.SITDestinationOriginalAddress != nil { + return *siCopy.SITDestinationOriginalAddress } } } - if shipmentCopy.DeliveryAddressUpdate.Status == models.ShipmentAddressUpdateStatusApproved { - result = shipmentCopy.DeliveryAddressUpdate.NewAddress - } else { - result = *shipmentCopy.DestinationAddress - } - return result, nil + + return *mtoShipment.DestinationAddress } // serviceItemNeedsParamKey wrapper for using paramCache.ServiceItemNeedsParamKey, if s.paramCache is nil diff --git a/pkg/payment_request/service_param_value_lookups/service_param_value_lookups_test.go b/pkg/payment_request/service_param_value_lookups/service_param_value_lookups_test.go index bc5587b7941..04f46e29c27 100644 --- a/pkg/payment_request/service_param_value_lookups/service_param_value_lookups_test.go +++ b/pkg/payment_request/service_param_value_lookups/service_param_value_lookups_test.go @@ -1087,3 +1087,232 @@ func (suite *ServiceParamValueLookupsSuite) TestFetchContractForMove() { suite.Equal(testdatagen.DefaultContractCode, contract.Code) }) } + +func (suite *ServiceParamValueLookupsSuite) TestGetDestinationAfterCheckingSIT() { + suite.Run("returned destination address should be SITDestinationOriginalAddress if an approved Destination SIT exists", func() { + now := time.Now() + destinationAddress := factory.BuildAddress(suite.DB(), []factory.Customization{ + { + Model: models.Address{ + PostalCode: "88101", + }, + }, + }, nil) + + mtoServiceItem := factory.BuildMTOServiceItem(suite.DB(), []factory.Customization{ + { + Model: models.ReService{ + Code: models.ReServiceCodeDLH, + Name: models.ReServiceCodeDLH.String(), + }, + }, + { + Model: models.MTOServiceItem{ + Status: models.MTOServiceItemStatusSubmitted, + }, + }, + { + Model: destinationAddress, + LinkOnly: true, + Type: &factory.Addresses.SITDestinationOriginalAddress, + }, + }, []factory.Trait{ + factory.GetTraitAvailableToPrimeMove, + }) + + factory.BuildMTOServiceItem(suite.DB(), []factory.Customization{ + { + Model: models.ReService{ + Code: models.ReServiceCodeDSH, + Name: models.ReServiceCodeDSH.String(), + }, + }, + { + Model: models.MTOServiceItem{ + Status: models.MTOServiceItemStatusApproved, + }, + }, + { + Model: destinationAddress, + LinkOnly: true, + Type: &factory.Addresses.SITDestinationOriginalAddress, + }, + { + Model: mtoServiceItem.MTOShipment, + LinkOnly: true, + }, + }, []factory.Trait{ + factory.GetTraitAvailableToPrimeMove, + }) + + factory.BuildMTOServiceItem(suite.DB(), []factory.Customization{ + { + Model: models.ReService{ + Code: models.ReServiceCodeFSC, + Name: models.ReServiceCodeFSC.String(), + }, + }, + { + Model: models.MTOServiceItem{ + Status: models.MTOServiceItemStatusApproved, + }, + }, + { + Model: destinationAddress, + LinkOnly: true, + Type: &factory.Addresses.SITDestinationOriginalAddress, + }, + { + Model: mtoServiceItem.MTOShipment, + LinkOnly: true, + }, + }, []factory.Trait{ + factory.GetTraitAvailableToPrimeMove, + }) + + factory.BuildMTOServiceItem(suite.DB(), []factory.Customization{ + { + Model: models.ReService{ + Code: models.ReServiceCodeDDFSIT, + Name: models.ReServiceCodeDDFSIT.String(), + }, + }, + { + Model: models.MTOServiceItem{ + Status: models.MTOServiceItemStatusApproved, + ApprovedAt: &now, + }, + }, + { + Model: destinationAddress, + LinkOnly: true, + Type: &factory.Addresses.SITDestinationOriginalAddress, + }, + { + Model: mtoServiceItem.MTOShipment, + LinkOnly: true, + }, + }, []factory.Trait{ + factory.GetTraitAvailableToPrimeMove, + }) + + serviceDestinationAddress := GetDestinationAfterCheckingSIT(suite.AppContextForTest(), mtoServiceItem.MTOShipment, &mtoServiceItem) + + // with an approved Destination SIT -> serviceDestinationAddress should return same address as SITDestinationOriginalAddress + suite.NotEqual(mtoServiceItem.SITDestinationOriginalAddress.PostalCode, mtoServiceItem.MTOShipment.DestinationAddress.PostalCode) + suite.Equal(mtoServiceItem.SITDestinationOriginalAddress.PostalCode, serviceDestinationAddress.PostalCode) + }) + + suite.Run("returned destination address should be SITDestinationOriginalAddress if an approved Destination SIT exists", func() { + destinationAddress := factory.BuildAddress(suite.DB(), []factory.Customization{ + { + Model: models.Address{ + PostalCode: "88101", + }, + }, + }, nil) + + mtoServiceItem := factory.BuildMTOServiceItem(suite.DB(), []factory.Customization{ + { + Model: models.ReService{ + Code: models.ReServiceCodeDLH, + Name: models.ReServiceCodeDLH.String(), + }, + }, + { + Model: models.MTOServiceItem{ + Status: models.MTOServiceItemStatusSubmitted, + }, + }, + { + Model: destinationAddress, + LinkOnly: true, + Type: &factory.Addresses.SITDestinationOriginalAddress, + }, + }, []factory.Trait{ + factory.GetTraitAvailableToPrimeMove, + }) + + factory.BuildMTOServiceItem(suite.DB(), []factory.Customization{ + { + Model: models.ReService{ + Code: models.ReServiceCodeDSH, + Name: models.ReServiceCodeDSH.String(), + }, + }, + { + Model: models.MTOServiceItem{ + Status: models.MTOServiceItemStatusApproved, + }, + }, + { + Model: destinationAddress, + LinkOnly: true, + Type: &factory.Addresses.SITDestinationOriginalAddress, + }, + { + Model: mtoServiceItem.MTOShipment, + LinkOnly: true, + }, + }, []factory.Trait{ + factory.GetTraitAvailableToPrimeMove, + }) + + factory.BuildMTOServiceItem(suite.DB(), []factory.Customization{ + { + Model: models.ReService{ + Code: models.ReServiceCodeFSC, + Name: models.ReServiceCodeFSC.String(), + }, + }, + { + Model: models.MTOServiceItem{ + Status: models.MTOServiceItemStatusApproved, + }, + }, + { + Model: destinationAddress, + LinkOnly: true, + Type: &factory.Addresses.SITDestinationOriginalAddress, + }, + { + Model: mtoServiceItem.MTOShipment, + LinkOnly: true, + }, + }, []factory.Trait{ + factory.GetTraitAvailableToPrimeMove, + }) + + factory.BuildMTOServiceItem(suite.DB(), []factory.Customization{ + { + Model: models.ReService{ + Code: models.ReServiceCodeDDFSIT, + Name: models.ReServiceCodeDDFSIT.String(), + }, + }, + { + Model: models.MTOServiceItem{ + Status: models.MTOServiceItemStatusSubmitted, + ApprovedAt: nil, + }, + }, + { + Model: destinationAddress, + LinkOnly: true, + Type: &factory.Addresses.SITDestinationOriginalAddress, + }, + { + Model: mtoServiceItem.MTOShipment, + LinkOnly: true, + }, + }, []factory.Trait{ + factory.GetTraitAvailableToPrimeMove, + }) + + serviceDestinationAddress := GetDestinationAfterCheckingSIT(suite.AppContextForTest(), mtoServiceItem.MTOShipment, &mtoServiceItem) + + // without an approved Destination SIT -> serviceDestinationAddress should return same address as MTOShipment.DestinationAddress + suite.Equal(serviceDestinationAddress.PostalCode, mtoServiceItem.MTOShipment.DestinationAddress.PostalCode) + suite.NotEqual(mtoServiceItem.SITDestinationOriginalAddress.PostalCode, serviceDestinationAddress.PostalCode) + }) +} From edd3e4312fe07688fba324169b3c5234d01cf81e Mon Sep 17 00:00:00 2001 From: Tae Jung Date: Mon, 6 Jan 2025 18:08:18 +0000 Subject: [PATCH 2/2] added check for distance --- .../service_param_value_lookups/distance_zip_lookup.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/payment_request/service_param_value_lookups/distance_zip_lookup.go b/pkg/payment_request/service_param_value_lookups/distance_zip_lookup.go index ea66b5ebfb2..1465bbb53c1 100644 --- a/pkg/payment_request/service_param_value_lookups/distance_zip_lookup.go +++ b/pkg/payment_request/service_param_value_lookups/distance_zip_lookup.go @@ -103,10 +103,12 @@ func (r DistanceZipLookup) lookup(appCtx appcontext.AppContext, keyData *Service } miles := unit.Miles(totalDistanceMiles) - mtoShipment.Distance = &miles - err = db.Save(&mtoShipment) - if err != nil { - return "", err + if mtoShipment.Distance == nil || mtoShipment.Distance.Int() != totalDistanceMiles { + mtoShipment.Distance = &miles + err = db.Save(&mtoShipment) + if err != nil { + return "", err + } } return strconv.Itoa(distanceMiles), nil