diff --git a/migrations/app/migrations_manifest.txt b/migrations/app/migrations_manifest.txt index 80635ac6586..4556d45f28b 100644 --- a/migrations/app/migrations_manifest.txt +++ b/migrations/app/migrations_manifest.txt @@ -1001,3 +1001,4 @@ 20240917165710_update_duty_locations_provides_services_counseling.up.sql 20240930171315_updatePostalCodeToGbloc233BGNC.up.sql 20241001174400_add_is_oconus_column.up.sql +20241001193619_market-code-enum.up.sql diff --git a/migrations/app/schema/20241001193619_market-code-enum.up.sql b/migrations/app/schema/20241001193619_market-code-enum.up.sql new file mode 100644 index 00000000000..472e3ee6f3b --- /dev/null +++ b/migrations/app/schema/20241001193619_market-code-enum.up.sql @@ -0,0 +1,4 @@ +-- create and set market code +create type market_code_enum as enum ('i', 'd'); +ALTER TABLE mto_shipments ADD COLUMN IF NOT EXISTS market_code market_code_enum; +COMMENT ON COLUMN mto_shipments.market_code IS 'Market code indicator for the shipment. i for international and d for destination.'; diff --git a/pkg/models/mto_shipments.go b/pkg/models/mto_shipments.go index 62389e95fc7..dee472017dc 100644 --- a/pkg/models/mto_shipments.go +++ b/pkg/models/mto_shipments.go @@ -23,6 +23,14 @@ const ( NTSrRaw = "HHG_OUTOF_NTS_DOMESTIC" ) +// Market code indicator of international or domestic +type MarketCode string + +const ( + MarketCodeDomestic MarketCode = "d" // domestic + MarketCodeInternational MarketCode = "i" // international +) + const ( // MTOShipmentTypeHHG is an HHG Shipment Type default MTOShipmentTypeHHG MTOShipmentType = "HHG" @@ -160,6 +168,7 @@ type MTOShipment struct { OriginSITAuthEndDate *time.Time `db:"origin_sit_auth_end_date"` DestinationSITAuthEndDate *time.Time `db:"dest_sit_auth_end_date"` MobileHome *MobileHome `has_one:"mobile_home" fk_id:"shipment_id"` + MarketCode *MarketCode `db:"market_code"` } // TableName overrides the table name used by Pop. @@ -239,6 +248,14 @@ func (m *MTOShipment) Validate(_ *pop.Connection) (*validate.Errors, error) { string(DestinationTypeOtherThanAuthorized), }}) + // Validate MarketCode if exists + if m.MarketCode != nil { + vs = append(vs, &validators.StringInclusion{Field: string(*m.MarketCode), Name: "MarketCode", List: []string{ + string(MarketCodeDomestic), + string(MarketCodeInternational), + }}) + } + return validate.Validate(vs...), nil } diff --git a/pkg/models/mto_shipments_test.go b/pkg/models/mto_shipments_test.go index edb7a550b91..b17797726a3 100644 --- a/pkg/models/mto_shipments_test.go +++ b/pkg/models/mto_shipments_test.go @@ -15,6 +15,7 @@ func (suite *ModelSuite) TestMTOShipmentValidation() { sitDaysAllowance := 90 tacType := models.LOATypeHHG sacType := models.LOATypeHHG + marketCode := models.MarketCodeDomestic validMTOShipment := models.MTOShipment{ MoveTaskOrderID: uuid.Must(uuid.NewV4()), Status: models.MTOShipmentStatusApproved, @@ -23,6 +24,7 @@ func (suite *ModelSuite) TestMTOShipmentValidation() { SITDaysAllowance: &sitDaysAllowance, TACType: &tacType, SACType: &sacType, + MarketCode: &marketCode, } expErrors := map[string][]string{} suite.verifyValidationErrors(&validMTOShipment, expErrors) @@ -39,9 +41,11 @@ func (suite *ModelSuite) TestMTOShipmentValidation() { suite.Run("test rejected MTOShipment", func() { rejectionReason := "bad shipment" + marketCode := models.MarketCodeDomestic rejectedMTOShipment := models.MTOShipment{ MoveTaskOrderID: uuid.Must(uuid.NewV4()), Status: models.MTOShipmentStatusRejected, + MarketCode: &marketCode, RejectionReason: &rejectionReason, } expErrors := map[string][]string{} @@ -57,6 +61,7 @@ func (suite *ModelSuite) TestMTOShipmentValidation() { sitDaysAllowance := -1 serviceOrderNumber := "" tacType := models.LOAType("FAKE") + marketCode := models.MarketCode("x") invalidMTOShipment := models.MTOShipment{ MoveTaskOrderID: uuid.Must(uuid.NewV4()), Status: models.MTOShipmentStatusRejected, @@ -69,6 +74,7 @@ func (suite *ModelSuite) TestMTOShipmentValidation() { StorageFacilityID: &uuid.Nil, TACType: &tacType, SACType: &tacType, + MarketCode: &marketCode, } expErrors := map[string][]string{ "prime_estimated_weight": {"-1000 is not greater than 0."}, @@ -81,6 +87,7 @@ func (suite *ModelSuite) TestMTOShipmentValidation() { "storage_facility_id": {"StorageFacilityID can not be blank."}, "tactype": {"TACType is not in the list [HHG, NTS]."}, "sactype": {"SACType is not in the list [HHG, NTS]."}, + "market_code": {"MarketCode is not in the list [d, i]."}, } suite.verifyValidationErrors(&invalidMTOShipment, expErrors) })