Skip to content

Commit

Permalink
Merge pull request #13675 from transcom/MAIN-B-20946
Browse files Browse the repository at this point in the history
MAIN B-20946 SSW max obligation calculation correction
  • Loading branch information
deandreJones authored Sep 10, 2024
2 parents c0a9fea + 92f6df2 commit 3657a7f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 18 deletions.
6 changes: 5 additions & 1 deletion pkg/services/ppm_closeout/ppm_closeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,11 @@ func (p *ppmCloseoutFetcher) getServiceItemPrices(appCtx appcontext.AppContext,
ppmToMtoShipment = ppmshipment.MapPPMShipmentFinalFields(ppmShipment, totalWeight)
} else {
// Reassign ppm shipment fields to their expected location on the mto shipment for dates, addresses, weights ...
ppmToMtoShipment = ppmshipment.MapPPMShipmentEstimatedFields(ppmShipment)
ppmToMtoShipment, err = ppmshipment.MapPPMShipmentEstimatedFields(appCtx, ppmShipment)
if err != nil {
logger.Error("unable to map PPM estimated fields", zap.Error(err))
return serviceItemPrices{}, err
}
}

sitCosts, err := p.GetExpenseStoragePrice(appCtx, ppmShipment.ID)
Expand Down
24 changes: 20 additions & 4 deletions pkg/services/ppmshipment/ppm_estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,11 @@ func (f estimatePPM) calculatePrice(appCtx appcontext.AppContext, ppmShipment *m
mtoShipment = MapPPMShipmentFinalFields(*ppmShipment, totalWeightFromWeightTickets)
} else {
// Reassign ppm shipment fields to their expected location on the mto shipment for dates, addresses, weights ...
mtoShipment = MapPPMShipmentEstimatedFields(*ppmShipment)
mtoShipment, err = MapPPMShipmentEstimatedFields(appCtx, *ppmShipment)
if err != nil {
logger.Error("unable to map PPM estimated fields", zap.Error(err))
return nil, err
}
}

totalPrice := unit.Cents(0)
Expand Down Expand Up @@ -674,15 +678,27 @@ func priceAdditionalDaySIT(appCtx appcontext.AppContext, pricer services.ParamsP

// mapPPMShipmentEstimatedFields remaps our PPMShipment specific information into the fields where the service param lookups
// expect to find them on the MTOShipment model. This is only in-memory and shouldn't get saved to the database.
func MapPPMShipmentEstimatedFields(ppmShipment models.PPMShipment) models.MTOShipment {
func MapPPMShipmentEstimatedFields(appCtx appcontext.AppContext, ppmShipment models.PPMShipment) (models.MTOShipment, error) {
// we have access to the MoveTaskOrderID in the ppmShipment object so we can use that to get the customer's maximum weight entitlement
var move models.Move
err := appCtx.DB().Q().Eager(
"Orders.Entitlement",
).Where("show = TRUE").Find(&move, ppmShipment.Shipment.MoveTaskOrderID)
if err != nil {
return models.MTOShipment{}, apperror.NewNotFoundError(ppmShipment.ID, " error querying move")
}
orders := move.Orders
if orders.Entitlement.DBAuthorizedWeight == nil {
return models.MTOShipment{}, apperror.NewNotFoundError(ppmShipment.ID, " DB authorized weight cannot be nil")
}

ppmShipment.Shipment.ActualPickupDate = &ppmShipment.ExpectedDepartureDate
ppmShipment.Shipment.RequestedPickupDate = &ppmShipment.ExpectedDepartureDate
ppmShipment.Shipment.PickupAddress = &models.Address{PostalCode: ppmShipment.PickupAddress.PostalCode}
ppmShipment.Shipment.DestinationAddress = &models.Address{PostalCode: ppmShipment.DestinationAddress.PostalCode}
ppmShipment.Shipment.PrimeActualWeight = ppmShipment.EstimatedWeight
ppmShipment.Shipment.PrimeActualWeight = (*unit.Pound)(orders.Entitlement.DBAuthorizedWeight)

return ppmShipment.Shipment
return ppmShipment.Shipment, nil
}

// mapPPMShipmentFinalFields remaps our PPMShipment specific information into the fields where the service param lookups
Expand Down
21 changes: 19 additions & 2 deletions pkg/services/ppmshipment/ppm_estimator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ func (suite *PPMShipmentSuite) TestPPMEstimator() {

suite.Equal(oldPPMShipment.PickupAddress.PostalCode, newPPM.PickupAddress.PostalCode)
suite.Equal(unit.Pound(5000), *newPPM.EstimatedWeight)
suite.Equal(unit.Cents(70064364), *ppmEstimate)
suite.Equal(unit.Cents(112102682), *ppmEstimate)
})

suite.Run("Estimated Incentive - Success - clears advance and advance requested values", func() {
Expand Down Expand Up @@ -540,7 +540,7 @@ func (suite *PPMShipmentSuite) TestPPMEstimator() {
suite.NilOrNoVerrs(err)
suite.Nil(newPPM.HasRequestedAdvance)
suite.Nil(newPPM.AdvanceAmountRequested)
suite.Equal(unit.Cents(38213948), *ppmEstimate)
suite.Equal(unit.Cents(112102682), *ppmEstimate)
})

suite.Run("Estimated Incentive - does not change when required fields are the same", func() {
Expand Down Expand Up @@ -1637,7 +1637,24 @@ func (suite *PPMShipmentSuite) TestPPMEstimator() {
setupPricerData()

destinationLocation := models.SITLocationTypeDestination
move := factory.BuildMove(suite.DB(), []factory.Customization{
{
Model: models.Order{
ID: uuid.Must(uuid.NewV4()),
},
},
{
Model: models.Entitlement{
ID: uuid.Must(uuid.NewV4()),
DBAuthorizedWeight: models.IntPointer(2000),
},
},
}, nil)
originalShipment := factory.BuildPPMShipment(suite.DB(), []factory.Customization{
{
Model: move,
LinkOnly: true,
},
{
Model: models.PPMShipment{
SITExpected: models.BoolPointer(true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func FormatValuesShipmentSummaryWorksheetFormPage1(data services.ShipmentSummary
page1.ActualObligationGCC100 = formattedShipment.ShipmentWeightForObligation + " - Estimated lbs; " + formattedShipment.FinalIncentive
page1.PreparationDate1 = formatAOADate(data.SignedCertifications, data.PPMShipment.ID)
}
page1.MaxObligationGCC100 = FormatWeights(data.WeightAllotment.TotalWeight) + " lbs; " + formattedShipment.EstimatedIncentive
page1.MaxObligationGCC100 = FormatWeights(data.WeightAllotment.Entitlement) + " lbs; " + formattedShipment.EstimatedIncentive
page1.MaxObligationGCCMaxAdvance = formattedShipment.MaxAdvance
page1.ActualObligationAdvance = formattedShipment.AdvanceAmountReceived
page1.MaxObligationSIT = fmt.Sprintf("%02d Days in SIT", data.MaxSITStorageEntitlement)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ func (suite *ShipmentSummaryWorksheetServiceSuite) TestFetchDataShipmentSummaryW
suite.Equal(ppmShipment.EstimatedWeight, ssd.PPMShipments[0].EstimatedWeight)
suite.Require().NotNil(ssd.PPMShipments[0].AdvanceAmountRequested)
suite.Equal(ppmShipment.AdvanceAmountRequested, ssd.PPMShipments[0].AdvanceAmountRequested)
// suite.Equal(signedCertification.ID, ssd.SignedCertification.ID)
}

func (suite *ShipmentSummaryWorksheetServiceSuite) TestFetchDataShipmentSummaryWorksheetWithErrorNoMove() {
Expand Down Expand Up @@ -272,7 +271,6 @@ func (suite *ShipmentSummaryWorksheetServiceSuite) TestFetchDataShipmentSummaryW
suite.Equal(ppmShipment.EstimatedWeight, ssd.PPMShipments[0].EstimatedWeight)
suite.Require().NotNil(ssd.PPMShipments[0].AdvanceAmountRequested)
suite.Equal(ppmShipment.AdvanceAmountRequested, ssd.PPMShipments[0].AdvanceAmountRequested)
// suite.Equal(signedCertification.ID, ssd.SignedCertification.ID)
suite.Require().Len(ssd.MovingExpenses, 0)
}

Expand Down Expand Up @@ -318,12 +316,14 @@ func (suite *ShipmentSummaryWorksheetServiceSuite) TestFormatValuesShipmentSumma
netWeight := unit.Pound(4000)
cents := unit.Cents(1000)
locator := "ABCDEF-01"
PPMShipment := models.PPMShipment{
estIncentive := unit.Cents(1000000)
PPMShipments := models.PPMShipment{
ExpectedDepartureDate: expectedPickupDate,
ActualMoveDate: &actualPickupDate,
Status: models.PPMShipmentStatusWaitingOnCustomer,
EstimatedWeight: &netWeight,
AdvanceAmountRequested: &cents,
EstimatedIncentive: &estIncentive,
Shipment: models.MTOShipment{
ShipmentLocator: &locator,
},
Expand All @@ -336,7 +336,7 @@ func (suite *ShipmentSummaryWorksheetServiceSuite) TestFormatValuesShipmentSumma
PPMRemainingEntitlement: 3000,
WeightAllotment: wtgEntitlements,
PreparationDate: time.Date(2019, 1, 1, 1, 1, 1, 1, time.UTC),
PPMShipment: PPMShipment,
PPMShipment: PPMShipments,
}
sswPage1, err := FormatValuesShipmentSummaryWorksheetFormPage1(ssd, false)
suite.NoError(err)
Expand All @@ -351,13 +351,10 @@ func (suite *ShipmentSummaryWorksheetServiceSuite) TestFormatValuesShipmentSumma
suite.Equal("444-555-8888", sswPage1.PreferredPhoneNumber)
suite.Equal("michael+ppm-expansion_1@truss.works", sswPage1.PreferredEmail)
suite.Equal("1234567890", sswPage1.DODId)

suite.Equal("Air Force", sswPage1.IssuingBranchOrAgency)
suite.Equal("21-Dec-2018", sswPage1.OrdersIssueDate)
suite.Equal("PCS/012345", sswPage1.OrdersTypeAndOrdersNumber)

suite.Equal("Fort Eisenhower, GA 30813", sswPage1.NewDutyAssignment)

suite.Equal("15,000", sswPage1.WeightAllotment)
suite.Equal("2,000", sswPage1.WeightAllotmentProGear)
suite.Equal("500", sswPage1.WeightAllotmentProgearSpouse)
Expand All @@ -367,9 +364,8 @@ func (suite *ShipmentSummaryWorksheetServiceSuite) TestFormatValuesShipmentSumma
suite.Equal("11-Jan-2019", sswPage1.ShipmentPickUpDates)
suite.Equal("4,000 lbs - Estimated", sswPage1.ShipmentWeights)
suite.Equal("Waiting On Customer", sswPage1.ShipmentCurrentShipmentStatuses)

suite.Equal("17,500", sswPage1.TotalWeightAllotmentRepeat)

suite.Equal("15,000 lbs; $10,000.00", sswPage1.MaxObligationGCC100)
suite.Equal("3,000", sswPage1.PPMRemainingEntitlement)

// quick test when there is no PPM actual move date
Expand Down
2 changes: 1 addition & 1 deletion playwright/tests/office/ppms/happyPathFlows.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ test.describe('Services counselor user', () => {
await expect(shipmentContainer.locator('[data-testid="estimatedWeight"]')).toContainText('4,000 lbs');
await expect(shipmentContainer.locator('[data-testid="proGearWeight"]')).toContainText('Yes, 1,000 lbs');
await expect(shipmentContainer.locator('[data-testid="spouseProGear"]')).toContainText('Yes, 500 lbs');
await expect(shipmentContainer.locator('[data-testid="estimatedIncentive"]')).toContainText('$67,689');
await expect(shipmentContainer.locator('[data-testid="estimatedIncentive"]')).toContainText('$223,235');
await expect(shipmentContainer.locator('[data-testid="hasRequestedAdvance"]')).toContainText('Yes, $10,000');
await expect(shipmentContainer.locator('[data-testid="counselorRemarks"]')).toContainText(
'Added correct incentive',
Expand Down

0 comments on commit 3657a7f

Please sign in to comment.