From 3ead62acf539a89bc671ba82f1352a86e8b7dff4 Mon Sep 17 00:00:00 2001 From: pambecker Date: Mon, 20 Jan 2025 15:41:41 +0000 Subject: [PATCH] more oconus updates for gbloc --- pkg/models/mto_shipments.go | 27 ------------- pkg/models/order.go | 40 ------------------- .../ghc_payment_request_invoice_generator.go | 18 +++++++-- .../move_task_order_fetcher.go | 22 +++++++--- .../move_task_order_creator.go | 28 ++++++++----- 5 files changed, 49 insertions(+), 86 deletions(-) diff --git a/pkg/models/mto_shipments.go b/pkg/models/mto_shipments.go index 917e75b7978..ee91209f961 100644 --- a/pkg/models/mto_shipments.go +++ b/pkg/models/mto_shipments.go @@ -277,33 +277,6 @@ func GetCustomerFromShipment(db *pop.Connection, shipmentID uuid.UUID) (*Service return &serviceMember, nil } -func (m *MTOShipment) UpdateOrdersDestinationGBLOC(db *pop.Connection) error { - // Since this requires looking up the order in the DB, the order must have an ID. This means, the order has to have been created first. - if uuid.UUID.IsNil(m.ID) { - return fmt.Errorf("error updating orders destination GBLOC for shipment due to no shipment ID provided") - } - - var err error - var order Order - - err = db.Load(&m, "MoveTaskOrder.OrdersID") - if err != nil { - return fmt.Errorf("error loading orders for shipment ID: %s with error %w", m.ID, err) - } - - order, err = FetchOrder(db, m.MoveTaskOrder.OrdersID) - if err != nil { - return fmt.Errorf("error fetching order for shipment ID: %s with error %w", m.ID, err) - } - - err = order.UpdateDestinationGBLOC(db) - if err != nil { - return fmt.Errorf("error fetching GBLOC for postal code with error %w", err) - } - - return nil -} - // Helper function to check that an MTO Shipment contains a PPM Shipment func (m MTOShipment) ContainsAPPMShipment() bool { return m.PPMShipment != nil diff --git a/pkg/models/order.go b/pkg/models/order.go index 84b9d8a0446..762b3881c5b 100644 --- a/pkg/models/order.go +++ b/pkg/models/order.go @@ -492,46 +492,6 @@ func (o Order) GetDestinationAddressForAssociatedMoves(db *pop.Connection) (*Add return &destinationAddress, nil } -// UpdateDestinationGBLOC updates the destination GBLOC for the associated Order in the DB -func (o Order) UpdateDestinationGBLOC(db *pop.Connection) error { - // Since this requires looking up the order in the DB, the order must have an ID. This means, the order has to have been created first. - if uuid.UUID.IsNil(o.ID) { - return errors.WithMessage(ErrInvalidOrderID, "You must created the order in the DB before updating the destination GBLOC.") - } - - var dbOrder Order - err := db.Find(&dbOrder, o.ID) - if err != nil { - if err.Error() == RecordNotFoundErrorString { - return errors.WithMessage(err, "No Order was found for the order ID "+o.ID.String()) - } - return err - } - - err = db.Load(&o, "NewDutyLocation.Address.PostalCode") - if err != nil { - if err.Error() == RecordNotFoundErrorString { - return errors.WithMessage(err, "No New Duty Location Address Postal Code was found for the order ID "+o.ID.String()) - } - return err - } - - var gblocResult PostalCodeToGBLOC - gblocResult, err = FetchGBLOCForPostalCode(db, o.NewDutyLocation.Address.PostalCode) - if err != nil { - return errors.WithMessage(err, "Could not get GBLOC for postal code "+o.NewDutyLocation.Address.PostalCode) - } - - dbOrder.DestinationGBLOC = &gblocResult.GBLOC - - err = db.Save(&dbOrder) - if err != nil { - return errors.WithMessage(err, "Could not save the updated destination GBLOC for order ID "+o.ID.String()) - } - - return nil -} - // IsCompleteForGBL checks if orders have all fields necessary to generate a GBL func (o *Order) IsCompleteForGBL() bool { diff --git a/pkg/services/invoice/ghc_payment_request_invoice_generator.go b/pkg/services/invoice/ghc_payment_request_invoice_generator.go index fd111048868..f9e863df64c 100644 --- a/pkg/services/invoice/ghc_payment_request_invoice_generator.go +++ b/pkg/services/invoice/ghc_payment_request_invoice_generator.go @@ -447,16 +447,26 @@ func (g ghcPaymentRequestInvoiceGenerator) createBuyerAndSellerOrganizationNames return apperror.NewQueryError("MTOShipments", err, fmt.Sprintf("error querying for shipments pickup address gbloc to use in N1*BY segments in PaymentRequest %s: %s", paymentRequestID, err)) } } - pickupPostalCodeToGbloc, gblocErr := models.FetchGBLOCForPostalCode(appCtx.DB(), address.PostalCode) - if gblocErr != nil { - return apperror.NewInvalidInputError(pickupPostalCodeToGbloc.ID, gblocErr, nil, "unable to determine GBLOC for pickup postal code") + var pickupPostalCodeToGbloc *string + if *address.IsOconus { + originDutyLocationGBLOCOconus, gblocErr := models.FetchAddressGbloc(appCtx.DB(), address, orders.ServiceMember) + if gblocErr != nil { + return apperror.NewInvalidInputError(address.ID, gblocErr, nil, "unable to determine GBLOC for Oconus pickup postal code") + } + pickupPostalCodeToGbloc = originDutyLocationGBLOCOconus + } else { + originDutyLocationGBLOCConus, gblocErr := models.FetchGBLOCForPostalCode(appCtx.DB(), originDutyLocation.Address.PostalCode) + if gblocErr != nil { + return apperror.NewInvalidInputError(address.ID, gblocErr, nil, "unable to determine GBLOC for pickup postal code") + } + pickupPostalCodeToGbloc = &originDutyLocationGBLOCConus.GBLOC } header.BuyerOrganizationName = edisegment.N1{ EntityIdentifierCode: "BY", Name: truncateStr(originDutyLocation.Name, maxLocationlength), IdentificationCodeQualifier: "92", - IdentificationCode: modifyGblocIfMarines(*orders.ServiceMember.Affiliation, pickupPostalCodeToGbloc.GBLOC), + IdentificationCode: modifyGblocIfMarines(*orders.ServiceMember.Affiliation, *pickupPostalCodeToGbloc), } // seller organization name diff --git a/pkg/services/move_task_order/move_task_order_fetcher.go b/pkg/services/move_task_order/move_task_order_fetcher.go index 1d30aef5ceb..002634f97e4 100644 --- a/pkg/services/move_task_order/move_task_order_fetcher.go +++ b/pkg/services/move_task_order/move_task_order_fetcher.go @@ -324,13 +324,23 @@ func (f moveTaskOrderFetcher) FetchMoveTaskOrder(appCtx appcontext.AppContext, s mto.MTOServiceItems = loadedServiceItems if mto.Orders.DestinationGBLOC == nil { - newDutyLocationGBLOC, err := models.FetchGBLOCForPostalCode(appCtx.DB(), mto.Orders.NewDutyLocation.Address.PostalCode) - if err != nil { - err = apperror.NewBadDataError("New duty location GBLOC cannot be verified") - appCtx.Logger().Error(err.Error()) - return &models.Move{}, apperror.NewQueryError("DestinationGBLOC", err, "") + var newDutyLocationGBLOC *string + if *mto.Orders.NewDutyLocation.Address.IsOconus { + newDutyLocationGBLOCOconus, err := models.FetchAddressGbloc(appCtx.DB(), mto.Orders.NewDutyLocation.Address, mto.Orders.ServiceMember) + if err != nil { + return nil, apperror.NewNotFoundError(mto.Orders.NewDutyLocation.ID, "while looking for Duty Location Oconus GBLOC") + } + newDutyLocationGBLOC = newDutyLocationGBLOCOconus + } else { + newDutyLocationGBLOCConus, err := models.FetchGBLOCForPostalCode(appCtx.DB(), mto.Orders.NewDutyLocation.Address.PostalCode) + if err != nil { + err = apperror.NewBadDataError("New duty location GBLOC cannot be verified") + appCtx.Logger().Error(err.Error()) + return &models.Move{}, apperror.NewQueryError("DestinationGBLOC", err, "") + } + newDutyLocationGBLOC = &newDutyLocationGBLOCConus.GBLOC } - mto.Orders.DestinationGBLOC = &newDutyLocationGBLOC.GBLOC + mto.Orders.DestinationGBLOC = newDutyLocationGBLOC } return mto, nil diff --git a/pkg/services/support/move_task_order/move_task_order_creator.go b/pkg/services/support/move_task_order/move_task_order_creator.go index 85f3500c2de..d0bc162d54c 100644 --- a/pkg/services/support/move_task_order/move_task_order_creator.go +++ b/pkg/services/support/move_task_order/move_task_order_creator.go @@ -132,17 +132,27 @@ func createOrder(appCtx appcontext.AppContext, customer *models.ServiceMember, o order.OriginDutyLocation = originDutyLocation order.OriginDutyLocationID = &originDutyLocationID - var originDutyLocationGBLOC models.PostalCodeToGBLOC - originDutyLocationGBLOC, err = models.FetchGBLOCForPostalCode(appCtx.DB(), originDutyLocation.Address.PostalCode) - if err != nil { - switch err { - case sql.ErrNoRows: - return nil, apperror.NewNotFoundError(originDutyLocationID, "while looking for Duty Location PostalCodeToGBLOC") - default: - return nil, apperror.NewQueryError("PostalCodeToGBLOC", err, "") + var originDutyLocationGBLOC *string + if *originDutyLocation.Address.IsOconus { + originDutyLocationGBLOCOconus, err := models.FetchAddressGbloc(appCtx.DB(), originDutyLocation.Address, order.ServiceMember) + if err != nil { + return nil, apperror.NewNotFoundError(originDutyLocation.ID, "while looking for Duty Location Oconus GBLOC") + } + originDutyLocationGBLOC = originDutyLocationGBLOCOconus + } else { + originDutyLocationGBLOCConus, err := models.FetchGBLOCForPostalCode(appCtx.DB(), originDutyLocation.Address.PostalCode) + if err != nil { + switch err { + case sql.ErrNoRows: + return nil, apperror.NewNotFoundError(originDutyLocation.ID, "while looking for Duty Location PostalCodeToGBLOC") + default: + return nil, apperror.NewQueryError("PostalCodeToGBLOC", err, "") + } } + originDutyLocationGBLOC = &originDutyLocationGBLOCConus.GBLOC } - order.OriginDutyLocationGBLOC = &originDutyLocationGBLOC.GBLOC + + order.OriginDutyLocationGBLOC = originDutyLocationGBLOC } // Check that the uploaded orders document exists var uploadedOrders *models.Document