Skip to content

Commit

Permalink
Merge branch 'main' into MAIN-B-22661
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljordan-caci authored Feb 26, 2025
2 parents f7f5d5d + 9703fbb commit 634eeda
Show file tree
Hide file tree
Showing 7 changed files with 1,033 additions and 8 deletions.
1 change: 1 addition & 0 deletions migrations/app/migrations_manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,7 @@
20250121184450_upd_duty_loc_B-22242.up.sql
20250123173216_add_destination_queue_db_func_and_gbloc_view.up.sql
20250123210535_update_re_intl_transit_times_for_ak_hhg.up.sql
20250127143137_insert_nsra_re_intl_transit_times.up.sql
20250204162411_updating_create_accessorial_service_item_proc_for_crating.up.sql
20250206173204_add_hawaii_data.up.sql
20250207153450_add_fetch_documents_func.up.sql
Expand Down

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions pkg/factory/address_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,21 @@ func GetTraitAddressAKZone4() []Customization {
},
}
}

// GetTraitAddressAKZone5 is an address in Zone 5 of Alaska for NSRA15 rates
func GetTraitAddressAKZone5() []Customization {

return []Customization{
{
Model: models.Address{
StreetAddress1: "Street Address 1",
StreetAddress2: models.StringPointer("P.O. Box 1234"),
StreetAddress3: models.StringPointer("c/o Another Person"),
City: "ANAKTUVUK",
State: "AK",
PostalCode: "99721",
IsOconus: models.BoolPointer(true),
},
},
}
}
14 changes: 10 additions & 4 deletions pkg/services/mto_shipment/mto_shipment_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ func (o *mtoShipmentStatusUpdater) setRequiredDeliveryDate(appCtx appcontext.App
pickupLocation = shipment.PickupAddress
deliveryLocation = shipment.DestinationAddress
}
requiredDeliveryDate, calcErr := CalculateRequiredDeliveryDate(appCtx, o.planner, *pickupLocation, *deliveryLocation, *shipment.ScheduledPickupDate, weight.Int(), shipment.MarketCode, shipment.MoveTaskOrderID)
requiredDeliveryDate, calcErr := CalculateRequiredDeliveryDate(appCtx, o.planner, *pickupLocation, *deliveryLocation, *shipment.ScheduledPickupDate, weight.Int(), shipment.MarketCode, shipment.MoveTaskOrderID, shipment.ShipmentType)
if calcErr != nil {
return calcErr
}
Expand Down Expand Up @@ -1192,7 +1192,7 @@ func reServiceCodesForShipment(shipment models.MTOShipment) []models.ReServiceCo
// CalculateRequiredDeliveryDate function is used to get a distance calculation using the pickup and destination addresses. It then uses
// the value returned to make a fetch on the ghc_domestic_transit_times table and returns a required delivery date
// based on the max_days_transit_time.
func CalculateRequiredDeliveryDate(appCtx appcontext.AppContext, planner route.Planner, pickupAddress models.Address, destinationAddress models.Address, pickupDate time.Time, weight int, marketCode models.MarketCode, moveID uuid.UUID) (*time.Time, error) {
func CalculateRequiredDeliveryDate(appCtx appcontext.AppContext, planner route.Planner, pickupAddress models.Address, destinationAddress models.Address, pickupDate time.Time, weight int, marketCode models.MarketCode, moveID uuid.UUID, shipmentType models.MTOShipmentType) (*time.Time, error) {
internationalShipment := marketCode == models.MarketCodeInternational

distance, err := planner.ZipTransitDistance(appCtx, pickupAddress.PostalCode, destinationAddress.PostalCode, internationalShipment)
Expand Down Expand Up @@ -1264,8 +1264,14 @@ func CalculateRequiredDeliveryDate(appCtx appcontext.AppContext, planner route.P
}
}

if intlTransTime.HhgTransitTime != nil {
requiredDeliveryDate = requiredDeliveryDate.AddDate(0, 0, *intlTransTime.HhgTransitTime)
if shipmentType != models.MTOShipmentTypeUnaccompaniedBaggage {
if intlTransTime.HhgTransitTime != nil {
requiredDeliveryDate = requiredDeliveryDate.AddDate(0, 0, *intlTransTime.HhgTransitTime)
}
} else {
if intlTransTime.UbTransitTime != nil {
requiredDeliveryDate = requiredDeliveryDate.AddDate(0, 0, *intlTransTime.UbTransitTime)
}
}
}

Expand Down
86 changes: 84 additions & 2 deletions pkg/services/mto_shipment/mto_shipment_updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2493,6 +2493,7 @@ func (suite *MTOShipmentServiceSuite) TestUpdateMTOShipmentStatus() {
zone2Address := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddressAKZone2})
zone3Address := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddressAKZone3})
zone4Address := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddressAKZone4})
zone5Address := factory.BuildAddress(suite.DB(), nil, []factory.Trait{factory.GetTraitAddressAKZone5})

estimatedWeight := unit.Pound(11000)

Expand Down Expand Up @@ -2587,10 +2588,91 @@ func (suite *MTOShipmentServiceSuite) TestUpdateMTOShipmentStatus() {
err = suite.DB().Find(&fetchedShipment, shipment.ID)
suite.NoError(err)
suite.NotNil(fetchedShipment.RequiredDeliveryDate)
fmt.Println("fetchedShipment.RequiredDeliveryDate")
fmt.Println(fetchedShipment.RequiredDeliveryDate)
suite.Equal(rdd20DaysDate.Format(time.RFC3339), fetchedShipment.RequiredDeliveryDate.Format(time.RFC3339))
}
testCases60Days := []struct {
pickupLocation models.Address
destinationLocation models.Address
}{
{conusAddress, zone5Address},
{zone5Address, conusAddress},
}

// adding 72 days; ghcDomesticTransitTime0LbsUpper.MaxDaysTransitTime is 12, plus 60 for Zone 5 HHG
rdd60DaysDate := testdatagen.DateInsidePeakRateCycle.AddDate(0, 0, 72)
for _, testCase := range testCases60Days {
shipment := factory.BuildMTOShipmentMinimal(suite.DB(), []factory.Customization{
{
Model: move,
LinkOnly: true,
},
{
Model: models.MTOShipment{
ShipmentType: models.MTOShipmentTypeHHG,
ScheduledPickupDate: &testdatagen.DateInsidePeakRateCycle,
PrimeEstimatedWeight: &estimatedWeight,
Status: models.MTOShipmentStatusSubmitted,
},
},
{
Model: testCase.pickupLocation,
Type: &factory.Addresses.PickupAddress,
LinkOnly: true,
},
{
Model: testCase.destinationLocation,
Type: &factory.Addresses.DeliveryAddress,
LinkOnly: true,
},
}, nil)
shipmentEtag := etag.GenerateEtag(shipment.UpdatedAt)
_, err = updater.UpdateMTOShipmentStatus(appCtx, shipment.ID, status, nil, nil, shipmentEtag)
suite.NoError(err)

fetchedShipment := models.MTOShipment{}
err = suite.DB().Find(&fetchedShipment, shipment.ID)
suite.NoError(err)
suite.NotNil(fetchedShipment.RequiredDeliveryDate)
suite.Equal(rdd60DaysDate.Format(time.RFC3339), fetchedShipment.RequiredDeliveryDate.Format(time.RFC3339))
}

// adding 42 days; ghcDomesticTransitTime0LbsUpper.MaxDaysTransitTime is 12, plus 30 for Zone 5 UB
rdd60DaysDateUB := testdatagen.DateInsidePeakRateCycle.AddDate(0, 0, 42)
for _, testCase := range testCases60Days {
shipment := factory.BuildMTOShipmentMinimal(suite.DB(), []factory.Customization{
{
Model: move,
LinkOnly: true,
},
{
Model: models.MTOShipment{
ShipmentType: models.MTOShipmentTypeUnaccompaniedBaggage,
ScheduledPickupDate: &testdatagen.DateInsidePeakRateCycle,
PrimeEstimatedWeight: &estimatedWeight,
Status: models.MTOShipmentStatusSubmitted,
},
},
{
Model: testCase.pickupLocation,
Type: &factory.Addresses.PickupAddress,
LinkOnly: true,
},
{
Model: testCase.destinationLocation,
Type: &factory.Addresses.DeliveryAddress,
LinkOnly: true,
},
}, nil)
shipmentEtag := etag.GenerateEtag(shipment.UpdatedAt)
_, err = updater.UpdateMTOShipmentStatus(appCtx, shipment.ID, status, nil, nil, shipmentEtag)
suite.NoError(err)

fetchedShipment := models.MTOShipment{}
err = suite.DB().Find(&fetchedShipment, shipment.ID)
suite.NoError(err)
suite.NotNil(fetchedShipment.RequiredDeliveryDate)
suite.Equal(rdd60DaysDateUB.Format(time.RFC3339), fetchedShipment.RequiredDeliveryDate.Format(time.RFC3339))
}
})

suite.Run("Cannot set SUBMITTED status on shipment via UpdateMTOShipmentStatus", func() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/services/mto_shipment/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func checkPrimeValidationsOnModel(planner route.Planner) validator {
weight = older.NTSRecordedWeight
}
requiredDeliveryDate, err := CalculateRequiredDeliveryDate(appCtx, planner, *latestPickupAddress,
*latestDestinationAddress, *latestSchedPickupDate, weight.Int(), older.MarketCode, older.MoveTaskOrderID)
*latestDestinationAddress, *latestSchedPickupDate, weight.Int(), older.MarketCode, older.MoveTaskOrderID, older.ShipmentType)
if err != nil {
verrs.Add("requiredDeliveryDate", err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/services/mto_shipment/shipment_approver.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (f *shipmentApprover) setRequiredDeliveryDate(appCtx appcontext.AppContext,
deliveryLocation = shipment.DestinationAddress
weight = shipment.PrimeEstimatedWeight.Int()
}
requiredDeliveryDate, calcErr := CalculateRequiredDeliveryDate(appCtx, f.planner, *pickupLocation, *deliveryLocation, *shipment.ScheduledPickupDate, weight, shipment.MarketCode, shipment.MoveTaskOrderID)
requiredDeliveryDate, calcErr := CalculateRequiredDeliveryDate(appCtx, f.planner, *pickupLocation, *deliveryLocation, *shipment.ScheduledPickupDate, weight, shipment.MarketCode, shipment.MoveTaskOrderID, shipment.ShipmentType)
if calcErr != nil {
return calcErr
}
Expand Down

0 comments on commit 634eeda

Please sign in to comment.