Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

B 22087 main - Number of shipments in the search queue not decreasing when shipments are deleted #14856

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions pkg/handlers/ghcapi/internal/payloads/model_to_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -2628,13 +2628,7 @@ func SearchMoves(appCtx appcontext.AppContext, moves models.Moves) *ghcmessages.
for i, move := range moves {
customer := move.Orders.ServiceMember

numShipments := 0

for _, shipment := range move.MTOShipments {
if shipment.Status != models.MTOShipmentStatusDraft {
numShipments++
}
}
numShipments := len(move.MTOShipments)

var pickupDate, deliveryDate *strfmt.Date

Expand Down
20 changes: 20 additions & 0 deletions pkg/models/mto_shipments.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,23 @@ func FetchShipmentByID(db *pop.Connection, shipmentID uuid.UUID) (*MTOShipment,
}
return &mtoShipment, nil
}

// filters the returned MtoShipments for each move.
// Ignoring mto shipments that have been deleted, cancelled, or rejected.
func FilterDeletedRejectedCanceledMtoShipments(unfilteredShipments MTOShipments) MTOShipments {
if len(unfilteredShipments) == 0 {
return unfilteredShipments
}

filteredShipments := MTOShipments{}
for _, shipment := range unfilteredShipments {
if shipment.DeletedAt == nil &&
(shipment.Status != MTOShipmentStatusDraft) &&
(shipment.Status != MTOShipmentStatusRejected) &&
(shipment.Status != MTOShipmentStatusCanceled) {
filteredShipments = append(filteredShipments, shipment)
}
}

return filteredShipments
}
8 changes: 7 additions & 1 deletion pkg/services/move/move_searcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (s moveSearcher) SearchMoves(appCtx appcontext.AppContext, params *services
Join("addresses as origin_addresses", "origin_addresses.id = origin_duty_locations.address_id").
Join("duty_locations as new_duty_locations", "new_duty_locations.id = orders.new_duty_location_id").
Join("addresses as new_addresses", "new_addresses.id = new_duty_locations.address_id").
LeftJoin("mto_shipments", "mto_shipments.move_id = moves.id AND mto_shipments.status <> 'DRAFT'").
LeftJoin("mto_shipments", "mto_shipments.move_id = moves.id").
LeftJoin("move_to_gbloc", "move_to_gbloc.move_id = moves.id").
GroupBy("moves.id", "service_members.id", "origin_addresses.id", "new_addresses.id").
Where("show = TRUE")
Expand Down Expand Up @@ -105,6 +105,12 @@ func (s moveSearcher) SearchMoves(appCtx appcontext.AppContext, params *services
if err != nil {
return models.Moves{}, 0, apperror.NewQueryError("Move", err, "")
}

for i := range moves {
if moves[i].MTOShipments != nil {
moves[i].MTOShipments = models.FilterDeletedRejectedCanceledMtoShipments(moves[i].MTOShipments)
}
}
return moves, query.Paginator.TotalEntriesSize, nil
}

Expand Down
91 changes: 91 additions & 0 deletions pkg/services/move/move_searcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,97 @@ func (suite *MoveServiceSuite) TestMoveSearch() {
suite.Equal(secondMove.Locator, moves[0].Locator)
suite.Equal(2, totalCount)
})
suite.Run("filtering mto shipments search results", func() {
qaeUser := factory.BuildOfficeUserWithRoles(suite.DB(), nil, []roles.RoleType{roles.RoleTypeQae})

session := auth.Session{
ApplicationName: auth.OfficeApp,
Roles: qaeUser.User.Roles,
OfficeUserID: qaeUser.ID,
IDToken: "fake_token",
AccessToken: "fakeAccessToken",
}

moveWithShipmentsOfEveryStatus := factory.BuildMove(suite.DB(), []factory.Customization{
{
Model: models.Move{
Locator: "AAAAAA",
},
},
}, nil)

shipmentWithSubmittedStatus := factory.BuildMTOShipment(suite.DB(), []factory.Customization{
{
Model: moveWithShipmentsOfEveryStatus,
LinkOnly: true,
},
{
Model: models.MTOShipment{
Status: models.MTOShipmentStatusSubmitted,
},
},
}, nil)
shipmentWithCanceledStatus := factory.BuildMTOShipment(suite.DB(), []factory.Customization{
{
Model: moveWithShipmentsOfEveryStatus,
LinkOnly: true,
},
{
Model: models.MTOShipment{
Status: models.MTOShipmentStatusCanceled,
},
},
}, nil)
rejectionReason := "bad shipment"
shipmentWithRejectedStatus := factory.BuildMTOShipment(suite.DB(), []factory.Customization{
{
Model: moveWithShipmentsOfEveryStatus,
LinkOnly: true,
},
{
Model: models.MTOShipment{
Status: models.MTOShipmentStatusRejected,
RejectionReason: &rejectionReason,
},
},
}, nil)
shipmentWithCancellationRequestedStatus := factory.BuildMTOShipment(suite.DB(), []factory.Customization{
{
Model: moveWithShipmentsOfEveryStatus,
LinkOnly: true,
},
{
Model: models.MTOShipment{
Status: models.MTOShipmentStatusCancellationRequested,
},
},
}, nil)
shipmentWithApprovedStatus := factory.BuildMTOShipment(suite.DB(), []factory.Customization{
{
Model: moveWithShipmentsOfEveryStatus,
LinkOnly: true,
},
{
Model: models.MTOShipment{
Status: models.MTOShipmentStatusApproved,
},
},
}, nil)
moveWithShipmentsOfEveryStatus.MTOShipments = models.MTOShipments{
shipmentWithSubmittedStatus,
shipmentWithCanceledStatus,
shipmentWithRejectedStatus,
shipmentWithCancellationRequestedStatus,
shipmentWithApprovedStatus,
}
filteredShipments := models.FilterDeletedRejectedCanceledMtoShipments(moveWithShipmentsOfEveryStatus.MTOShipments)
moves, _, err := searcher.SearchMoves(suite.AppContextWithSessionForTest(&session), &services.SearchMovesParams{Locator: &moveWithShipmentsOfEveryStatus.Locator})
suite.NoError(err)
suite.Len(moves, 1)
suite.Len(moves[0].MTOShipments, 3)
suite.Equal(len(filteredShipments), 3)

})
}

func setupTestData(suite *MoveServiceSuite) (models.Move, models.Move, models.MTOShipment) {
Expand Down
Loading