From 4bcf62e3e90a13c7c4d4aecd9f78c4f62c6455ca Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Wed, 11 Dec 2024 20:32:42 +0000 Subject: [PATCH 01/29] merged in latest int, added conflict error, adding tests --- migrations/app/migrations_manifest.txt | 1 + ..._internatinoal_nts_re_service_items.up.sql | 22 ++++ pkg/models/mto_shipments.go | 9 ++ pkg/models/mto_shipments_test.go | 34 ++++++ .../mto_shipment/mto_shipment_updater.go | 16 +-- .../mto_shipment/mto_shipment_updater_test.go | 101 ++++++++++++++++++ .../mto_shipment/shipment_approver.go | 9 +- .../SubmittedRequestedShipments.jsx | 4 +- .../Office/ShipmentForm/ShipmentForm.jsx | 2 +- 9 files changed, 185 insertions(+), 13 deletions(-) create mode 100644 migrations/app/schema/20241208080706_add_internatinoal_nts_re_service_items.up.sql diff --git a/migrations/app/migrations_manifest.txt b/migrations/app/migrations_manifest.txt index ce95f21200c..09c6e00bd96 100644 --- a/migrations/app/migrations_manifest.txt +++ b/migrations/app/migrations_manifest.txt @@ -1051,3 +1051,4 @@ 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 +20241208080706_add_internatinoal_nts_re_service_items.up.sql diff --git a/migrations/app/schema/20241208080706_add_internatinoal_nts_re_service_items.up.sql b/migrations/app/schema/20241208080706_add_internatinoal_nts_re_service_items.up.sql new file mode 100644 index 00000000000..a8df589a072 --- /dev/null +++ b/migrations/app/schema/20241208080706_add_internatinoal_nts_re_service_items.up.sql @@ -0,0 +1,22 @@ +-- +-- Add service items for international NTS shipments. +-- +INSERT INTO re_service_items +(id, service_id, shipment_type, market_code, is_auto_approved, created_at, updated_at, sort) +VALUES + ('2a560507-db09-4be1-b809-49c0f515b31b', '9f3d551a-0725-430e-897e-80ee9add3ae9' ,'HHG_INTO_NTS_DOMESTIC', 'i', true, now(), now(), 1), + ('366ee5a4-eb61-4ded-a68c-ddc29fe1a886', '874cb86a-bc39-4f57-a614-53ee3fcacf14' ,'HHG_INTO_NTS_DOMESTIC', 'i', true, now(), now(), 2), + ('e702818f-defd-452c-81a3-865b902e7dd0', '388115e8-abe9-441d-96cf-a39f24baa0a3' ,'HHG_INTO_NTS_DOMESTIC', 'i', true, now(), now(), 3), + ('aac4e95e-27ed-4f09-9b6b-384d8542f410', '86203d72-7f7c-49ff-82f0-5b95e4958f60' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), nil), + ('010f2f91-7381-4149-8d74-8eb5f593a864', '806c6d59-57ff-4a3f-9518-ebf29ba9cb10' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), nil), + ('a41966b7-b83a-4eaf-8e68-d5e884777102', '28389ee1-56cf-400c-aa52-1501ecdd7c69' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), nil), + ('14c77957-3c76-465a-bb07-c98d36ef1e54', 'bd6064ca-e780-4ab4-a37b-0ae98eebb244' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), nil), + ('d52d2d03-100a-4ed9-b2de-16eac63a375f', '22fc07ed-be15-4f50-b941-cbd38153b378' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), nil), + ('7fd91408-7d69-4375-b7e6-5b2ff714206b', 'bd424e45-397b-4766-9712-de4ae3a2da36' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), nil), + ('b3dc509d-d652-4300-a702-a1ddce6255b6', 'b488bf85-ea5e-49c8-ba5c-e2fa278ac806' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), nil), + ('001eadb6-3526-45b9-96e0-0648bb481e86', '6f4f6e31-0675-4051-b659-89832259f390' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), nil), + ('b991c5c9-af2c-4146-b999-1d0bdf91de3f', '624a97c5-dfbf-4da9-a6e9-526b4f95af8d' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), nil), + ('5a89315a-257b-4ef0-92cb-4c06aa6f1332', '4132416b-b1aa-42e7-98f2-0ac0a03e8a31' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), nil), + ('d4a98dea-a5f7-4b92-b5de-e6350ab07824', '81e29d0c-02a6-4a7a-be02-554deb3ee49e' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), nil), + ('eaea90c2-93d3-4db9-89cd-23ac57ec9ce1', '690a5fc1-0ea5-4554-8294-a367b5daefa9' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), nil); + diff --git a/pkg/models/mto_shipments.go b/pkg/models/mto_shipments.go index 0d0885ded6a..b71d4d40996 100644 --- a/pkg/models/mto_shipments.go +++ b/pkg/models/mto_shipments.go @@ -10,6 +10,7 @@ import ( "github.com/gofrs/uuid" "github.com/pkg/errors" + "github.com/transcom/mymove/pkg/apperror" "github.com/transcom/mymove/pkg/unit" ) @@ -419,6 +420,14 @@ func DetermineMarketCode(address1 *Address, address2 *Address) (MarketCode, erro } func CreateApprovedServiceItemsForShipment(db *pop.Connection, shipment *MTOShipment) error { + // check if at least one pickup or destination/storage facility address is conus. + if (shipment.PickupAddress != nil && shipment.DestinationAddress != nil) || (shipment.PickupAddress != nil && shipment.StorageFacility != nil) { + if (*shipment.PickupAddress.IsOconus && *shipment.DestinationAddress.IsOconus) || + (*shipment.PickupAddress.IsOconus && *shipment.StorageFacility.Address.IsOconus) { + err := apperror.NewConflictError(shipment.ID, "cannot handle shipments from oconus to oconus") + return err + } + } err := db.RawQuery("CALL create_approved_service_items_for_shipment($1)", shipment.ID).Exec() if err != nil { return fmt.Errorf("error creating approved service items: %w", err) diff --git a/pkg/models/mto_shipments_test.go b/pkg/models/mto_shipments_test.go index 5f2a5f78864..1336b6d9b66 100644 --- a/pkg/models/mto_shipments_test.go +++ b/pkg/models/mto_shipments_test.go @@ -323,4 +323,38 @@ func (suite *ModelSuite) TestCreateApprovedServiceItemsForShipment() { err := models.CreateApprovedServiceItemsForShipment(suite.DB(), &invalidShipment) suite.Error(err) }) + + suite.Run("test error handling for invalid shipment addresses", func() { + + shipment := factory.BuildMTOShipment(suite.DB(), []factory.Customization{ + { + + Model: models.Address{ + StreetAddress1: "some address", + City: "city", + State: "AK", + PostalCode: "99506", + IsOconus: models.BoolPointer(true), + }, + Type: &factory.Addresses.PickupAddress, + }, + { + Model: models.MTOShipment{ + MarketCode: "i", + }, + }, + { + Model: models.Address{ + StreetAddress1: "some address", + City: "city", + State: "AK", + PostalCode: "98765", + IsOconus: models.BoolPointer(true), + }, + Type: &factory.Addresses.DeliveryAddress, + }, + }, nil) + err := models.CreateApprovedServiceItemsForShipment(suite.DB(), &shipment) + suite.Error(err) + }) } diff --git a/pkg/services/mto_shipment/mto_shipment_updater.go b/pkg/services/mto_shipment/mto_shipment_updater.go index 457234947ac..cd021e9979c 100644 --- a/pkg/services/mto_shipment/mto_shipment_updater.go +++ b/pkg/services/mto_shipment/mto_shipment_updater.go @@ -1092,13 +1092,15 @@ func reServiceCodesForShipment(shipment models.MTOShipment) []models.ReServiceCo } } case models.MTOShipmentTypeHHGIntoNTSDom: - // Need to create: Dom Linehaul, Fuel Surcharge, Dom Origin Price, Dom Destination Price, Dom NTS Packing - return []models.ReServiceCode{ - models.ReServiceCodeDLH, - models.ReServiceCodeFSC, - models.ReServiceCodeDOP, - models.ReServiceCodeDDP, - models.ReServiceCodeDNPK, + if shipment.MarketCode != models.MarketCodeInternational { + // Need to create: Dom Linehaul, Fuel Surcharge, Dom Origin Price, Dom Destination Price, Dom NTS Packing + return []models.ReServiceCode{ + models.ReServiceCodeDLH, + models.ReServiceCodeFSC, + models.ReServiceCodeDOP, + models.ReServiceCodeDDP, + models.ReServiceCodeDNPK, + } } case models.MTOShipmentTypeHHGOutOfNTSDom: // Need to create: Dom Linehaul, Fuel Surcharge, Dom Origin Price, Dom Destination Price, Dom Unpacking diff --git a/pkg/services/mto_shipment/mto_shipment_updater_test.go b/pkg/services/mto_shipment/mto_shipment_updater_test.go index aabab4f1a16..a6a4211b70b 100644 --- a/pkg/services/mto_shipment/mto_shipment_updater_test.go +++ b/pkg/services/mto_shipment/mto_shipment_updater_test.go @@ -3031,3 +3031,104 @@ func (suite *MTOShipmentServiceSuite) TestUpdateStatusServiceItems() { suite.Equal(models.ReServiceCodeDSH, serviceItems[0].ReService.Code) }) } + +func (suite *MTOShipmentServiceSuite) TestUpdateInternatinoalServiceItems() { + + expectedReServiceCodes := []models.ReServiceCode{ + models.ReServiceCodeISLH, + models.ReServiceCodePODFSC, + models.ReServiceCodeINPK, + } + + var pickupAddress models.Address + var storageFacilityDestinationAddress models.Address + var mto models.Move + + setupTestData := func() { + for i := range expectedReServiceCodes { + factory.FetchReServiceByCode(suite.DB(), expectedReServiceCodes[i]) + } + + pickupAddress = factory.BuildAddress(suite.DB(), []factory.Customization{ + { + Model: models.Address{ + StreetAddress1: "JBER", + City: "Anchorage", + State: "AK", + PostalCode: "99506", + IsOconus: models.BoolPointer(true), + }, + }, + }, nil) + + storageFacilityDestinationAddress = factory.BuildAddress(suite.DB(), []factory.Customization{ + { + Model: models.Address{ + StreetAddress1: "JBER", + City: "Anchorage", + State: "AK", + PostalCode: "99507", + IsOconus: models.BoolPointer(true), + }, + }, + }, nil) + + mto = factory.BuildMove(suite.DB(), []factory.Customization{ + { + Model: models.Move{ + Status: models.MoveStatusAPPROVED, + }, + }, + }, nil) + } + + builder := query.NewQueryBuilder() + moveRouter := moveservices.NewMoveRouter() + planner := &mocks.Planner{} + planner.On("ZipTransitDistance", + mock.AnythingOfType("*appcontext.appContext"), + mock.Anything, + mock.Anything, + ).Return(400, nil) + siCreator := mtoserviceitem.NewMTOServiceItemCreator(planner, builder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) + updater := NewMTOShipmentStatusUpdater(builder, siCreator, planner) + + suite.Run("Shipments with different origin/destination ZIP3 have longhaul service item", func() { + setupTestData() + + shipment := factory.BuildMTOShipment(suite.DB(), []factory.Customization{ + { + Model: mto, + LinkOnly: true, + }, + { + Model: pickupAddress, + Type: &factory.Addresses.PickupAddress, + LinkOnly: true, + }, + { + Model: storageFacilityDestinationAddress, + Type: &factory.Addresses.DeliveryAddress, + LinkOnly: true, + }, + { + Model: models.MTOShipment{ + ShipmentType: models.MTOShipmentTypeHHGIntoNTSDom, + Status: models.MTOShipmentStatusSubmitted, + }, + }, + }, nil) + + appCtx := suite.AppContextForTest() + eTag := etag.GenerateEtag(shipment.UpdatedAt) + + updatedShipment, err := updater.UpdateMTOShipmentStatus(appCtx, shipment.ID, models.MTOShipmentStatusApproved, nil, nil, eTag) + suite.NoError(err) + + serviceItems := models.MTOServiceItems{} + err = appCtx.DB().EagerPreload("ReService").Where("mto_shipment_id = ?", updatedShipment.ID).All(&serviceItems) + suite.NoError(err) + + suite.Equal(models.ReServiceCodeDLH, serviceItems[0].ReService.Code) + }) +} diff --git a/pkg/services/mto_shipment/shipment_approver.go b/pkg/services/mto_shipment/shipment_approver.go index 52e849e469b..b716b141024 100644 --- a/pkg/services/mto_shipment/shipment_approver.go +++ b/pkg/services/mto_shipment/shipment_approver.go @@ -2,6 +2,7 @@ package mtoshipment import ( "math" + "slices" "github.com/gofrs/uuid" "github.com/pkg/errors" @@ -77,17 +78,19 @@ func (f *shipmentApprover) ApproveShipment(appCtx appcontext.AppContext, shipmen } } - // create international shipment service items - if shipment.ShipmentType == models.MTOShipmentTypeHHG && shipment.MarketCode == models.MarketCodeInternational { + // if there are existing 're_service_items' for the international shipment then create 'mto_service_items' + internationalSi := []models.MTOShipmentType{models.MTOShipmentTypeHHG, models.MTOShipmentTypeHHGIntoNTSDom} + if slices.Contains(internationalSi, shipment.ShipmentType) && shipment.MarketCode == models.MarketCodeInternational { err := models.CreateApprovedServiceItemsForShipment(appCtx.DB(), shipment) if err != nil { return shipment, err } } + transactionError := appCtx.NewTransaction(func(txnAppCtx appcontext.AppContext) error { verrs, err := txnAppCtx.DB().ValidateAndSave(shipment) if verrs != nil && verrs.HasAny() { - invalidInputError := apperror.NewInvalidInputError(shipment.ID, nil, verrs, "There was an issue with validating the updates") + invalidInputError := apperror.NewInvalidInputError(uuid.Nil, err, nil, "There was an issue with validating the updates") return invalidInputError } diff --git a/src/components/Office/RequestedShipments/SubmittedRequestedShipments.jsx b/src/components/Office/RequestedShipments/SubmittedRequestedShipments.jsx index 62330c5ba9b..695ed8da887 100644 --- a/src/components/Office/RequestedShipments/SubmittedRequestedShipments.jsx +++ b/src/components/Office/RequestedShipments/SubmittedRequestedShipments.jsx @@ -222,9 +222,9 @@ const SubmittedRequestedShipments = ({ normalize: false, }, { - onError: () => { + onError: (error) => { setSubmitting(false); - setFlashMessage(null); + setErrorMessage(error?.message); // ('Shipment failed to update.'); }, }, ); diff --git a/src/components/Office/ShipmentForm/ShipmentForm.jsx b/src/components/Office/ShipmentForm/ShipmentForm.jsx index bb352f02bf6..5734706f3d4 100644 --- a/src/components/Office/ShipmentForm/ShipmentForm.jsx +++ b/src/components/Office/ShipmentForm/ShipmentForm.jsx @@ -606,7 +606,7 @@ const ShipmentForm = (props) => { navigate(moveDetailsPath); }, onError: (error) => { - handleSetError(error, `Something went wrong, and your changes were not saved. Please try again.`); + handleSetError(error.message, `Something went wrong, and your changes were not saved. Please try again.`); }, }, ); From 0427ed65f21ac6a1763ce15c2f7a7c93c81e8fb2 Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Wed, 11 Dec 2024 20:59:30 +0000 Subject: [PATCH 02/29] removing frontend for now --- pkg/services/mto_shipment/shipment_approver.go | 2 +- src/components/Office/ShipmentForm/ShipmentForm.jsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/services/mto_shipment/shipment_approver.go b/pkg/services/mto_shipment/shipment_approver.go index b716b141024..de413a59a59 100644 --- a/pkg/services/mto_shipment/shipment_approver.go +++ b/pkg/services/mto_shipment/shipment_approver.go @@ -90,7 +90,7 @@ func (f *shipmentApprover) ApproveShipment(appCtx appcontext.AppContext, shipmen transactionError := appCtx.NewTransaction(func(txnAppCtx appcontext.AppContext) error { verrs, err := txnAppCtx.DB().ValidateAndSave(shipment) if verrs != nil && verrs.HasAny() { - invalidInputError := apperror.NewInvalidInputError(uuid.Nil, err, nil, "There was an issue with validating the updates") + invalidInputError := apperror.NewInvalidInputError(shipment.ID, nil, verrs, "There was an issue with validating the updates") return invalidInputError } diff --git a/src/components/Office/ShipmentForm/ShipmentForm.jsx b/src/components/Office/ShipmentForm/ShipmentForm.jsx index 5734706f3d4..bb352f02bf6 100644 --- a/src/components/Office/ShipmentForm/ShipmentForm.jsx +++ b/src/components/Office/ShipmentForm/ShipmentForm.jsx @@ -606,7 +606,7 @@ const ShipmentForm = (props) => { navigate(moveDetailsPath); }, onError: (error) => { - handleSetError(error.message, `Something went wrong, and your changes were not saved. Please try again.`); + handleSetError(error, `Something went wrong, and your changes were not saved. Please try again.`); }, }, ); From c8288281363e9908048c7012c0b5d7703528587f Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Thu, 12 Dec 2024 03:29:05 +0000 Subject: [PATCH 03/29] syntax fixes and working on tests --- ..._internatinoal_nts_re_service_items.up.sql | 24 +++--- pkg/models/mto_shipments.go | 12 ++- .../mto_shipment/mto_shipment_updater_test.go | 44 ++++++----- .../mto_shipment/shipment_approver_test.go | 76 +++++++++++++++++++ 4 files changed, 117 insertions(+), 39 deletions(-) diff --git a/migrations/app/schema/20241208080706_add_internatinoal_nts_re_service_items.up.sql b/migrations/app/schema/20241208080706_add_internatinoal_nts_re_service_items.up.sql index a8df589a072..45fa84a8de1 100644 --- a/migrations/app/schema/20241208080706_add_internatinoal_nts_re_service_items.up.sql +++ b/migrations/app/schema/20241208080706_add_internatinoal_nts_re_service_items.up.sql @@ -7,16 +7,16 @@ VALUES ('2a560507-db09-4be1-b809-49c0f515b31b', '9f3d551a-0725-430e-897e-80ee9add3ae9' ,'HHG_INTO_NTS_DOMESTIC', 'i', true, now(), now(), 1), ('366ee5a4-eb61-4ded-a68c-ddc29fe1a886', '874cb86a-bc39-4f57-a614-53ee3fcacf14' ,'HHG_INTO_NTS_DOMESTIC', 'i', true, now(), now(), 2), ('e702818f-defd-452c-81a3-865b902e7dd0', '388115e8-abe9-441d-96cf-a39f24baa0a3' ,'HHG_INTO_NTS_DOMESTIC', 'i', true, now(), now(), 3), - ('aac4e95e-27ed-4f09-9b6b-384d8542f410', '86203d72-7f7c-49ff-82f0-5b95e4958f60' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), nil), - ('010f2f91-7381-4149-8d74-8eb5f593a864', '806c6d59-57ff-4a3f-9518-ebf29ba9cb10' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), nil), - ('a41966b7-b83a-4eaf-8e68-d5e884777102', '28389ee1-56cf-400c-aa52-1501ecdd7c69' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), nil), - ('14c77957-3c76-465a-bb07-c98d36ef1e54', 'bd6064ca-e780-4ab4-a37b-0ae98eebb244' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), nil), - ('d52d2d03-100a-4ed9-b2de-16eac63a375f', '22fc07ed-be15-4f50-b941-cbd38153b378' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), nil), - ('7fd91408-7d69-4375-b7e6-5b2ff714206b', 'bd424e45-397b-4766-9712-de4ae3a2da36' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), nil), - ('b3dc509d-d652-4300-a702-a1ddce6255b6', 'b488bf85-ea5e-49c8-ba5c-e2fa278ac806' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), nil), - ('001eadb6-3526-45b9-96e0-0648bb481e86', '6f4f6e31-0675-4051-b659-89832259f390' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), nil), - ('b991c5c9-af2c-4146-b999-1d0bdf91de3f', '624a97c5-dfbf-4da9-a6e9-526b4f95af8d' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), nil), - ('5a89315a-257b-4ef0-92cb-4c06aa6f1332', '4132416b-b1aa-42e7-98f2-0ac0a03e8a31' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), nil), - ('d4a98dea-a5f7-4b92-b5de-e6350ab07824', '81e29d0c-02a6-4a7a-be02-554deb3ee49e' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), nil), - ('eaea90c2-93d3-4db9-89cd-23ac57ec9ce1', '690a5fc1-0ea5-4554-8294-a367b5daefa9' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), nil); + ('aac4e95e-27ed-4f09-9b6b-384d8542f410', '86203d72-7f7c-49ff-82f0-5b95e4958f60' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), NULL), + ('010f2f91-7381-4149-8d74-8eb5f593a864', '806c6d59-57ff-4a3f-9518-ebf29ba9cb10' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), NULL), + ('a41966b7-b83a-4eaf-8e68-d5e884777102', '28389ee1-56cf-400c-aa52-1501ecdd7c69' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), NULL), + ('14c77957-3c76-465a-bb07-c98d36ef1e54', 'bd6064ca-e780-4ab4-a37b-0ae98eebb244' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), NULL), + ('d52d2d03-100a-4ed9-b2de-16eac63a375f', '22fc07ed-be15-4f50-b941-cbd38153b378' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), NULL), + ('7fd91408-7d69-4375-b7e6-5b2ff714206b', 'bd424e45-397b-4766-9712-de4ae3a2da36' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), NULL), + ('b3dc509d-d652-4300-a702-a1ddce6255b6', 'b488bf85-ea5e-49c8-ba5c-e2fa278ac806' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), NULL), + ('001eadb6-3526-45b9-96e0-0648bb481e86', '6f4f6e31-0675-4051-b659-89832259f390' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), NULL), + ('b991c5c9-af2c-4146-b999-1d0bdf91de3f', '624a97c5-dfbf-4da9-a6e9-526b4f95af8d' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), NULL), + ('5a89315a-257b-4ef0-92cb-4c06aa6f1332', '4132416b-b1aa-42e7-98f2-0ac0a03e8a31' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), NULL), + ('d4a98dea-a5f7-4b92-b5de-e6350ab07824', '81e29d0c-02a6-4a7a-be02-554deb3ee49e' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), NULL), + ('eaea90c2-93d3-4db9-89cd-23ac57ec9ce1', '690a5fc1-0ea5-4554-8294-a367b5daefa9' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), NULL); diff --git a/pkg/models/mto_shipments.go b/pkg/models/mto_shipments.go index b71d4d40996..8e454ee81a1 100644 --- a/pkg/models/mto_shipments.go +++ b/pkg/models/mto_shipments.go @@ -420,14 +420,12 @@ func DetermineMarketCode(address1 *Address, address2 *Address) (MarketCode, erro } func CreateApprovedServiceItemsForShipment(db *pop.Connection, shipment *MTOShipment) error { - // check if at least one pickup or destination/storage facility address is conus. - if (shipment.PickupAddress != nil && shipment.DestinationAddress != nil) || (shipment.PickupAddress != nil && shipment.StorageFacility != nil) { - if (*shipment.PickupAddress.IsOconus && *shipment.DestinationAddress.IsOconus) || - (*shipment.PickupAddress.IsOconus && *shipment.StorageFacility.Address.IsOconus) { - err := apperror.NewConflictError(shipment.ID, "cannot handle shipments from oconus to oconus") - return err - } + if shipment.PickupAddress != nil && shipment.DestinationAddress != nil && + *shipment.PickupAddress.IsOconus && *shipment.DestinationAddress.IsOconus { + err := apperror.NewConflictError(shipment.ID, "cannot handle shipments from oconus to oconus") + return err } + err := db.RawQuery("CALL create_approved_service_items_for_shipment($1)", shipment.ID).Exec() if err != nil { return fmt.Errorf("error creating approved service items: %w", err) diff --git a/pkg/services/mto_shipment/mto_shipment_updater_test.go b/pkg/services/mto_shipment/mto_shipment_updater_test.go index a6a4211b70b..1dd62295336 100644 --- a/pkg/services/mto_shipment/mto_shipment_updater_test.go +++ b/pkg/services/mto_shipment/mto_shipment_updater_test.go @@ -3032,16 +3032,18 @@ func (suite *MTOShipmentServiceSuite) TestUpdateStatusServiceItems() { }) } -func (suite *MTOShipmentServiceSuite) TestUpdateInternatinoalServiceItems() { +func (suite *MTOShipmentServiceSuite) TestUpdateDomesticServiceItems() { expectedReServiceCodes := []models.ReServiceCode{ - models.ReServiceCodeISLH, - models.ReServiceCodePODFSC, - models.ReServiceCodeINPK, + models.ReServiceCodeDLH, + models.ReServiceCodeFSC, + models.ReServiceCodeDOP, + models.ReServiceCodeDDP, + models.ReServiceCodeDNPK, } var pickupAddress models.Address - var storageFacilityDestinationAddress models.Address + var storageFacility models.StorageFacility var mto models.Move setupTestData := func() { @@ -3052,23 +3054,23 @@ func (suite *MTOShipmentServiceSuite) TestUpdateInternatinoalServiceItems() { pickupAddress = factory.BuildAddress(suite.DB(), []factory.Customization{ { Model: models.Address{ - StreetAddress1: "JBER", - City: "Anchorage", - State: "AK", - PostalCode: "99506", - IsOconus: models.BoolPointer(true), + StreetAddress1: "Test Street 1", + City: "Des moines", + State: "IA", + PostalCode: "50309", + IsOconus: models.BoolPointer(false), }, }, }, nil) - storageFacilityDestinationAddress = factory.BuildAddress(suite.DB(), []factory.Customization{ + storageFacility = factory.BuildStorageFacility(suite.DB(), []factory.Customization{ { Model: models.Address{ - StreetAddress1: "JBER", - City: "Anchorage", - State: "AK", - PostalCode: "99507", - IsOconus: models.BoolPointer(true), + StreetAddress1: "Test Street Adress 2", + City: "Des moines", + State: "IA", + PostalCode: "50314", + IsOconus: models.BoolPointer(false), }, }, }, nil) @@ -3093,7 +3095,7 @@ func (suite *MTOShipmentServiceSuite) TestUpdateInternatinoalServiceItems() { siCreator := mtoserviceitem.NewMTOServiceItemCreator(planner, builder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) updater := NewMTOShipmentStatusUpdater(builder, siCreator, planner) - suite.Run("Shipments with different origin/destination ZIP3 have longhaul service item", func() { + suite.Run("Preapproved service items successfully added to domestic nts shipments", func() { setupTestData() shipment := factory.BuildMTOShipment(suite.DB(), []factory.Customization{ @@ -3107,8 +3109,8 @@ func (suite *MTOShipmentServiceSuite) TestUpdateInternatinoalServiceItems() { LinkOnly: true, }, { - Model: storageFacilityDestinationAddress, - Type: &factory.Addresses.DeliveryAddress, + Model: storageFacility, + Type: &factory.StorageFacility, LinkOnly: true, }, { @@ -3129,6 +3131,8 @@ func (suite *MTOShipmentServiceSuite) TestUpdateInternatinoalServiceItems() { err = appCtx.DB().EagerPreload("ReService").Where("mto_shipment_id = ?", updatedShipment.ID).All(&serviceItems) suite.NoError(err) - suite.Equal(models.ReServiceCodeDLH, serviceItems[0].ReService.Code) + for i := 0; i < len(expectedReServiceCodes); i++ { + suite.Equal(expectedReServiceCodes[i], serviceItems[i].ReService.Code) + } }) } diff --git a/pkg/services/mto_shipment/shipment_approver_test.go b/pkg/services/mto_shipment/shipment_approver_test.go index 943cd4edb72..ce503e99480 100644 --- a/pkg/services/mto_shipment/shipment_approver_test.go +++ b/pkg/services/mto_shipment/shipment_approver_test.go @@ -255,6 +255,82 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { } }) + // TODO: find out why service items aren't being added for nts shipment only in tests + // suite.Run("Given international mtoShipment is approved successfully pre-approved mtoServiceItems are created NTS", func() { + // storageFacility := factory.BuildStorageFacility(suite.DB(), []factory.Customization{ + // { + // Model: models.StorageFacility{ + // Email: models.StringPointer("old@email.com"), + // }, + // }, + // { + // Model: models.Address{ + // StreetAddress1: "JBER", + // City: "Anchorage", + // State: "AK", + // PostalCode: "99507", + // IsOconus: models.BoolPointer(true), + // }, + // }, + // }, nil) + // internationalShipment := factory.BuildMTOShipment(suite.AppContextForTest().DB(), []factory.Customization{ + // { + // Model: models.Move{ + // Status: models.MoveStatusAPPROVED, + // }, + // }, + // { + // Model: models.Address{ + // StreetAddress1: "Tester Address", + // City: "Des Moines", + // State: "IA", + // PostalCode: "50314", + // IsOconus: models.BoolPointer(false), + // }, + // Type: &factory.Addresses.PickupAddress, + // }, + // { + // Model: models.MTOShipment{ + // MarketCode: "i", + // Status: models.MTOShipmentStatusSubmitted, + // ShipmentType: models.MTOShipmentTypeHHGIntoNTSDom, + // }, + // }, + // { + // Model: storageFacility, + // LinkOnly: true, + // }, + // }, nil) + // internationalShipmentEtag := etag.GenerateEtag(internationalShipment.UpdatedAt) + + // shipmentRouter := NewShipmentRouter() + // var serviceItemCreator services.MTOServiceItemCreator + // var planner route.Planner + // var moveWeights services.MoveWeights + + // // Approve international shipment + // shipmentApprover := NewShipmentApprover(shipmentRouter, serviceItemCreator, planner, moveWeights) + // _, err := shipmentApprover.ApproveShipment(suite.AppContextForTest(), internationalShipment.ID, internationalShipmentEtag) + // suite.NoError(err) + + // // Get created pre approved service items + // var serviceItems []models.MTOServiceItem + // err2 := suite.AppContextForTest().DB().EagerPreload("ReService").Where("mto_shipment_id = ?", internationalShipment.ID).Order("created_at asc").All(&serviceItems) + // suite.NoError(err2) + + // expectedReserviceCodes := []models.ReServiceCode{ + // models.ReServiceCodeISLH, + // models.ReServiceCodePODFSC, + // models.ReServiceCodeINPK, + // } + + // suite.Equal(len(expectedReserviceCodes), len(serviceItems)) + // for i := 0; i < len(serviceItems); i++ { + // actualReServiceCode := serviceItems[i].ReService.Code + // suite.True(slices.Contains(expectedReserviceCodes, actualReServiceCode)) + // } + // }) + suite.Run("If the mtoShipment is approved successfully it should create approved mtoServiceItems", func() { subtestData := suite.createApproveShipmentSubtestData() appCtx := subtestData.appCtx From 89ef13e0bfd5dd8089be98504f004abf2a0b949c Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Thu, 12 Dec 2024 15:23:44 +0000 Subject: [PATCH 04/29] removing added error logic and its handling --- pkg/models/mto_shipments.go | 7 ---- pkg/models/mto_shipments_test.go | 34 ------------------- .../SubmittedRequestedShipments.jsx | 4 +-- 3 files changed, 2 insertions(+), 43 deletions(-) diff --git a/pkg/models/mto_shipments.go b/pkg/models/mto_shipments.go index 8e454ee81a1..0d0885ded6a 100644 --- a/pkg/models/mto_shipments.go +++ b/pkg/models/mto_shipments.go @@ -10,7 +10,6 @@ import ( "github.com/gofrs/uuid" "github.com/pkg/errors" - "github.com/transcom/mymove/pkg/apperror" "github.com/transcom/mymove/pkg/unit" ) @@ -420,12 +419,6 @@ func DetermineMarketCode(address1 *Address, address2 *Address) (MarketCode, erro } func CreateApprovedServiceItemsForShipment(db *pop.Connection, shipment *MTOShipment) error { - if shipment.PickupAddress != nil && shipment.DestinationAddress != nil && - *shipment.PickupAddress.IsOconus && *shipment.DestinationAddress.IsOconus { - err := apperror.NewConflictError(shipment.ID, "cannot handle shipments from oconus to oconus") - return err - } - err := db.RawQuery("CALL create_approved_service_items_for_shipment($1)", shipment.ID).Exec() if err != nil { return fmt.Errorf("error creating approved service items: %w", err) diff --git a/pkg/models/mto_shipments_test.go b/pkg/models/mto_shipments_test.go index 1336b6d9b66..5f2a5f78864 100644 --- a/pkg/models/mto_shipments_test.go +++ b/pkg/models/mto_shipments_test.go @@ -323,38 +323,4 @@ func (suite *ModelSuite) TestCreateApprovedServiceItemsForShipment() { err := models.CreateApprovedServiceItemsForShipment(suite.DB(), &invalidShipment) suite.Error(err) }) - - suite.Run("test error handling for invalid shipment addresses", func() { - - shipment := factory.BuildMTOShipment(suite.DB(), []factory.Customization{ - { - - Model: models.Address{ - StreetAddress1: "some address", - City: "city", - State: "AK", - PostalCode: "99506", - IsOconus: models.BoolPointer(true), - }, - Type: &factory.Addresses.PickupAddress, - }, - { - Model: models.MTOShipment{ - MarketCode: "i", - }, - }, - { - Model: models.Address{ - StreetAddress1: "some address", - City: "city", - State: "AK", - PostalCode: "98765", - IsOconus: models.BoolPointer(true), - }, - Type: &factory.Addresses.DeliveryAddress, - }, - }, nil) - err := models.CreateApprovedServiceItemsForShipment(suite.DB(), &shipment) - suite.Error(err) - }) } diff --git a/src/components/Office/RequestedShipments/SubmittedRequestedShipments.jsx b/src/components/Office/RequestedShipments/SubmittedRequestedShipments.jsx index 695ed8da887..62330c5ba9b 100644 --- a/src/components/Office/RequestedShipments/SubmittedRequestedShipments.jsx +++ b/src/components/Office/RequestedShipments/SubmittedRequestedShipments.jsx @@ -222,9 +222,9 @@ const SubmittedRequestedShipments = ({ normalize: false, }, { - onError: (error) => { + onError: () => { setSubmitting(false); - setErrorMessage(error?.message); // ('Shipment failed to update.'); + setFlashMessage(null); }, }, ); From b3995e6866663e48e28cb04c6b103e614dc2e05d Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Thu, 12 Dec 2024 15:39:48 +0000 Subject: [PATCH 05/29] testing --- .../mto_shipment/shipment_approver_test.go | 154 +++++++++--------- 1 file changed, 79 insertions(+), 75 deletions(-) diff --git a/pkg/services/mto_shipment/shipment_approver_test.go b/pkg/services/mto_shipment/shipment_approver_test.go index ce503e99480..bcdcf6c8ce0 100644 --- a/pkg/services/mto_shipment/shipment_approver_test.go +++ b/pkg/services/mto_shipment/shipment_approver_test.go @@ -256,80 +256,84 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { }) // TODO: find out why service items aren't being added for nts shipment only in tests - // suite.Run("Given international mtoShipment is approved successfully pre-approved mtoServiceItems are created NTS", func() { - // storageFacility := factory.BuildStorageFacility(suite.DB(), []factory.Customization{ - // { - // Model: models.StorageFacility{ - // Email: models.StringPointer("old@email.com"), - // }, - // }, - // { - // Model: models.Address{ - // StreetAddress1: "JBER", - // City: "Anchorage", - // State: "AK", - // PostalCode: "99507", - // IsOconus: models.BoolPointer(true), - // }, - // }, - // }, nil) - // internationalShipment := factory.BuildMTOShipment(suite.AppContextForTest().DB(), []factory.Customization{ - // { - // Model: models.Move{ - // Status: models.MoveStatusAPPROVED, - // }, - // }, - // { - // Model: models.Address{ - // StreetAddress1: "Tester Address", - // City: "Des Moines", - // State: "IA", - // PostalCode: "50314", - // IsOconus: models.BoolPointer(false), - // }, - // Type: &factory.Addresses.PickupAddress, - // }, - // { - // Model: models.MTOShipment{ - // MarketCode: "i", - // Status: models.MTOShipmentStatusSubmitted, - // ShipmentType: models.MTOShipmentTypeHHGIntoNTSDom, - // }, - // }, - // { - // Model: storageFacility, - // LinkOnly: true, - // }, - // }, nil) - // internationalShipmentEtag := etag.GenerateEtag(internationalShipment.UpdatedAt) - - // shipmentRouter := NewShipmentRouter() - // var serviceItemCreator services.MTOServiceItemCreator - // var planner route.Planner - // var moveWeights services.MoveWeights - - // // Approve international shipment - // shipmentApprover := NewShipmentApprover(shipmentRouter, serviceItemCreator, planner, moveWeights) - // _, err := shipmentApprover.ApproveShipment(suite.AppContextForTest(), internationalShipment.ID, internationalShipmentEtag) - // suite.NoError(err) - - // // Get created pre approved service items - // var serviceItems []models.MTOServiceItem - // err2 := suite.AppContextForTest().DB().EagerPreload("ReService").Where("mto_shipment_id = ?", internationalShipment.ID).Order("created_at asc").All(&serviceItems) - // suite.NoError(err2) - - // expectedReserviceCodes := []models.ReServiceCode{ - // models.ReServiceCodeISLH, - // models.ReServiceCodePODFSC, - // models.ReServiceCodeINPK, - // } - - // suite.Equal(len(expectedReserviceCodes), len(serviceItems)) - // for i := 0; i < len(serviceItems); i++ { - // actualReServiceCode := serviceItems[i].ReService.Code - // suite.True(slices.Contains(expectedReserviceCodes, actualReServiceCode)) - // } - // }) + suite.Run("Given international mtoShipment is approved successfully pre-approved mtoServiceItems are created NTS", func() { + storageFacility := factory.BuildStorageFacility(suite.AppContextForTest().DB(), []factory.Customization{ + { + Model: models.StorageFacility{ + FacilityName: *models.StringPointer("Test Storage Name"), + Email: models.StringPointer("old@email.com"), + LotNumber: models.StringPointer("Test lot number"), + Phone: models.StringPointer("555-555-5555"), + }, + }, + { + Model: models.Address{ + StreetAddress1: "JBER", + City: "Anchorage", + State: "AK", + PostalCode: "99507", + IsOconus: models.BoolPointer(true), + }, + }, + }, nil) + + internationalShipment := factory.BuildMTOShipment(suite.AppContextForTest().DB(), []factory.Customization{ + { + Model: models.Move{ + Status: models.MoveStatusAPPROVED, + }, + }, + { + Model: models.Address{ + StreetAddress1: "Tester Address", + City: "Des Moines", + State: "IA", + PostalCode: "50314", + IsOconus: models.BoolPointer(false), + }, + Type: &factory.Addresses.PickupAddress, + }, + { + Model: models.MTOShipment{ + MarketCode: "i", + Status: models.MTOShipmentStatusSubmitted, + ShipmentType: models.MTOShipmentTypeHHGIntoNTSDom, + }, + }, + { + Model: storageFacility, + LinkOnly: true, + }, + }, nil) + internationalShipmentEtag := etag.GenerateEtag(internationalShipment.UpdatedAt) + + shipmentRouter := NewShipmentRouter() + var serviceItemCreator services.MTOServiceItemCreator + var planner route.Planner + var moveWeights services.MoveWeights + + // Approve international shipment + shipmentApprover := NewShipmentApprover(shipmentRouter, serviceItemCreator, planner, moveWeights) + _, err := shipmentApprover.ApproveShipment(suite.AppContextForTest(), internationalShipment.ID, internationalShipmentEtag) + suite.NoError(err) + + // Get created pre approved service items + var serviceItems []models.MTOServiceItem + err2 := suite.AppContextForTest().DB().EagerPreload("ReService").Where("mto_shipment_id = ?", internationalShipment.ID).Order("created_at asc").All(&serviceItems) + suite.NoError(err2) + + expectedReserviceCodes := []models.ReServiceCode{ + models.ReServiceCodeISLH, + models.ReServiceCodePODFSC, + models.ReServiceCodeINPK, + } + + suite.Equal(len(expectedReserviceCodes), len(serviceItems)) + for i := 0; i < len(serviceItems); i++ { + actualReServiceCode := serviceItems[i].ReService.Code + suite.True(slices.Contains(expectedReserviceCodes, actualReServiceCode)) + } + }) suite.Run("If the mtoShipment is approved successfully it should create approved mtoServiceItems", func() { subtestData := suite.createApproveShipmentSubtestData() @@ -339,7 +343,7 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { planner := subtestData.planner estimatedWeight := unit.Pound(1212) - shipmentForAutoApprove := factory.BuildMTOShipment(appCtx.DB(), []factory.Customization{ + shipmentForAutoApprove := factory.BuildMTOShipment(suite.AppContextForTest().DB(), []factory.Customization{ { Model: move, LinkOnly: true, From 6ad5618b98f45b1262fb34d788a94519f862d7af Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Thu, 12 Dec 2024 16:05:30 +0000 Subject: [PATCH 06/29] testing --- pkg/services/mto_shipment/shipment_approver_test.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/services/mto_shipment/shipment_approver_test.go b/pkg/services/mto_shipment/shipment_approver_test.go index bcdcf6c8ce0..87d95eea7a6 100644 --- a/pkg/services/mto_shipment/shipment_approver_test.go +++ b/pkg/services/mto_shipment/shipment_approver_test.go @@ -257,7 +257,7 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { // TODO: find out why service items aren't being added for nts shipment only in tests suite.Run("Given international mtoShipment is approved successfully pre-approved mtoServiceItems are created NTS", func() { - storageFacility := factory.BuildStorageFacility(suite.AppContextForTest().DB(), []factory.Customization{ + storageFacility := factory.BuildStorageFacility(suite.DB(), []factory.Customization{ { Model: models.StorageFacility{ FacilityName: *models.StringPointer("Test Storage Name"), @@ -277,7 +277,7 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { }, }, nil) - internationalShipment := factory.BuildMTOShipment(suite.AppContextForTest().DB(), []factory.Customization{ + internationalShipment := factory.BuildMTOShipment(suite.DB(), []factory.Customization{ { Model: models.Move{ Status: models.MoveStatusAPPROVED, @@ -324,7 +324,6 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { expectedReserviceCodes := []models.ReServiceCode{ models.ReServiceCodeISLH, - models.ReServiceCodePODFSC, models.ReServiceCodeINPK, } @@ -343,7 +342,7 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { planner := subtestData.planner estimatedWeight := unit.Pound(1212) - shipmentForAutoApprove := factory.BuildMTOShipment(suite.AppContextForTest().DB(), []factory.Customization{ + shipmentForAutoApprove := factory.BuildMTOShipment(appCtx.DB(), []factory.Customization{ { Model: move, LinkOnly: true, From cd85f86fb9e56d7e50c427f2b214d65e39f08ef3 Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Thu, 12 Dec 2024 19:56:06 +0000 Subject: [PATCH 07/29] adding invalid check for more coverage --- .../mto_shipment/shipment_approver_test.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pkg/services/mto_shipment/shipment_approver_test.go b/pkg/services/mto_shipment/shipment_approver_test.go index 87d95eea7a6..83b2ae35316 100644 --- a/pkg/services/mto_shipment/shipment_approver_test.go +++ b/pkg/services/mto_shipment/shipment_approver_test.go @@ -190,7 +190,7 @@ func (suite *MTOShipmentServiceSuite) createApproveShipmentSubtestData() (subtes } func (suite *MTOShipmentServiceSuite) TestApproveShipment() { - suite.Run("If the international mtoShipment is approved successfully it should create pre approved mtoServiceItems", func() { + suite.Run("Given international mtoShipment is approved successfully pre-approved mtoServiceItems are created HHG", func() { internationalShipment := factory.BuildMTOShipment(suite.AppContextForTest().DB(), []factory.Customization{ { Model: models.Move{ @@ -255,7 +255,6 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { } }) - // TODO: find out why service items aren't being added for nts shipment only in tests suite.Run("Given international mtoShipment is approved successfully pre-approved mtoServiceItems are created NTS", func() { storageFacility := factory.BuildStorageFacility(suite.DB(), []factory.Customization{ { @@ -866,4 +865,19 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { suite.NotNil(shipment.MoveTaskOrder.ExcessWeightQualifiedAt) }) + + suite.Run("Given invalid shipment error returned", func() { + invalidShipment := models.MTOShipment{} + invalidShipmentEtag := etag.GenerateEtag(invalidShipment.UpdatedAt) + + shipmentRouter := NewShipmentRouter() + var serviceItemCreator services.MTOServiceItemCreator + var planner route.Planner + var moveWeights services.MoveWeights + + // Approve international shipment + shipmentApprover := NewShipmentApprover(shipmentRouter, serviceItemCreator, planner, moveWeights) + _, err := shipmentApprover.ApproveShipment(suite.AppContextForTest(), invalidShipment.ID, invalidShipmentEtag) + suite.Error(err) + }) } From 76845c073c76f7a6b64bac44811c7b9a5f7d6a85 Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Fri, 13 Dec 2024 18:58:43 +0000 Subject: [PATCH 08/29] fix ordering --- ...241208080706_add_internatinoal_nts_re_service_items.up.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/migrations/app/schema/20241208080706_add_internatinoal_nts_re_service_items.up.sql b/migrations/app/schema/20241208080706_add_internatinoal_nts_re_service_items.up.sql index 45fa84a8de1..58e986de48a 100644 --- a/migrations/app/schema/20241208080706_add_internatinoal_nts_re_service_items.up.sql +++ b/migrations/app/schema/20241208080706_add_internatinoal_nts_re_service_items.up.sql @@ -5,8 +5,8 @@ INSERT INTO re_service_items (id, service_id, shipment_type, market_code, is_auto_approved, created_at, updated_at, sort) VALUES ('2a560507-db09-4be1-b809-49c0f515b31b', '9f3d551a-0725-430e-897e-80ee9add3ae9' ,'HHG_INTO_NTS_DOMESTIC', 'i', true, now(), now(), 1), - ('366ee5a4-eb61-4ded-a68c-ddc29fe1a886', '874cb86a-bc39-4f57-a614-53ee3fcacf14' ,'HHG_INTO_NTS_DOMESTIC', 'i', true, now(), now(), 2), - ('e702818f-defd-452c-81a3-865b902e7dd0', '388115e8-abe9-441d-96cf-a39f24baa0a3' ,'HHG_INTO_NTS_DOMESTIC', 'i', true, now(), now(), 3), + ('e702818f-defd-452c-81a3-865b902e7dd0', '388115e8-abe9-441d-96cf-a39f24baa0a3' ,'HHG_INTO_NTS_DOMESTIC', 'i', true, now(), now(), 2), + ('366ee5a4-eb61-4ded-a68c-ddc29fe1a886', '874cb86a-bc39-4f57-a614-53ee3fcacf14' ,'HHG_INTO_NTS_DOMESTIC', 'i', true, now(), now(), 3), ('aac4e95e-27ed-4f09-9b6b-384d8542f410', '86203d72-7f7c-49ff-82f0-5b95e4958f60' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), NULL), ('010f2f91-7381-4149-8d74-8eb5f593a864', '806c6d59-57ff-4a3f-9518-ebf29ba9cb10' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), NULL), ('a41966b7-b83a-4eaf-8e68-d5e884777102', '28389ee1-56cf-400c-aa52-1501ecdd7c69' ,'HHG_INTO_NTS_DOMESTIC', 'i', false, now(), now(), NULL), From 70387dd4918ca4bb2b41d0d868f21e8bc7e0f453 Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Mon, 16 Dec 2024 18:47:12 +0000 Subject: [PATCH 09/29] working comments --- pkg/services/mto_shipment/shipment_approver.go | 18 ++++++++++-------- .../mto_shipment/shipment_approver_test.go | 12 +++++++++--- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/pkg/services/mto_shipment/shipment_approver.go b/pkg/services/mto_shipment/shipment_approver.go index de413a59a59..0c1e916808f 100644 --- a/pkg/services/mto_shipment/shipment_approver.go +++ b/pkg/services/mto_shipment/shipment_approver.go @@ -78,16 +78,18 @@ func (f *shipmentApprover) ApproveShipment(appCtx appcontext.AppContext, shipmen } } - // if there are existing 're_service_items' for the international shipment then create 'mto_service_items' - internationalSi := []models.MTOShipmentType{models.MTOShipmentTypeHHG, models.MTOShipmentTypeHHGIntoNTSDom} - if slices.Contains(internationalSi, shipment.ShipmentType) && shipment.MarketCode == models.MarketCodeInternational { - err := models.CreateApprovedServiceItemsForShipment(appCtx.DB(), shipment) - if err != nil { - return shipment, err + transactionError := appCtx.NewTransaction(func(txnAppCtx appcontext.AppContext) error { + + // If there are existing 're_service_items' for the international shipment then create 'mto_service_items' + // These are currently the shipment types we handle but add any additional international shipment types here + internationalShipmentTypes := []models.MTOShipmentType{models.MTOShipmentTypeHHG, models.MTOShipmentTypeHHGIntoNTSDom} + if slices.Contains(internationalShipmentTypes, shipment.ShipmentType) && shipment.MarketCode == models.MarketCodeInternational { + err := models.CreateApprovedServiceItemsForShipment(appCtx.DB(), shipment) + if err != nil { + return err + } } - } - transactionError := appCtx.NewTransaction(func(txnAppCtx appcontext.AppContext) error { verrs, err := txnAppCtx.DB().ValidateAndSave(shipment) if verrs != nil && verrs.HasAny() { invalidInputError := apperror.NewInvalidInputError(shipment.ID, nil, verrs, "There was an issue with validating the updates") diff --git a/pkg/services/mto_shipment/shipment_approver_test.go b/pkg/services/mto_shipment/shipment_approver_test.go index 83b2ae35316..6f0cf6237ba 100644 --- a/pkg/services/mto_shipment/shipment_approver_test.go +++ b/pkg/services/mto_shipment/shipment_approver_test.go @@ -209,7 +209,7 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { }, { Model: models.MTOShipment{ - MarketCode: "i", + MarketCode: models.MarketCodeInternational, Status: models.MTOShipmentStatusSubmitted, }, }, @@ -294,7 +294,7 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { }, { Model: models.MTOShipment{ - MarketCode: "i", + MarketCode: models.MarketCodeInternational, Status: models.MTOShipmentStatusSubmitted, ShipmentType: models.MTOShipmentTypeHHGIntoNTSDom, }, @@ -867,7 +867,13 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { }) suite.Run("Given invalid shipment error returned", func() { - invalidShipment := models.MTOShipment{} + invalidShipment := factory.BuildMTOShipment(suite.AppContextForTest().DB(), []factory.Customization{ + { + Model: models.MTOShipment{ + ShipmentType: models.MTOShipmentTypePPM, + }, + }, + }, nil) invalidShipmentEtag := etag.GenerateEtag(invalidShipment.UpdatedAt) shipmentRouter := NewShipmentRouter() From d4e41949b98d51c929e5e9bd0cb9893b47f0c853 Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Wed, 18 Dec 2024 21:04:53 +0000 Subject: [PATCH 10/29] add int changes and generate new migration file --- migrations/app/migrations_manifest.txt | 1 + ...add_international_nts_service_items.up.sql | 21 ++++ .../mto_shipment/mto_shipment_updater.go | 16 +-- .../mto_shipment/mto_shipment_updater_test.go | 105 ++++++++++++++++++ .../mto_shipment/shipment_approver.go | 19 ++-- .../mto_shipment/shipment_approver_test.go | 103 ++++++++++++++++- 6 files changed, 249 insertions(+), 16 deletions(-) create mode 100644 migrations/app/schema/20241218204620_add_international_nts_service_items.up.sql diff --git a/migrations/app/migrations_manifest.txt b/migrations/app/migrations_manifest.txt index 3f453bf1226..0b91d4bfe2a 100644 --- a/migrations/app/migrations_manifest.txt +++ b/migrations/app/migrations_manifest.txt @@ -1051,3 +1051,4 @@ 20241204155919_update_ordering_proc.up.sql 20241204210208_retroactive_update_of_ppm_max_and_estimated_incentives_prd.up.sql 20241216170325_update_nts_enum_name.up.sql +20241218204620_add_international_nts_service_items.up.sql diff --git a/migrations/app/schema/20241218204620_add_international_nts_service_items.up.sql b/migrations/app/schema/20241218204620_add_international_nts_service_items.up.sql new file mode 100644 index 00000000000..2bb5207813f --- /dev/null +++ b/migrations/app/schema/20241218204620_add_international_nts_service_items.up.sql @@ -0,0 +1,21 @@ +-- +-- Add service items for international NTS shipments. +-- +INSERT INTO re_service_items +(id, service_id, shipment_type, market_code, is_auto_approved, created_at, updated_at, sort) +VALUES + ('2a560507-db09-4be1-b809-49c0f515b31b', '9f3d551a-0725-430e-897e-80ee9add3ae9' ,'HHG_INTO_NTS', 'i', true, now(), now(), 1), + ('e702818f-defd-452c-81a3-865b902e7dd0', '388115e8-abe9-441d-96cf-a39f24baa0a3' ,'HHG_INTO_NTS', 'i', true, now(), now(), 2), + ('366ee5a4-eb61-4ded-a68c-ddc29fe1a886', '874cb86a-bc39-4f57-a614-53ee3fcacf14' ,'HHG_INTO_NTS', 'i', true, now(), now(), 3), + ('aac4e95e-27ed-4f09-9b6b-384d8542f410', '86203d72-7f7c-49ff-82f0-5b95e4958f60' ,'HHG_INTO_NTS', 'i', false, now(), now(), NULL), + ('010f2f91-7381-4149-8d74-8eb5f593a864', '806c6d59-57ff-4a3f-9518-ebf29ba9cb10' ,'HHG_INTO_NTS', 'i', false, now(), now(), NULL), + ('a41966b7-b83a-4eaf-8e68-d5e884777102', '28389ee1-56cf-400c-aa52-1501ecdd7c69' ,'HHG_INTO_NTS', 'i', false, now(), now(), NULL), + ('14c77957-3c76-465a-bb07-c98d36ef1e54', 'bd6064ca-e780-4ab4-a37b-0ae98eebb244' ,'HHG_INTO_NTS', 'i', false, now(), now(), NULL), + ('d52d2d03-100a-4ed9-b2de-16eac63a375f', '22fc07ed-be15-4f50-b941-cbd38153b378' ,'HHG_INTO_NTS', 'i', false, now(), now(), NULL), + ('7fd91408-7d69-4375-b7e6-5b2ff714206b', 'bd424e45-397b-4766-9712-de4ae3a2da36' ,'HHG_INTO_NTS', 'i', false, now(), now(), NULL), + ('b3dc509d-d652-4300-a702-a1ddce6255b6', 'b488bf85-ea5e-49c8-ba5c-e2fa278ac806' ,'HHG_INTO_NTS', 'i', false, now(), now(), NULL), + ('001eadb6-3526-45b9-96e0-0648bb481e86', '6f4f6e31-0675-4051-b659-89832259f390' ,'HHG_INTO_NTS', 'i', false, now(), now(), NULL), + ('b991c5c9-af2c-4146-b999-1d0bdf91de3f', '624a97c5-dfbf-4da9-a6e9-526b4f95af8d' ,'HHG_INTO_NTS', 'i', false, now(), now(), NULL), + ('5a89315a-257b-4ef0-92cb-4c06aa6f1332', '4132416b-b1aa-42e7-98f2-0ac0a03e8a31' ,'HHG_INTO_NTS', 'i', false, now(), now(), NULL), + ('d4a98dea-a5f7-4b92-b5de-e6350ab07824', '81e29d0c-02a6-4a7a-be02-554deb3ee49e' ,'HHG_INTO_NTS', 'i', false, now(), now(), NULL), + ('eaea90c2-93d3-4db9-89cd-23ac57ec9ce1', '690a5fc1-0ea5-4554-8294-a367b5daefa9' ,'HHG_INTO_NTS', 'i', false, now(), now(), NULL); diff --git a/pkg/services/mto_shipment/mto_shipment_updater.go b/pkg/services/mto_shipment/mto_shipment_updater.go index 21b54188170..1c67d6f578a 100644 --- a/pkg/services/mto_shipment/mto_shipment_updater.go +++ b/pkg/services/mto_shipment/mto_shipment_updater.go @@ -1092,13 +1092,15 @@ func reServiceCodesForShipment(shipment models.MTOShipment) []models.ReServiceCo } } case models.MTOShipmentTypeHHGIntoNTS: - // Need to create: Dom Linehaul, Fuel Surcharge, Dom Origin Price, Dom Destination Price, Dom NTS Packing - return []models.ReServiceCode{ - models.ReServiceCodeDLH, - models.ReServiceCodeFSC, - models.ReServiceCodeDOP, - models.ReServiceCodeDDP, - models.ReServiceCodeDNPK, + if shipment.MarketCode != models.MarketCodeInternational { + // Need to create: Dom Linehaul, Fuel Surcharge, Dom Origin Price, Dom Destination Price, Dom NTS Packing + return []models.ReServiceCode{ + models.ReServiceCodeDLH, + models.ReServiceCodeFSC, + models.ReServiceCodeDOP, + models.ReServiceCodeDDP, + models.ReServiceCodeDNPK, + } } case models.MTOShipmentTypeHHGOutOfNTSDom: // Need to create: Dom Linehaul, Fuel Surcharge, Dom Origin Price, Dom Destination Price, Dom Unpacking diff --git a/pkg/services/mto_shipment/mto_shipment_updater_test.go b/pkg/services/mto_shipment/mto_shipment_updater_test.go index 185319eb3d7..7b66c7417d3 100644 --- a/pkg/services/mto_shipment/mto_shipment_updater_test.go +++ b/pkg/services/mto_shipment/mto_shipment_updater_test.go @@ -3031,3 +3031,108 @@ func (suite *MTOShipmentServiceSuite) TestUpdateStatusServiceItems() { suite.Equal(models.ReServiceCodeDSH, serviceItems[0].ReService.Code) }) } + +func (suite *MTOShipmentServiceSuite) TestUpdateDomesticServiceItems() { + + expectedReServiceCodes := []models.ReServiceCode{ + models.ReServiceCodeDLH, + models.ReServiceCodeFSC, + models.ReServiceCodeDOP, + models.ReServiceCodeDDP, + models.ReServiceCodeDNPK, + } + + var pickupAddress models.Address + var storageFacility models.StorageFacility + var mto models.Move + + setupTestData := func() { + for i := range expectedReServiceCodes { + factory.FetchReServiceByCode(suite.DB(), expectedReServiceCodes[i]) + } + + pickupAddress = factory.BuildAddress(suite.DB(), []factory.Customization{ + { + Model: models.Address{ + StreetAddress1: "Test Street 1", + City: "Des moines", + State: "IA", + PostalCode: "50309", + IsOconus: models.BoolPointer(false), + }, + }, + }, nil) + + storageFacility = factory.BuildStorageFacility(suite.DB(), []factory.Customization{ + { + Model: models.Address{ + StreetAddress1: "Test Street Adress 2", + City: "Des moines", + State: "IA", + PostalCode: "50314", + IsOconus: models.BoolPointer(false), + }, + }, + }, nil) + + mto = factory.BuildMove(suite.DB(), []factory.Customization{ + { + Model: models.Move{ + Status: models.MoveStatusAPPROVED, + }, + }, + }, nil) + } + + builder := query.NewQueryBuilder() + moveRouter := moveservices.NewMoveRouter() + planner := &mocks.Planner{} + planner.On("ZipTransitDistance", + mock.AnythingOfType("*appcontext.appContext"), + mock.Anything, + mock.Anything, + ).Return(400, nil) + siCreator := mtoserviceitem.NewMTOServiceItemCreator(planner, builder, moveRouter, ghcrateengine.NewDomesticUnpackPricer(), ghcrateengine.NewDomesticPackPricer(), ghcrateengine.NewDomesticLinehaulPricer(), ghcrateengine.NewDomesticShorthaulPricer(), ghcrateengine.NewDomesticOriginPricer(), ghcrateengine.NewDomesticDestinationPricer(), ghcrateengine.NewFuelSurchargePricer()) + updater := NewMTOShipmentStatusUpdater(builder, siCreator, planner) + + suite.Run("Preapproved service items successfully added to domestic nts shipments", func() { + setupTestData() + + shipment := factory.BuildMTOShipment(suite.DB(), []factory.Customization{ + { + Model: mto, + LinkOnly: true, + }, + { + Model: pickupAddress, + Type: &factory.Addresses.PickupAddress, + LinkOnly: true, + }, + { + Model: storageFacility, + Type: &factory.StorageFacility, + LinkOnly: true, + }, + { + Model: models.MTOShipment{ + ShipmentType: models.MTOShipmentTypeHHGIntoNTS, + Status: models.MTOShipmentStatusSubmitted, + }, + }, + }, nil) + + appCtx := suite.AppContextForTest() + eTag := etag.GenerateEtag(shipment.UpdatedAt) + + updatedShipment, err := updater.UpdateMTOShipmentStatus(appCtx, shipment.ID, models.MTOShipmentStatusApproved, nil, nil, eTag) + suite.NoError(err) + + serviceItems := models.MTOServiceItems{} + err = appCtx.DB().EagerPreload("ReService").Where("mto_shipment_id = ?", updatedShipment.ID).All(&serviceItems) + suite.NoError(err) + + for i := 0; i < len(expectedReServiceCodes); i++ { + suite.Equal(expectedReServiceCodes[i], serviceItems[i].ReService.Code) + } + }) +} diff --git a/pkg/services/mto_shipment/shipment_approver.go b/pkg/services/mto_shipment/shipment_approver.go index d52d7388ec4..5e05cec2f2f 100644 --- a/pkg/services/mto_shipment/shipment_approver.go +++ b/pkg/services/mto_shipment/shipment_approver.go @@ -2,6 +2,7 @@ package mtoshipment import ( "math" + "slices" "github.com/gofrs/uuid" "github.com/pkg/errors" @@ -77,14 +78,18 @@ func (f *shipmentApprover) ApproveShipment(appCtx appcontext.AppContext, shipmen } } - // create international shipment service items - if shipment.ShipmentType == models.MTOShipmentTypeHHG && shipment.MarketCode == models.MarketCodeInternational { - err := models.CreateApprovedServiceItemsForShipment(appCtx.DB(), shipment) - if err != nil { - return shipment, err - } - } transactionError := appCtx.NewTransaction(func(txnAppCtx appcontext.AppContext) error { + + // If there are existing 're_service_items' for the international shipment then create 'mto_service_items' + // These are currently the shipment types we handle but add any additional international shipment types here + internationalShipmentTypes := []models.MTOShipmentType{models.MTOShipmentTypeHHG, models.MTOShipmentTypeHHGIntoNTS} + if slices.Contains(internationalShipmentTypes, shipment.ShipmentType) && shipment.MarketCode == models.MarketCodeInternational { + err := models.CreateApprovedServiceItemsForShipment(appCtx.DB(), shipment) + if err != nil { + return err + } + } + verrs, err := txnAppCtx.DB().ValidateAndSave(shipment) if verrs != nil && verrs.HasAny() { invalidInputError := apperror.NewInvalidInputError(shipment.ID, nil, verrs, "There was an issue with validating the updates") diff --git a/pkg/services/mto_shipment/shipment_approver_test.go b/pkg/services/mto_shipment/shipment_approver_test.go index 3c1d36a4795..7033031584f 100644 --- a/pkg/services/mto_shipment/shipment_approver_test.go +++ b/pkg/services/mto_shipment/shipment_approver_test.go @@ -190,7 +190,7 @@ func (suite *MTOShipmentServiceSuite) createApproveShipmentSubtestData() (subtes } func (suite *MTOShipmentServiceSuite) TestApproveShipment() { - suite.Run("If the international mtoShipment is approved successfully it should create pre approved mtoServiceItems", func() { + suite.Run("Given international mtoShipment is approved successfully pre-approved mtoServiceItems are created HHG", func() { internationalShipment := factory.BuildMTOShipment(suite.AppContextForTest().DB(), []factory.Customization{ { Model: models.Move{ @@ -209,7 +209,7 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { }, { Model: models.MTOShipment{ - MarketCode: "i", + MarketCode: models.MarketCodeInternational, Status: models.MTOShipmentStatusSubmitted, }, }, @@ -255,6 +255,84 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { } }) + suite.Run("Given international mtoShipment is approved successfully pre-approved mtoServiceItems are created NTS", func() { + storageFacility := factory.BuildStorageFacility(suite.DB(), []factory.Customization{ + { + Model: models.StorageFacility{ + FacilityName: *models.StringPointer("Test Storage Name"), + Email: models.StringPointer("old@email.com"), + LotNumber: models.StringPointer("Test lot number"), + Phone: models.StringPointer("555-555-5555"), + }, + }, + { + Model: models.Address{ + StreetAddress1: "JBER", + City: "Anchorage", + State: "AK", + PostalCode: "99507", + IsOconus: models.BoolPointer(true), + }, + }, + }, nil) + + internationalShipment := factory.BuildMTOShipment(suite.DB(), []factory.Customization{ + { + Model: models.Move{ + Status: models.MoveStatusAPPROVED, + }, + }, + { + Model: models.Address{ + StreetAddress1: "Tester Address", + City: "Des Moines", + State: "IA", + PostalCode: "50314", + IsOconus: models.BoolPointer(false), + }, + Type: &factory.Addresses.PickupAddress, + }, + { + Model: models.MTOShipment{ + MarketCode: models.MarketCodeInternational, + Status: models.MTOShipmentStatusSubmitted, + ShipmentType: models.MTOShipmentTypeHHGIntoNTS, + }, + }, + { + Model: storageFacility, + LinkOnly: true, + }, + }, nil) + internationalShipmentEtag := etag.GenerateEtag(internationalShipment.UpdatedAt) + + shipmentRouter := NewShipmentRouter() + var serviceItemCreator services.MTOServiceItemCreator + var planner route.Planner + var moveWeights services.MoveWeights + + // Approve international shipment + shipmentApprover := NewShipmentApprover(shipmentRouter, serviceItemCreator, planner, moveWeights) + _, err := shipmentApprover.ApproveShipment(suite.AppContextForTest(), internationalShipment.ID, internationalShipmentEtag) + suite.NoError(err) + + // Get created pre approved service items + var serviceItems []models.MTOServiceItem + err2 := suite.AppContextForTest().DB().EagerPreload("ReService").Where("mto_shipment_id = ?", internationalShipment.ID).Order("created_at asc").All(&serviceItems) + suite.NoError(err2) + + expectedReserviceCodes := []models.ReServiceCode{ + models.ReServiceCodeISLH, + models.ReServiceCodeINPK, + } + + suite.Equal(len(expectedReserviceCodes), len(serviceItems)) + for i := 0; i < len(serviceItems); i++ { + actualReServiceCode := serviceItems[i].ReService.Code + suite.True(slices.Contains(expectedReserviceCodes, actualReServiceCode)) + } + }) + suite.Run("If the mtoShipment is approved successfully it should create approved mtoServiceItems", func() { subtestData := suite.createApproveShipmentSubtestData() appCtx := subtestData.appCtx @@ -787,4 +865,25 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { suite.NotNil(shipment.MoveTaskOrder.ExcessWeightQualifiedAt) }) + + suite.Run("Given invalid shipment error returned", func() { + invalidShipment := factory.BuildMTOShipment(suite.AppContextForTest().DB(), []factory.Customization{ + { + Model: models.MTOShipment{ + ShipmentType: models.MTOShipmentTypePPM, + }, + }, + }, nil) + invalidShipmentEtag := etag.GenerateEtag(invalidShipment.UpdatedAt) + + shipmentRouter := NewShipmentRouter() + var serviceItemCreator services.MTOServiceItemCreator + var planner route.Planner + var moveWeights services.MoveWeights + + // Approve international shipment + shipmentApprover := NewShipmentApprover(shipmentRouter, serviceItemCreator, planner, moveWeights) + _, err := shipmentApprover.ApproveShipment(suite.AppContextForTest(), invalidShipment.ID, invalidShipmentEtag) + suite.Error(err) + }) } From 03eb1289f1473693074899640838d88c788317e2 Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Thu, 19 Dec 2024 14:17:53 +0000 Subject: [PATCH 11/29] adding comments for re_services --- ...620_add_international_nts_service_items.up.sql | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/migrations/app/schema/20241218204620_add_international_nts_service_items.up.sql b/migrations/app/schema/20241218204620_add_international_nts_service_items.up.sql index 2bb5207813f..207c5379080 100644 --- a/migrations/app/schema/20241218204620_add_international_nts_service_items.up.sql +++ b/migrations/app/schema/20241218204620_add_international_nts_service_items.up.sql @@ -4,18 +4,33 @@ INSERT INTO re_service_items (id, service_id, shipment_type, market_code, is_auto_approved, created_at, updated_at, sort) VALUES + --ISLH International Shipping & Linehaul ('2a560507-db09-4be1-b809-49c0f515b31b', '9f3d551a-0725-430e-897e-80ee9add3ae9' ,'HHG_INTO_NTS', 'i', true, now(), now(), 1), + --PODFSC International POD Fuel Surcharge ('e702818f-defd-452c-81a3-865b902e7dd0', '388115e8-abe9-441d-96cf-a39f24baa0a3' ,'HHG_INTO_NTS', 'i', true, now(), now(), 2), + --INPK International NTS packing ('366ee5a4-eb61-4ded-a68c-ddc29fe1a886', '874cb86a-bc39-4f57-a614-53ee3fcacf14' ,'HHG_INTO_NTS', 'i', true, now(), now(), 3), + --ICRT International crating ('aac4e95e-27ed-4f09-9b6b-384d8542f410', '86203d72-7f7c-49ff-82f0-5b95e4958f60' ,'HHG_INTO_NTS', 'i', false, now(), now(), NULL), + --IDASIT International destination add'l day SIT ('010f2f91-7381-4149-8d74-8eb5f593a864', '806c6d59-57ff-4a3f-9518-ebf29ba9cb10' ,'HHG_INTO_NTS', 'i', false, now(), now(), NULL), + --IDDSIT International destination SIT delivery ('a41966b7-b83a-4eaf-8e68-d5e884777102', '28389ee1-56cf-400c-aa52-1501ecdd7c69' ,'HHG_INTO_NTS', 'i', false, now(), now(), NULL), + --IDFSIT International destination 1st day SIT ('14c77957-3c76-465a-bb07-c98d36ef1e54', 'bd6064ca-e780-4ab4-a37b-0ae98eebb244' ,'HHG_INTO_NTS', 'i', false, now(), now(), NULL), + --IDSHUT International destination shuttle service ('d52d2d03-100a-4ed9-b2de-16eac63a375f', '22fc07ed-be15-4f50-b941-cbd38153b378' ,'HHG_INTO_NTS', 'i', false, now(), now(), NULL), + --IOASIT International origin add'l day SIT ('7fd91408-7d69-4375-b7e6-5b2ff714206b', 'bd424e45-397b-4766-9712-de4ae3a2da36' ,'HHG_INTO_NTS', 'i', false, now(), now(), NULL), + --IOFSIT International origin 1st day SIT ('b3dc509d-d652-4300-a702-a1ddce6255b6', 'b488bf85-ea5e-49c8-ba5c-e2fa278ac806' ,'HHG_INTO_NTS', 'i', false, now(), now(), NULL), + --IOPSIT International origin SIT pickup ('001eadb6-3526-45b9-96e0-0648bb481e86', '6f4f6e31-0675-4051-b659-89832259f390' ,'HHG_INTO_NTS', 'i', false, now(), now(), NULL), + --IOSHUT International origin shuttle service ('b991c5c9-af2c-4146-b999-1d0bdf91de3f', '624a97c5-dfbf-4da9-a6e9-526b4f95af8d' ,'HHG_INTO_NTS', 'i', false, now(), now(), NULL), + --IUCRT International uncrating ('5a89315a-257b-4ef0-92cb-4c06aa6f1332', '4132416b-b1aa-42e7-98f2-0ac0a03e8a31' ,'HHG_INTO_NTS', 'i', false, now(), now(), NULL), + --IOFSC International Origin SIT Fuel Surcharge ('d4a98dea-a5f7-4b92-b5de-e6350ab07824', '81e29d0c-02a6-4a7a-be02-554deb3ee49e' ,'HHG_INTO_NTS', 'i', false, now(), now(), NULL), + --IDSFSC International Destination SIT Fuel Surcharge ('eaea90c2-93d3-4db9-89cd-23ac57ec9ce1', '690a5fc1-0ea5-4554-8294-a367b5daefa9' ,'HHG_INTO_NTS', 'i', false, now(), now(), NULL); From bb1c9a93a4e6fdba093f0c31b2099bcebc3480de Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Fri, 20 Dec 2024 14:47:16 +0000 Subject: [PATCH 12/29] add oconus to conus test and hook change --- migrations/app/migrations_manifest.txt | 2 +- .../mto_shipment/shipment_approver_test.go | 81 ++++++++++++++++++- 2 files changed, 81 insertions(+), 2 deletions(-) diff --git a/migrations/app/migrations_manifest.txt b/migrations/app/migrations_manifest.txt index 6a8d1fe23b6..41e201aba97 100644 --- a/migrations/app/migrations_manifest.txt +++ b/migrations/app/migrations_manifest.txt @@ -1054,7 +1054,7 @@ 20241204155919_update_ordering_proc.up.sql 20241204210208_retroactive_update_of_ppm_max_and_estimated_incentives_prd.up.sql 20241210143143_redefine_mto_shipment_audit_table.up.sql -20241217163231_update_duty_locations_bad_zips.up.sql 20241216170325_update_nts_enum_name.up.sql +20241217163231_update_duty_locations_bad_zips.up.sql 20241217180136_add_AK_zips_to_zip3_distances.up.sql 20241218204620_add_international_nts_service_items.up.sql diff --git a/pkg/services/mto_shipment/shipment_approver_test.go b/pkg/services/mto_shipment/shipment_approver_test.go index 7033031584f..3e6d3d7cc0b 100644 --- a/pkg/services/mto_shipment/shipment_approver_test.go +++ b/pkg/services/mto_shipment/shipment_approver_test.go @@ -255,7 +255,7 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { } }) - suite.Run("Given international mtoShipment is approved successfully pre-approved mtoServiceItems are created NTS", func() { + suite.Run("Given international mtoShipment is approved successfully pre-approved mtoServiceItems are created NTS OCONUS to CONUS", func() { storageFacility := factory.BuildStorageFacility(suite.DB(), []factory.Customization{ { Model: models.StorageFacility{ @@ -333,6 +333,85 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { } }) + suite.Run("Given international mtoShipment is approved successfully pre-approved mtoServiceItems are created NTS CONUS to OCONUS", func() { + storageFacility := factory.BuildStorageFacility(suite.DB(), []factory.Customization{ + { + Model: models.StorageFacility{ + FacilityName: *models.StringPointer("Test Storage Name"), + Email: models.StringPointer("old@email.com"), + LotNumber: models.StringPointer("Test lot number"), + Phone: models.StringPointer("555-555-5555"), + }, + }, + { + Model: models.Address{ + StreetAddress1: "Tester Address", + City: "Des Moines", + State: "IA", + PostalCode: "50314", + IsOconus: models.BoolPointer(true), + }, + }, + }, nil) + + internationalShipment := factory.BuildMTOShipment(suite.DB(), []factory.Customization{ + { + Model: models.Move{ + Status: models.MoveStatusAPPROVED, + }, + }, + { + Model: models.Address{ + StreetAddress1: "JBER", + City: "Anchorage", + State: "AK", + PostalCode: "99507", + IsOconus: models.BoolPointer(false), + }, + Type: &factory.Addresses.PickupAddress, + }, + { + Model: models.MTOShipment{ + MarketCode: models.MarketCodeInternational, + Status: models.MTOShipmentStatusSubmitted, + ShipmentType: models.MTOShipmentTypeHHGIntoNTS, + }, + }, + { + Model: storageFacility, + LinkOnly: true, + }, + }, nil) + internationalShipmentEtag := etag.GenerateEtag(internationalShipment.UpdatedAt) + + shipmentRouter := NewShipmentRouter() + var serviceItemCreator services.MTOServiceItemCreator + var planner route.Planner + var moveWeights services.MoveWeights + + // Approve international shipment + shipmentApprover := NewShipmentApprover(shipmentRouter, serviceItemCreator, planner, moveWeights) + _, err := shipmentApprover.ApproveShipment(suite.AppContextForTest(), internationalShipment.ID, internationalShipmentEtag) + suite.NoError(err) + + // Get created pre approved service items + var serviceItems []models.MTOServiceItem + err2 := suite.AppContextForTest().DB().EagerPreload("ReService").Where("mto_shipment_id = ?", internationalShipment.ID).Order("created_at asc").All(&serviceItems) + suite.NoError(err2) + + expectedReserviceCodes := []models.ReServiceCode{ + models.ReServiceCodeISLH, + models.ReServiceCodePODFSC, + models.ReServiceCodeINPK, + } + + suite.Equal(len(expectedReserviceCodes), len(serviceItems)) + for i := 0; i < len(serviceItems); i++ { + actualReServiceCode := serviceItems[i].ReService.Code + suite.True(slices.Contains(expectedReserviceCodes, actualReServiceCode)) + } + }) + suite.Run("If the mtoShipment is approved successfully it should create approved mtoServiceItems", func() { subtestData := suite.createApproveShipmentSubtestData() appCtx := subtestData.appCtx From d7445b5eb2f17c660595d5840a3e752b2a823837 Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Fri, 20 Dec 2024 14:53:06 +0000 Subject: [PATCH 13/29] wrong test --- pkg/services/mto_shipment/shipment_approver_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/services/mto_shipment/shipment_approver_test.go b/pkg/services/mto_shipment/shipment_approver_test.go index 3e6d3d7cc0b..b07513661fc 100644 --- a/pkg/services/mto_shipment/shipment_approver_test.go +++ b/pkg/services/mto_shipment/shipment_approver_test.go @@ -323,6 +323,7 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { expectedReserviceCodes := []models.ReServiceCode{ models.ReServiceCodeISLH, + models.ReServiceCodePODFSC, models.ReServiceCodeINPK, } @@ -401,7 +402,6 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { expectedReserviceCodes := []models.ReServiceCode{ models.ReServiceCodeISLH, - models.ReServiceCodePODFSC, models.ReServiceCodeINPK, } From 1aef07241ddf364415ba80fe1416f986122a2ee1 Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Fri, 20 Dec 2024 15:20:11 +0000 Subject: [PATCH 14/29] flipped tests lol --- pkg/services/mto_shipment/shipment_approver_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/services/mto_shipment/shipment_approver_test.go b/pkg/services/mto_shipment/shipment_approver_test.go index b07513661fc..3a0b923c30c 100644 --- a/pkg/services/mto_shipment/shipment_approver_test.go +++ b/pkg/services/mto_shipment/shipment_approver_test.go @@ -255,7 +255,7 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { } }) - suite.Run("Given international mtoShipment is approved successfully pre-approved mtoServiceItems are created NTS OCONUS to CONUS", func() { + suite.Run("Given international mtoShipment is approved successfully pre-approved mtoServiceItems are created NTS CONUS to OCONUS", func() { storageFacility := factory.BuildStorageFacility(suite.DB(), []factory.Customization{ { Model: models.StorageFacility{ @@ -323,7 +323,6 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { expectedReserviceCodes := []models.ReServiceCode{ models.ReServiceCodeISLH, - models.ReServiceCodePODFSC, models.ReServiceCodeINPK, } @@ -334,7 +333,7 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { } }) - suite.Run("Given international mtoShipment is approved successfully pre-approved mtoServiceItems are created NTS CONUS to OCONUS", func() { + suite.Run("Given international mtoShipment is approved successfully pre-approved mtoServiceItems are created NTS OCONUS to CONUS", func() { storageFacility := factory.BuildStorageFacility(suite.DB(), []factory.Customization{ { Model: models.StorageFacility{ @@ -350,7 +349,7 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { City: "Des Moines", State: "IA", PostalCode: "50314", - IsOconus: models.BoolPointer(true), + IsOconus: models.BoolPointer(false), }, }, }, nil) @@ -367,7 +366,7 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { City: "Anchorage", State: "AK", PostalCode: "99507", - IsOconus: models.BoolPointer(false), + IsOconus: models.BoolPointer(true), }, Type: &factory.Addresses.PickupAddress, }, @@ -402,6 +401,7 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { expectedReserviceCodes := []models.ReServiceCode{ models.ReServiceCodeISLH, + models.ReServiceCodePODFSC, models.ReServiceCodeINPK, } From 2dd1c152386bbc5aed3562016a4d186e57c3cbc4 Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Fri, 20 Dec 2024 15:36:59 +0000 Subject: [PATCH 15/29] added test --- .../mto_shipment/shipment_approver_test.go | 81 ++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/pkg/services/mto_shipment/shipment_approver_test.go b/pkg/services/mto_shipment/shipment_approver_test.go index 7033031584f..3a0b923c30c 100644 --- a/pkg/services/mto_shipment/shipment_approver_test.go +++ b/pkg/services/mto_shipment/shipment_approver_test.go @@ -255,7 +255,7 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { } }) - suite.Run("Given international mtoShipment is approved successfully pre-approved mtoServiceItems are created NTS", func() { + suite.Run("Given international mtoShipment is approved successfully pre-approved mtoServiceItems are created NTS CONUS to OCONUS", func() { storageFacility := factory.BuildStorageFacility(suite.DB(), []factory.Customization{ { Model: models.StorageFacility{ @@ -333,6 +333,85 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { } }) + suite.Run("Given international mtoShipment is approved successfully pre-approved mtoServiceItems are created NTS OCONUS to CONUS", func() { + storageFacility := factory.BuildStorageFacility(suite.DB(), []factory.Customization{ + { + Model: models.StorageFacility{ + FacilityName: *models.StringPointer("Test Storage Name"), + Email: models.StringPointer("old@email.com"), + LotNumber: models.StringPointer("Test lot number"), + Phone: models.StringPointer("555-555-5555"), + }, + }, + { + Model: models.Address{ + StreetAddress1: "Tester Address", + City: "Des Moines", + State: "IA", + PostalCode: "50314", + IsOconus: models.BoolPointer(false), + }, + }, + }, nil) + + internationalShipment := factory.BuildMTOShipment(suite.DB(), []factory.Customization{ + { + Model: models.Move{ + Status: models.MoveStatusAPPROVED, + }, + }, + { + Model: models.Address{ + StreetAddress1: "JBER", + City: "Anchorage", + State: "AK", + PostalCode: "99507", + IsOconus: models.BoolPointer(true), + }, + Type: &factory.Addresses.PickupAddress, + }, + { + Model: models.MTOShipment{ + MarketCode: models.MarketCodeInternational, + Status: models.MTOShipmentStatusSubmitted, + ShipmentType: models.MTOShipmentTypeHHGIntoNTS, + }, + }, + { + Model: storageFacility, + LinkOnly: true, + }, + }, nil) + internationalShipmentEtag := etag.GenerateEtag(internationalShipment.UpdatedAt) + + shipmentRouter := NewShipmentRouter() + var serviceItemCreator services.MTOServiceItemCreator + var planner route.Planner + var moveWeights services.MoveWeights + + // Approve international shipment + shipmentApprover := NewShipmentApprover(shipmentRouter, serviceItemCreator, planner, moveWeights) + _, err := shipmentApprover.ApproveShipment(suite.AppContextForTest(), internationalShipment.ID, internationalShipmentEtag) + suite.NoError(err) + + // Get created pre approved service items + var serviceItems []models.MTOServiceItem + err2 := suite.AppContextForTest().DB().EagerPreload("ReService").Where("mto_shipment_id = ?", internationalShipment.ID).Order("created_at asc").All(&serviceItems) + suite.NoError(err2) + + expectedReserviceCodes := []models.ReServiceCode{ + models.ReServiceCodeISLH, + models.ReServiceCodePODFSC, + models.ReServiceCodeINPK, + } + + suite.Equal(len(expectedReserviceCodes), len(serviceItems)) + for i := 0; i < len(serviceItems); i++ { + actualReServiceCode := serviceItems[i].ReService.Code + suite.True(slices.Contains(expectedReserviceCodes, actualReServiceCode)) + } + }) + suite.Run("If the mtoShipment is approved successfully it should create approved mtoServiceItems", func() { subtestData := suite.createApproveShipmentSubtestData() appCtx := subtestData.appCtx From 08332c37dd86545576eefa45e2631af81de03558 Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Fri, 20 Dec 2024 15:43:10 +0000 Subject: [PATCH 16/29] fixed asserts --- pkg/services/mto_shipment/shipment_approver_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/services/mto_shipment/shipment_approver_test.go b/pkg/services/mto_shipment/shipment_approver_test.go index 3a0b923c30c..f79f81677a3 100644 --- a/pkg/services/mto_shipment/shipment_approver_test.go +++ b/pkg/services/mto_shipment/shipment_approver_test.go @@ -323,6 +323,7 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { expectedReserviceCodes := []models.ReServiceCode{ models.ReServiceCodeISLH, + models.ReServiceCodePODFSC, models.ReServiceCodeINPK, } @@ -401,7 +402,6 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { expectedReserviceCodes := []models.ReServiceCode{ models.ReServiceCodeISLH, - models.ReServiceCodePODFSC, models.ReServiceCodeINPK, } From 0efdd5421799b474c42501bc9277b07f3a138c1e Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Fri, 20 Dec 2024 16:08:35 +0000 Subject: [PATCH 17/29] should be it --- pkg/services/mto_shipment/shipment_approver_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/services/mto_shipment/shipment_approver_test.go b/pkg/services/mto_shipment/shipment_approver_test.go index f79f81677a3..3a0b923c30c 100644 --- a/pkg/services/mto_shipment/shipment_approver_test.go +++ b/pkg/services/mto_shipment/shipment_approver_test.go @@ -323,7 +323,6 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { expectedReserviceCodes := []models.ReServiceCode{ models.ReServiceCodeISLH, - models.ReServiceCodePODFSC, models.ReServiceCodeINPK, } @@ -402,6 +401,7 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { expectedReserviceCodes := []models.ReServiceCode{ models.ReServiceCodeISLH, + models.ReServiceCodePODFSC, models.ReServiceCodeINPK, } From 6449f4d8fa01c7d5b850b53a347b736b597901a8 Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Tue, 7 Jan 2025 16:22:00 +0000 Subject: [PATCH 18/29] maybe fix factory for oconus to conus --- pkg/factory/mto_shipment_factory.go | 6 +++++- pkg/services/mto_shipment/shipment_approver_test.go | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/factory/mto_shipment_factory.go b/pkg/factory/mto_shipment_factory.go index 1c7858d572f..025a94fc09c 100644 --- a/pkg/factory/mto_shipment_factory.go +++ b/pkg/factory/mto_shipment_factory.go @@ -57,7 +57,7 @@ func buildMTOShipmentWithBuildType(db *pop.Connection, customs []Customization, defaultStatus = models.MTOShipmentStatusDraft buildStorageFacility = hasStorageFacilityCustom shipmentHasPickupDetails = true - shipmentHasDeliveryDetails = false + shipmentHasDeliveryDetails = true case mtoShipmentNTSR: defaultShipmentType = models.MTOShipmentTypeHHGOutOfNTSDom defaultStatus = models.MTOShipmentStatusDraft @@ -83,6 +83,10 @@ func buildMTOShipmentWithBuildType(db *pop.Connection, customs []Customization, MarketCode: defaultMarketCode, } + if newMTOShipment.ShipmentType == models.MTOShipmentTypeHHGIntoNTS && newMTOShipment.StorageFacility != nil { + newMTOShipment.DestinationAddress = &newMTOShipment.StorageFacility.Address + } + if cMtoShipment.Status == models.MTOShipmentStatusApproved { approvedDate := time.Date(GHCTestYear, time.March, 20, 0, 0, 0, 0, time.UTC) newMTOShipment.ApprovedDate = &approvedDate diff --git a/pkg/services/mto_shipment/shipment_approver_test.go b/pkg/services/mto_shipment/shipment_approver_test.go index 3a0b923c30c..3ecbc0a203f 100644 --- a/pkg/services/mto_shipment/shipment_approver_test.go +++ b/pkg/services/mto_shipment/shipment_approver_test.go @@ -354,7 +354,7 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { }, }, nil) - internationalShipment := factory.BuildMTOShipment(suite.DB(), []factory.Customization{ + internationalShipment := factory.BuildNTSShipment(suite.DB(), []factory.Customization{ { Model: models.Move{ Status: models.MoveStatusAPPROVED, From b5e5c229128fb3a7d3ba3b4f929febfc1b08f266 Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Tue, 7 Jan 2025 16:56:58 +0000 Subject: [PATCH 19/29] update factory test --- pkg/factory/mto_shipment_factory_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/factory/mto_shipment_factory_test.go b/pkg/factory/mto_shipment_factory_test.go index ea43a0a0373..60403a50f0d 100644 --- a/pkg/factory/mto_shipment_factory_test.go +++ b/pkg/factory/mto_shipment_factory_test.go @@ -450,9 +450,9 @@ func (suite *FactorySuite) TestBuildMTOShipment() { suite.NotNil(ntsShipment.PrimeActualWeight) suite.Nil(ntsShipment.StorageFacility) suite.NotNil(ntsShipment.ScheduledPickupDate) - suite.Nil(ntsShipment.RequestedDeliveryDate) + suite.NotNil(ntsShipment.RequestedDeliveryDate) suite.Nil(ntsShipment.ActualDeliveryDate) - suite.Nil(ntsShipment.ScheduledDeliveryDate) + suite.NotNil(ntsShipment.ScheduledDeliveryDate) }) suite.Run("Successful creation of NTSShipment with storage facility", func() { From aeed16556a5bd98a2effd943fe1029d5a288c617 Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Tue, 7 Jan 2025 18:56:56 +0000 Subject: [PATCH 20/29] adding back function logic from int overwrite --- pkg/services/mto_shipment/shipment_approver.go | 4 +++- pkg/services/mto_shipment/shipment_approver_test.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/services/mto_shipment/shipment_approver.go b/pkg/services/mto_shipment/shipment_approver.go index de81ce0440e..17c5e5ffdc0 100644 --- a/pkg/services/mto_shipment/shipment_approver.go +++ b/pkg/services/mto_shipment/shipment_approver.go @@ -2,6 +2,7 @@ package mtoshipment import ( "math" + "slices" "github.com/gofrs/uuid" "github.com/pkg/errors" @@ -80,7 +81,8 @@ func (f *shipmentApprover) ApproveShipment(appCtx appcontext.AppContext, shipmen transactionError := appCtx.NewTransaction(func(txnAppCtx appcontext.AppContext) error { // create international shipment service items before approving // we use a database proc to create the basic auto-approved service items - if shipment.ShipmentType == models.MTOShipmentTypeHHG && shipment.MarketCode == models.MarketCodeInternational { + internationalShipmentTypes := []models.MTOShipmentType{models.MTOShipmentTypeHHG, models.MTOShipmentTypeHHGIntoNTS} + if slices.Contains(internationalShipmentTypes, shipment.ShipmentType) && shipment.MarketCode == models.MarketCodeInternational { err := models.CreateApprovedServiceItemsForShipment(appCtx.DB(), shipment) if err != nil { return err diff --git a/pkg/services/mto_shipment/shipment_approver_test.go b/pkg/services/mto_shipment/shipment_approver_test.go index d0f64222f1e..3490e5e976f 100644 --- a/pkg/services/mto_shipment/shipment_approver_test.go +++ b/pkg/services/mto_shipment/shipment_approver_test.go @@ -300,7 +300,7 @@ func (suite *MTOShipmentServiceSuite) TestApproveShipment() { models.ReServiceCodeIHUPK, } - suite.Equal(4, len(serviceItems)) + suite.Equal(len(expectedReserviceCodes), len(serviceItems)) for i := 0; i < len(serviceItems); i++ { actualReServiceCode := serviceItems[i].ReService.Code suite.True(slices.Contains(expectedReserviceCodes, actualReServiceCode)) From d5632dfec4c333d8a135fb56ef6c5ee93324bed1 Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Wed, 8 Jan 2025 15:49:23 +0000 Subject: [PATCH 21/29] removed extra loop and put check at top of func --- .../mto_shipment/mto_shipment_updater.go | 82 +++++++++---------- .../mto_shipment/mto_shipment_updater_test.go | 4 - 2 files changed, 40 insertions(+), 46 deletions(-) diff --git a/pkg/services/mto_shipment/mto_shipment_updater.go b/pkg/services/mto_shipment/mto_shipment_updater.go index d1367ebef05..2ff73a2a431 100644 --- a/pkg/services/mto_shipment/mto_shipment_updater.go +++ b/pkg/services/mto_shipment/mto_shipment_updater.go @@ -1110,9 +1110,9 @@ func reServiceCodesForShipment(shipment models.MTOShipment) []models.ReServiceCo // More info in MB-1140: https://dp3.atlassian.net/browse/MB-1140 // international shipment service items are created in the shipment_approver - switch shipment.ShipmentType { - case models.MTOShipmentTypeHHG: - if shipment.MarketCode != models.MarketCodeInternational { + if shipment.MarketCode != models.MarketCodeInternational { + switch shipment.ShipmentType { + case models.MTOShipmentTypeHHG: originZIP3 := shipment.PickupAddress.PostalCode[0:3] destinationZIP3 := shipment.DestinationAddress.PostalCode[0:3] @@ -1136,9 +1136,7 @@ func reServiceCodesForShipment(shipment models.MTOShipment) []models.ReServiceCo models.ReServiceCodeDPK, models.ReServiceCodeDUPK, } - } - case models.MTOShipmentTypeHHGIntoNTS: - if shipment.MarketCode != models.MarketCodeInternational { + case models.MTOShipmentTypeHHGIntoNTS: // Need to create: Dom Linehaul, Fuel Surcharge, Dom Origin Price, Dom Destination Price, Dom NTS Packing return []models.ReServiceCode{ models.ReServiceCodeDLH, @@ -1147,42 +1145,42 @@ func reServiceCodesForShipment(shipment models.MTOShipment) []models.ReServiceCo models.ReServiceCodeDDP, models.ReServiceCodeDNPK, } - } - case models.MTOShipmentTypeHHGOutOfNTSDom: - // Need to create: Dom Linehaul, Fuel Surcharge, Dom Origin Price, Dom Destination Price, Dom Unpacking - return []models.ReServiceCode{ - models.ReServiceCodeDLH, - models.ReServiceCodeFSC, - models.ReServiceCodeDOP, - models.ReServiceCodeDDP, - models.ReServiceCodeDUPK, - } - case models.MTOShipmentTypeMobileHome: - // Need to create: Dom Linehaul, Fuel Surcharge, Dom Origin Price, Dom Destination Price, Dom Mobile Home Factor - return []models.ReServiceCode{ - models.ReServiceCodeDLH, - models.ReServiceCodeFSC, - models.ReServiceCodeDOP, - models.ReServiceCodeDDP, - models.ReServiceCodeDMHF, - } - case models.MTOShipmentTypeBoatHaulAway: - // Need to create: Dom Linehaul, Fuel Surcharge, Dom Origin Price, Dom Destination Price, Dom Haul Away Boat Factor - return []models.ReServiceCode{ - models.ReServiceCodeDLH, - models.ReServiceCodeFSC, - models.ReServiceCodeDOP, - models.ReServiceCodeDDP, - models.ReServiceCodeDBHF, - } - case models.MTOShipmentTypeBoatTowAway: - // Need to create: Dom Linehaul, Fuel Surcharge, Dom Origin Price, Dom Destination Price, Dom Tow Away Boat Factor - return []models.ReServiceCode{ - models.ReServiceCodeDLH, - models.ReServiceCodeFSC, - models.ReServiceCodeDOP, - models.ReServiceCodeDDP, - models.ReServiceCodeDBTF, + case models.MTOShipmentTypeHHGOutOfNTSDom: + // Need to create: Dom Linehaul, Fuel Surcharge, Dom Origin Price, Dom Destination Price, Dom Unpacking + return []models.ReServiceCode{ + models.ReServiceCodeDLH, + models.ReServiceCodeFSC, + models.ReServiceCodeDOP, + models.ReServiceCodeDDP, + models.ReServiceCodeDUPK, + } + case models.MTOShipmentTypeMobileHome: + // Need to create: Dom Linehaul, Fuel Surcharge, Dom Origin Price, Dom Destination Price, Dom Mobile Home Factor + return []models.ReServiceCode{ + models.ReServiceCodeDLH, + models.ReServiceCodeFSC, + models.ReServiceCodeDOP, + models.ReServiceCodeDDP, + models.ReServiceCodeDMHF, + } + case models.MTOShipmentTypeBoatHaulAway: + // Need to create: Dom Linehaul, Fuel Surcharge, Dom Origin Price, Dom Destination Price, Dom Haul Away Boat Factor + return []models.ReServiceCode{ + models.ReServiceCodeDLH, + models.ReServiceCodeFSC, + models.ReServiceCodeDOP, + models.ReServiceCodeDDP, + models.ReServiceCodeDBHF, + } + case models.MTOShipmentTypeBoatTowAway: + // Need to create: Dom Linehaul, Fuel Surcharge, Dom Origin Price, Dom Destination Price, Dom Tow Away Boat Factor + return []models.ReServiceCode{ + models.ReServiceCodeDLH, + models.ReServiceCodeFSC, + models.ReServiceCodeDOP, + models.ReServiceCodeDDP, + models.ReServiceCodeDBTF, + } } } diff --git a/pkg/services/mto_shipment/mto_shipment_updater_test.go b/pkg/services/mto_shipment/mto_shipment_updater_test.go index f4c0eab5245..bfced125206 100644 --- a/pkg/services/mto_shipment/mto_shipment_updater_test.go +++ b/pkg/services/mto_shipment/mto_shipment_updater_test.go @@ -3461,10 +3461,6 @@ func (suite *MTOShipmentServiceSuite) TestUpdateDomesticServiceItems() { var mto models.Move setupTestData := func() { - for i := range expectedReServiceCodes { - factory.FetchReServiceByCode(suite.DB(), expectedReServiceCodes[i]) - } - pickupAddress = factory.BuildAddress(suite.DB(), []factory.Customization{ { Model: models.Address{ From d098c803b0a3d4ba3857da3b36797129923770b0 Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Wed, 8 Jan 2025 16:20:53 +0000 Subject: [PATCH 22/29] ub got removed from the list? --- pkg/services/mto_shipment/shipment_approver.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/services/mto_shipment/shipment_approver.go b/pkg/services/mto_shipment/shipment_approver.go index 1e000faeccf..93aed2d6540 100644 --- a/pkg/services/mto_shipment/shipment_approver.go +++ b/pkg/services/mto_shipment/shipment_approver.go @@ -81,7 +81,7 @@ func (f *shipmentApprover) ApproveShipment(appCtx appcontext.AppContext, shipmen transactionError := appCtx.NewTransaction(func(txnAppCtx appcontext.AppContext) error { // create international shipment service items before approving // we use a database proc to create the basic auto-approved service items - internationalShipmentTypes := []models.MTOShipmentType{models.MTOShipmentTypeHHG, models.MTOShipmentTypeHHGIntoNTS} + internationalShipmentTypes := []models.MTOShipmentType{models.MTOShipmentTypeHHG, models.MTOShipmentTypeHHGIntoNTS, models.MTOShipmentTypeUnaccompaniedBaggage} if slices.Contains(internationalShipmentTypes, shipment.ShipmentType) && shipment.MarketCode == models.MarketCodeInternational { err := models.CreateApprovedServiceItemsForShipment(appCtx.DB(), shipment) if err != nil { From a1c8dada378e7a23693d11233803b1bcd8ceddac Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Wed, 8 Jan 2025 21:02:12 +0000 Subject: [PATCH 23/29] add in nil/type check --- .../mto_shipment/mto_shipment_updater.go | 67 ++++++++++--------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/pkg/services/mto_shipment/mto_shipment_updater.go b/pkg/services/mto_shipment/mto_shipment_updater.go index 2ff73a2a431..0b42d65ca46 100644 --- a/pkg/services/mto_shipment/mto_shipment_updater.go +++ b/pkg/services/mto_shipment/mto_shipment_updater.go @@ -853,45 +853,48 @@ func (f *mtoShipmentUpdater) updateShipmentRecord(appCtx appcontext.AppContext, // if the shipment has an estimated weight, we need to update the service item pricing // we only need to do this if the estimated weight, primary addresses, and pickup date are being updated since those all impact pricing // we will compare data here to see if we even need to update the pricing - if newShipment.MarketCode == models.MarketCodeInternational && - (newShipment.PrimeEstimatedWeight != nil || + if dbShipment.PickupAddress != nil && dbShipment.DestinationAddress != nil && + newShipment.ShipmentType == models.MTOShipmentTypeHHGIntoNTS || newShipment.ShipmentType == models.MTOShipmentTypeHHGOutOfNTSDom { + if newShipment.MarketCode == models.MarketCodeInternational && + newShipment.PrimeEstimatedWeight != nil || newShipment.PickupAddress != nil && newShipment.PickupAddress.PostalCode != dbShipment.PickupAddress.PostalCode || newShipment.DestinationAddress != nil && newShipment.DestinationAddress.PostalCode != dbShipment.DestinationAddress.PostalCode || - newShipment.RequestedPickupDate != nil && newShipment.RequestedPickupDate.Format("2006-01-02") != dbShipment.RequestedPickupDate.Format("2006-01-02")) { + newShipment.RequestedPickupDate != nil && newShipment.RequestedPickupDate.Format("2006-01-02") != dbShipment.RequestedPickupDate.Format("2006-01-02") { - portZip, portType, err := models.GetPortLocationInfoForShipment(appCtx.DB(), newShipment.ID) - if err != nil { - return err - } - // if we don't have the port data, then we won't worry about pricing POEFSC/PODFSC because we need the distance from/to the ports - if portZip != nil && portType != nil { - var pickupZip string - var destZip string - // if the port type is POEFSC this means the shipment is CONUS -> OCONUS (pickup -> port) - // if the port type is PODFSC this means the shipment is OCONUS -> CONUS (port -> destination) - if *portType == models.ReServiceCodePOEFSC.String() { - pickupZip = newShipment.PickupAddress.PostalCode - destZip = *portZip - } else if *portType == models.ReServiceCodePODFSC.String() { - pickupZip = *portZip - destZip = newShipment.DestinationAddress.PostalCode - } - // we need to get the mileage from DTOD first, the db proc will consume that - mileage, err := f.planner.ZipTransitDistance(appCtx, pickupZip, destZip, true, true) + portZip, portType, err := models.GetPortLocationInfoForShipment(appCtx.DB(), newShipment.ID) if err != nil { return err } + // if we don't have the port data, then we won't worry about pricing POEFSC/PODFSC because we need the distance from/to the ports + if portZip != nil && portType != nil { + var pickupZip string + var destZip string + // if the port type is POEFSC this means the shipment is CONUS -> OCONUS (pickup -> port) + // if the port type is PODFSC this means the shipment is OCONUS -> CONUS (port -> destination) + if *portType == models.ReServiceCodePOEFSC.String() { + pickupZip = newShipment.PickupAddress.PostalCode + destZip = *portZip + } else if *portType == models.ReServiceCodePODFSC.String() { + pickupZip = *portZip + destZip = newShipment.DestinationAddress.PostalCode + } + // we need to get the mileage from DTOD first, the db proc will consume that + mileage, err := f.planner.ZipTransitDistance(appCtx, pickupZip, destZip, true, true) + if err != nil { + return err + } - // update the service item pricing if relevant fields have changed - err = models.UpdateEstimatedPricingForShipmentBasicServiceItems(appCtx.DB(), newShipment, &mileage) - if err != nil { - return err - } - } else { - // if we don't have the port data, that's okay - we can update the other service items except for PODFSC/POEFSC - err = models.UpdateEstimatedPricingForShipmentBasicServiceItems(appCtx.DB(), newShipment, nil) - if err != nil { - return err + // update the service item pricing if relevant fields have changed + err = models.UpdateEstimatedPricingForShipmentBasicServiceItems(appCtx.DB(), newShipment, &mileage) + if err != nil { + return err + } + } else { + // if we don't have the port data, that's okay - we can update the other service items except for PODFSC/POEFSC + err = models.UpdateEstimatedPricingForShipmentBasicServiceItems(appCtx.DB(), newShipment, nil) + if err != nil { + return err + } } } } From 27d0535a81c0805df3778e6227e150171e496086 Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Wed, 8 Jan 2025 21:09:30 +0000 Subject: [PATCH 24/29] generate swagger --- swagger/prime_v3.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/swagger/prime_v3.yaml b/swagger/prime_v3.yaml index d5abe7d4ade..10692aa49f7 100644 --- a/swagger/prime_v3.yaml +++ b/swagger/prime_v3.yaml @@ -3544,14 +3544,14 @@ definitions: description: >- Single-letter designator for domestic (d) or international (i) shipments - portOfDebarkation: - $ref: '#/definitions/Port' - portOfEmbarkation: - $ref: '#/definitions/Port' originRateArea: $ref: '#/definitions/RateArea' destinationRateArea: $ref: '#/definitions/RateArea' + portOfDebarkation: + $ref: '#/definitions/Port' + portOfEmbarkation: + $ref: '#/definitions/Port' MTOShipmentsWithoutServiceObjects: description: A list of shipments without their associated service items. items: From 212af35936744eb3efbe0064e2379b9180ae6e52 Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Wed, 8 Jan 2025 22:05:28 +0000 Subject: [PATCH 25/29] added nts/nil checks --- .../mto_shipment/mto_shipment_updater.go | 75 +++++++++---------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/pkg/services/mto_shipment/mto_shipment_updater.go b/pkg/services/mto_shipment/mto_shipment_updater.go index 0b42d65ca46..b70a83b43b9 100644 --- a/pkg/services/mto_shipment/mto_shipment_updater.go +++ b/pkg/services/mto_shipment/mto_shipment_updater.go @@ -853,48 +853,47 @@ func (f *mtoShipmentUpdater) updateShipmentRecord(appCtx appcontext.AppContext, // if the shipment has an estimated weight, we need to update the service item pricing // we only need to do this if the estimated weight, primary addresses, and pickup date are being updated since those all impact pricing // we will compare data here to see if we even need to update the pricing - if dbShipment.PickupAddress != nil && dbShipment.DestinationAddress != nil && - newShipment.ShipmentType == models.MTOShipmentTypeHHGIntoNTS || newShipment.ShipmentType == models.MTOShipmentTypeHHGOutOfNTSDom { - if newShipment.MarketCode == models.MarketCodeInternational && - newShipment.PrimeEstimatedWeight != nil || - newShipment.PickupAddress != nil && newShipment.PickupAddress.PostalCode != dbShipment.PickupAddress.PostalCode || - newShipment.DestinationAddress != nil && newShipment.DestinationAddress.PostalCode != dbShipment.DestinationAddress.PostalCode || - newShipment.RequestedPickupDate != nil && newShipment.RequestedPickupDate.Format("2006-01-02") != dbShipment.RequestedPickupDate.Format("2006-01-02") { - - portZip, portType, err := models.GetPortLocationInfoForShipment(appCtx.DB(), newShipment.ID) + if newShipment.MarketCode == models.MarketCodeInternational && + newShipment.ShipmentType != models.MTOShipmentTypeHHGIntoNTS || + newShipment.ShipmentType != models.MTOShipmentTypeHHGOutOfNTSDom || + newShipment.PrimeEstimatedWeight != nil || + newShipment.PickupAddress != nil && dbShipment.PickupAddress != nil && newShipment.PickupAddress.PostalCode != dbShipment.PickupAddress.PostalCode || + newShipment.DestinationAddress != nil && dbShipment.DestinationAddress != nil && newShipment.DestinationAddress.PostalCode != dbShipment.DestinationAddress.PostalCode || + newShipment.RequestedPickupDate != nil && newShipment.RequestedPickupDate.Format("2006-01-02") != dbShipment.RequestedPickupDate.Format("2006-01-02") { + + portZip, portType, err := models.GetPortLocationInfoForShipment(appCtx.DB(), newShipment.ID) + if err != nil { + return err + } + // if we don't have the port data, then we won't worry about pricing POEFSC/PODFSC because we need the distance from/to the ports + if portZip != nil && portType != nil { + var pickupZip string + var destZip string + // if the port type is POEFSC this means the shipment is CONUS -> OCONUS (pickup -> port) + // if the port type is PODFSC this means the shipment is OCONUS -> CONUS (port -> destination) + if *portType == models.ReServiceCodePOEFSC.String() { + pickupZip = newShipment.PickupAddress.PostalCode + destZip = *portZip + } else if *portType == models.ReServiceCodePODFSC.String() { + pickupZip = *portZip + destZip = newShipment.DestinationAddress.PostalCode + } + // we need to get the mileage from DTOD first, the db proc will consume that + mileage, err := f.planner.ZipTransitDistance(appCtx, pickupZip, destZip, true, true) if err != nil { return err } - // if we don't have the port data, then we won't worry about pricing POEFSC/PODFSC because we need the distance from/to the ports - if portZip != nil && portType != nil { - var pickupZip string - var destZip string - // if the port type is POEFSC this means the shipment is CONUS -> OCONUS (pickup -> port) - // if the port type is PODFSC this means the shipment is OCONUS -> CONUS (port -> destination) - if *portType == models.ReServiceCodePOEFSC.String() { - pickupZip = newShipment.PickupAddress.PostalCode - destZip = *portZip - } else if *portType == models.ReServiceCodePODFSC.String() { - pickupZip = *portZip - destZip = newShipment.DestinationAddress.PostalCode - } - // we need to get the mileage from DTOD first, the db proc will consume that - mileage, err := f.planner.ZipTransitDistance(appCtx, pickupZip, destZip, true, true) - if err != nil { - return err - } - // update the service item pricing if relevant fields have changed - err = models.UpdateEstimatedPricingForShipmentBasicServiceItems(appCtx.DB(), newShipment, &mileage) - if err != nil { - return err - } - } else { - // if we don't have the port data, that's okay - we can update the other service items except for PODFSC/POEFSC - err = models.UpdateEstimatedPricingForShipmentBasicServiceItems(appCtx.DB(), newShipment, nil) - if err != nil { - return err - } + // update the service item pricing if relevant fields have changed + err = models.UpdateEstimatedPricingForShipmentBasicServiceItems(appCtx.DB(), newShipment, &mileage) + if err != nil { + return err + } + } else { + // if we don't have the port data, that's okay - we can update the other service items except for PODFSC/POEFSC + err = models.UpdateEstimatedPricingForShipmentBasicServiceItems(appCtx.DB(), newShipment, nil) + if err != nil { + return err } } } From 4ee0dbe4476dfad907d86104c317d241c0b7c04b Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Thu, 9 Jan 2025 22:33:56 +0000 Subject: [PATCH 26/29] remove breaking type change --- pkg/services/mto_shipment/mto_shipment_updater.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkg/services/mto_shipment/mto_shipment_updater.go b/pkg/services/mto_shipment/mto_shipment_updater.go index b70a83b43b9..601ad03e682 100644 --- a/pkg/services/mto_shipment/mto_shipment_updater.go +++ b/pkg/services/mto_shipment/mto_shipment_updater.go @@ -854,8 +854,6 @@ func (f *mtoShipmentUpdater) updateShipmentRecord(appCtx appcontext.AppContext, // we only need to do this if the estimated weight, primary addresses, and pickup date are being updated since those all impact pricing // we will compare data here to see if we even need to update the pricing if newShipment.MarketCode == models.MarketCodeInternational && - newShipment.ShipmentType != models.MTOShipmentTypeHHGIntoNTS || - newShipment.ShipmentType != models.MTOShipmentTypeHHGOutOfNTSDom || newShipment.PrimeEstimatedWeight != nil || newShipment.PickupAddress != nil && dbShipment.PickupAddress != nil && newShipment.PickupAddress.PostalCode != dbShipment.PickupAddress.PostalCode || newShipment.DestinationAddress != nil && dbShipment.DestinationAddress != nil && newShipment.DestinationAddress.PostalCode != dbShipment.DestinationAddress.PostalCode || From 46a4f808298014ace967109fb6c8d5f13d595a20 Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Thu, 9 Jan 2025 23:31:54 +0000 Subject: [PATCH 27/29] trying to find why tests are brekaing? --- pkg/services/mto_shipment/mto_shipment_updater.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/services/mto_shipment/mto_shipment_updater.go b/pkg/services/mto_shipment/mto_shipment_updater.go index 601ad03e682..b9f301dd765 100644 --- a/pkg/services/mto_shipment/mto_shipment_updater.go +++ b/pkg/services/mto_shipment/mto_shipment_updater.go @@ -855,8 +855,8 @@ func (f *mtoShipmentUpdater) updateShipmentRecord(appCtx appcontext.AppContext, // we will compare data here to see if we even need to update the pricing if newShipment.MarketCode == models.MarketCodeInternational && newShipment.PrimeEstimatedWeight != nil || - newShipment.PickupAddress != nil && dbShipment.PickupAddress != nil && newShipment.PickupAddress.PostalCode != dbShipment.PickupAddress.PostalCode || - newShipment.DestinationAddress != nil && dbShipment.DestinationAddress != nil && newShipment.DestinationAddress.PostalCode != dbShipment.DestinationAddress.PostalCode || + newShipment.PickupAddress != nil && newShipment.PickupAddress.PostalCode != dbShipment.PickupAddress.PostalCode || + newShipment.DestinationAddress != nil && newShipment.DestinationAddress.PostalCode != dbShipment.DestinationAddress.PostalCode || newShipment.RequestedPickupDate != nil && newShipment.RequestedPickupDate.Format("2006-01-02") != dbShipment.RequestedPickupDate.Format("2006-01-02") { portZip, portType, err := models.GetPortLocationInfoForShipment(appCtx.DB(), newShipment.ID) From 214c4ffe1091beae3d7e5e6c65c5903a91a10202 Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Fri, 10 Jan 2025 02:22:39 +0000 Subject: [PATCH 28/29] changing file completely back --- pkg/services/mto_shipment/mto_shipment_updater.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/services/mto_shipment/mto_shipment_updater.go b/pkg/services/mto_shipment/mto_shipment_updater.go index b9f301dd765..2ff73a2a431 100644 --- a/pkg/services/mto_shipment/mto_shipment_updater.go +++ b/pkg/services/mto_shipment/mto_shipment_updater.go @@ -854,10 +854,10 @@ func (f *mtoShipmentUpdater) updateShipmentRecord(appCtx appcontext.AppContext, // we only need to do this if the estimated weight, primary addresses, and pickup date are being updated since those all impact pricing // we will compare data here to see if we even need to update the pricing if newShipment.MarketCode == models.MarketCodeInternational && - newShipment.PrimeEstimatedWeight != nil || - newShipment.PickupAddress != nil && newShipment.PickupAddress.PostalCode != dbShipment.PickupAddress.PostalCode || - newShipment.DestinationAddress != nil && newShipment.DestinationAddress.PostalCode != dbShipment.DestinationAddress.PostalCode || - newShipment.RequestedPickupDate != nil && newShipment.RequestedPickupDate.Format("2006-01-02") != dbShipment.RequestedPickupDate.Format("2006-01-02") { + (newShipment.PrimeEstimatedWeight != nil || + newShipment.PickupAddress != nil && newShipment.PickupAddress.PostalCode != dbShipment.PickupAddress.PostalCode || + newShipment.DestinationAddress != nil && newShipment.DestinationAddress.PostalCode != dbShipment.DestinationAddress.PostalCode || + newShipment.RequestedPickupDate != nil && newShipment.RequestedPickupDate.Format("2006-01-02") != dbShipment.RequestedPickupDate.Format("2006-01-02")) { portZip, portType, err := models.GetPortLocationInfoForShipment(appCtx.DB(), newShipment.ID) if err != nil { From ba7dc65a5364bfd5d5fb87721ec118b0755f3170 Mon Sep 17 00:00:00 2001 From: KonstanceH Date: Fri, 10 Jan 2025 02:48:14 +0000 Subject: [PATCH 29/29] this is weird --- pkg/services/mto_shipment/mto_shipment_updater.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/services/mto_shipment/mto_shipment_updater.go b/pkg/services/mto_shipment/mto_shipment_updater.go index 2ff73a2a431..4da7227e596 100644 --- a/pkg/services/mto_shipment/mto_shipment_updater.go +++ b/pkg/services/mto_shipment/mto_shipment_updater.go @@ -855,8 +855,8 @@ func (f *mtoShipmentUpdater) updateShipmentRecord(appCtx appcontext.AppContext, // we will compare data here to see if we even need to update the pricing if newShipment.MarketCode == models.MarketCodeInternational && (newShipment.PrimeEstimatedWeight != nil || - newShipment.PickupAddress != nil && newShipment.PickupAddress.PostalCode != dbShipment.PickupAddress.PostalCode || - newShipment.DestinationAddress != nil && newShipment.DestinationAddress.PostalCode != dbShipment.DestinationAddress.PostalCode || + newShipment.PickupAddress != nil && dbShipment.PickupAddress != nil && newShipment.PickupAddress.PostalCode != dbShipment.PickupAddress.PostalCode || + newShipment.DestinationAddress != nil && dbShipment.DestinationAddress != nil && newShipment.DestinationAddress.PostalCode != dbShipment.DestinationAddress.PostalCode || newShipment.RequestedPickupDate != nil && newShipment.RequestedPickupDate.Format("2006-01-02") != dbShipment.RequestedPickupDate.Format("2006-01-02")) { portZip, portType, err := models.GetPortLocationInfoForShipment(appCtx.DB(), newShipment.ID)