Skip to content

Commit

Permalink
Merge branch 'main' into adh-MB-16500-chi-routing
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Jul 24, 2023
2 parents 2ffb8ff + a0ca7b4 commit 0967560
Show file tree
Hide file tree
Showing 23 changed files with 686 additions and 54 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/analyze-bundle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
- name: Set up node
uses: actions/setup-node@v3
with:
node-version: '18.13.0'
node-version-file: '.tool-versions'

- name: Install dependencies
run: yarn install
Expand Down Expand Up @@ -85,7 +85,7 @@ jobs:
- name: Set up node
uses: actions/setup-node@v3
with:
node-version: '18.13.0'
node-version-file: '.tool-versions'

- name: Install dependencies
run: yarn install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/front-end-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up node
uses: actions/setup-node@v3
with:
node-version: '18.13.0'
node-version-file: '.tool-versions'

- name: Install dependencies
run: yarn install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/happo-tests-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up node
uses: actions/setup-node@v3
with:
node-version: '18.13.0'
node-version-file: '.tool-versions'

- name: Install dependencies
run: yarn install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/happo-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Set up node
uses: actions/setup-node@v3
with:
node-version: '18.13.0'
node-version-file: '.tool-versions'

- name: Install dependencies
run: yarn install
Expand Down
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
golang 1.20.5
nodejs 18.13.0
1 change: 0 additions & 1 deletion Brewfile.local
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ brew 'diffutils'
brew 'direnv'
brew 'entr'
brew 'jq'
brew 'nodenv'
brew 'postgresql'
brew 'pre-commit'
brew 'shellcheck'
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ endif

.PHONY: check_go_version
check_go_version: .check_go_version.stamp ## Check that the correct Golang version is installed
.check_go_version.stamp: scripts/check-go-version .go-version
.check_go_version.stamp: scripts/check-go-version .tool-versions
scripts/check-go-version
touch .check_go_version.stamp

Expand All @@ -112,7 +112,7 @@ endif

.PHONY: check_node_version
check_node_version: .check_node_version.stamp ## Check that the correct Node version is installed
.check_node_version.stamp: scripts/check-node-version .node-version
.check_node_version.stamp: scripts/check-node-version .tool-versions
scripts/check-node-version
touch .check_node_version.stamp

Expand Down
55 changes: 15 additions & 40 deletions fresh-brew.local
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,28 @@ configure_shell_file_for_asdf() {
fi
}

install_go_with_asdf() {
go_version="$(cat < ".go-version")"
install_asdf_tools() {
go_version="$(awk '/golang/ { print $2 }' .tool-versions)"

if ! asdf_plugin_is_installed "golang"; then
fancy_echo "Adding golang plugin to asdf..."
asdf plugin add golang
install_go_version "$go_version"
else
fancy_echo "Updating asdf golang plugin..."
asdf plugin update golang
if ! golang_version_is_installed "$go_version"; then
install_go_version "$go_version"
fi
fi

if ! asdf_plugin_is_installed "nodejs"; then
fancy_echo "Adding nodejs plugin to asdf..."
asdf plugin add nodejs
else
fancy_echo "Updating asdf nodejs plugin..."
asdf plugin update nodejs
fi

fancy_echo "Installing asdf managed tools from .tool-versions..."
asdf install

fancy_echo "Setting global golang version to $go_version ..."
asdf global golang "$go_version"
}
Expand All @@ -35,38 +43,6 @@ asdf_plugin_is_installed() {
asdf plugin list -1 | grep -Fqx "$1"
}

install_go_version() {
fancy_echo "Installing golang version $1..."
asdf install golang "$1"
}

golang_version_is_installed() {
asdf list golang -1 | grep -Fqx "$1"
}

install_node_with_nodenv() {
node_version="$(cat < ".node-version")"

fancy_echo "Installing node $node_version ..."
if nodenv versions | grep "$node_version"; then
fancy_echo "node $node_version already installed."
else
brew upgrade node-build
nodenv install "$node_version"
fi
fancy_echo "Configuring Nodenv..."
configure_shell_file_for_nodenv
}

configure_shell_file_for_nodenv() {
if [[ $SHELL == *fish ]]; then
append_to_file "$shell_file" 'status --is-interactive; and source (nodenv init -|psub)'
else
# shellcheck disable=SC2016
append_to_file "$shell_file" 'eval "$(nodenv init -)"'
fi
}

configure_shell_file_for_gopath() {
if [[ $SHELL == *fish ]]; then
append_to_file "$shell_file" "set -x GOPATH (go env GOPATH)"
Expand Down Expand Up @@ -126,8 +102,7 @@ EOF
fi

configure_shell_file_for_asdf
install_go_with_asdf
install_node_with_nodenv
install_asdf_tools
configure_shell_file_for_gopath
# make sure that any functions that write to the shell file appear before this
# direnv function below because the direnv line has to be at the very end of the
Expand Down
16 changes: 16 additions & 0 deletions pkg/factory/mto_service_item_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,14 @@ func BuildDestSITServiceItems(db *pop.Connection, move models.Move, shipment mod
Reason: &reason,
},
},
{
Model: models.Address{},
Type: &Addresses.SITDestinationFinalAddress,
},
{
Model: models.Address{},
Type: &Addresses.SITDestinationOriginalAddress,
},
}, nil)

ddsfsc := BuildRealMTOServiceItemWithAllDeps(db, models.ReServiceCodeDDSFSC, move, shipment, []Customization{
Expand All @@ -796,6 +804,14 @@ func BuildDestSITServiceItems(db *pop.Connection, move models.Move, shipment mod
Reason: &reason,
},
},
{
Model: models.Address{},
Type: &Addresses.SITDestinationFinalAddress,
},
{
Model: models.Address{},
Type: &Addresses.SITDestinationOriginalAddress,
},
}, nil)
return []models.MTOServiceItem{ddfsit, ddasit, dddsit, ddsfsc}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func applyMinimum(code models.ReServiceCode, shipmentType models.MTOShipmentType
models.ReServiceCodeDDASIT,
models.ReServiceCodeDOPSIT,
models.ReServiceCodeDDDSIT,
models.ReServiceCodeDDSFSC,
models.ReServiceCodeDPK,
models.ReServiceCodeDNPK,
models.ReServiceCodeDUPK,
Expand Down
8 changes: 8 additions & 0 deletions pkg/services/ghc_rate_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,11 @@ type DomesticDestinationSITDeliveryPricer interface {
Price(appCtx appcontext.AppContext, contractCode string, requestedPickupDate time.Time, weight unit.Pound, serviceArea string, sitSchedule int, zipDest string, zipSITDest string, distance unit.Miles) (unit.Cents, PricingDisplayParams, error)
ParamsPricer
}

// DomesticDestinationSITFuelSurchargePricer prices domestic destination SIT fuel surcharge
//
//go:generate mockery --name DomesticDestinationSITFuelSurchargePricer
type DomesticDestinationSITFuelSurchargePricer interface {
Price(appCtx appcontext.AppContext, actualPickupDate time.Time, distance unit.Miles, weight unit.Pound, fscWeightBasedDistanceMultiplier float64, eiaFuelPrice unit.Millicents, isPPM bool) (unit.Cents, PricingDisplayParams, error)
ParamsPricer
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package ghcrateengine

import (
"database/sql"
"fmt"
"math"
"time"

"github.com/gofrs/uuid"
"github.com/pkg/errors"

"github.com/transcom/mymove/pkg/appcontext"
"github.com/transcom/mymove/pkg/apperror"
"github.com/transcom/mymove/pkg/models"
"github.com/transcom/mymove/pkg/services"
"github.com/transcom/mymove/pkg/unit"
)

type domesticDestinationSITFuelSurchargePricer struct {
}

func NewDomesticDestinationSITFuelSurchargePricer() services.DomesticDestinationSITFuelSurchargePricer {
return &domesticDestinationSITFuelSurchargePricer{}
}

func (p domesticDestinationSITFuelSurchargePricer) Price(_ appcontext.AppContext, actualPickupDate time.Time, distance unit.Miles, weight unit.Pound, fscWeightBasedDistanceMultiplier float64, eiaFuelPrice unit.Millicents, isPPM bool) (unit.Cents, services.PricingDisplayParams, error) {
// Validate parameters
if actualPickupDate.IsZero() {
return 0, nil, errors.New("ActualPickupDate is required")
}
if distance <= 0 {
return 0, nil, errors.New("Distance must be greater than 0")
}
if !isPPM && weight < minDomesticWeight {
return 0, nil, fmt.Errorf("Weight must be a minimum of %d", minDomesticWeight)
}
if fscWeightBasedDistanceMultiplier == 0 {
return 0, nil, errors.New("WeightBasedDistanceMultiplier is required")
}
if eiaFuelPrice == 0 {
return 0, nil, errors.New("EIAFuelPrice is required")
}

fscPriceDifferenceInCents := (eiaFuelPrice - baseGHCDieselFuelPrice).Float64() / 1000.0
fscMultiplier := fscWeightBasedDistanceMultiplier * distance.Float64()
fscPrice := fscMultiplier * fscPriceDifferenceInCents * 100
totalCost := unit.Cents(math.Round(fscPrice))

displayParams := services.PricingDisplayParams{
{Key: models.ServiceItemParamNameFSCPriceDifferenceInCents, Value: FormatFloat(fscPriceDifferenceInCents, 1)},
{Key: models.ServiceItemParamNameFSCMultiplier, Value: FormatFloat(fscMultiplier, 7)},
}

return totalCost, displayParams, nil
}

func (p domesticDestinationSITFuelSurchargePricer) PriceUsingParams(appCtx appcontext.AppContext, params models.PaymentServiceItemParams) (unit.Cents, services.PricingDisplayParams, error) {
actualPickupDate, err := getParamTime(params, models.ServiceItemParamNameActualPickupDate)
if err != nil {
return unit.Cents(0), nil, err
}

var paymentServiceItem models.PaymentServiceItem
mtoShipment := params[0].PaymentServiceItem.MTOServiceItem.MTOShipment

if mtoShipment.ID == uuid.Nil {
err = appCtx.DB().Eager("MTOServiceItem", "MTOServiceItem.MTOShipment").Find(&paymentServiceItem, params[0].PaymentServiceItemID)
if err != nil {
switch err {
case sql.ErrNoRows:
return unit.Cents(0), nil, apperror.NewNotFoundError(params[0].PaymentServiceItemID, "looking for PaymentServiceItem")
default:
return unit.Cents(0), nil, apperror.NewQueryError("PaymentServiceItem", err, "")
}
}
mtoShipment = paymentServiceItem.MTOServiceItem.MTOShipment
}

distance, err := getParamInt(params, models.ServiceItemParamNameDistanceZipSITDest)
if err != nil {
return unit.Cents(0), nil, err
}

weightBilled, err := getParamInt(params, models.ServiceItemParamNameWeightBilled)
if err != nil {
return unit.Cents(0), nil, err
}

fscWeightBasedDistanceMultiplier, err := getParamFloat(params, models.ServiceItemParamNameFSCWeightBasedDistanceMultiplier)
if err != nil {
return unit.Cents(0), nil, err
}

eiaFuelPrice, err := getParamInt(params, models.ServiceItemParamNameEIAFuelPrice)
if err != nil {
return unit.Cents(0), nil, err
}

var isPPM = false
if params[0].PaymentServiceItem.MTOServiceItem.MTOShipment.ShipmentType == models.MTOShipmentTypePPM {
// PPMs do not require minimums for a shipment's weight
// this flag is passed into the Price function to ensure the weight min
// are not enforced for PPMs
isPPM = true
}

return p.Price(appCtx, actualPickupDate, unit.Miles(distance), unit.Pound(weightBilled), fscWeightBasedDistanceMultiplier, unit.Millicents(eiaFuelPrice), isPPM)
}
Loading

0 comments on commit 0967560

Please sign in to comment.