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

v2.21.0 #116

Merged
merged 9 commits into from
May 13, 2022
Merged
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: ruby
rvm:
- 2.5.3
- 2.7.6
services:
- mysql
branches:
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/scenarios_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ScenariosController < OrganizationAwareController
#
#-----------------------------------------------------------------------------
def index
@fy_year = allowed_params[:fy_year] || current_fiscal_year_year
@fy_year = allowed_params[:fy_year] || current_planning_year_year
@scenarios = Scenario.where(fy_year: @fy_year, organization: current_user.viewable_organizations).order(created_at: :desc)

respond_to do |format|
Expand Down
18 changes: 18 additions & 0 deletions app/models/scenario.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class Scenario < ApplicationRecord
#Formatting i.e. fiscal year
include TransamFormatHelper

#------------------------------------------------------------------------------
# Callbacks
#------------------------------------------------------------------------------
after_initialize :set_defaults

# List of hash parameters allowed by the controller
FORM_PARAMS = [
:organization_id,
Expand Down Expand Up @@ -468,4 +473,17 @@ def self.current_fiscal_year_year
SystemConfig.instance.fy_year
end

#------------------------------------------------------------------------------
#
# Protected Methods
#
#------------------------------------------------------------------------------
protected

# Set resonable defaults for a new scenario
def set_defaults
self.fy_year ||= current_planning_year_year
self.ending_fy_year ||= current_planning_year_year
self.reviewer_organization ||= Organization.find_by(organization_type: OrganizationType.where(name: 'Grantor'))
end
end
31 changes: 19 additions & 12 deletions app/services/capital_project_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,15 @@ def post_build_clean_up organization
#########################################
# Scenario Work
#########################################
@scenario.draft_project_phases.each do |phase|
phase.set_estimated_cost
end
# If we're coming in from some route other than `build`, such as `update_asset_schedule`, then @scenario will be nil
if @scenario
@scenario.draft_project_phases.each do |phase|
phase.set_estimated_cost
end

@scenario.draft_projects.each do |project|
project.set_project_number
@scenario.draft_projects.each do |project|
project.set_project_number
end
end
#########################################
##########################################
Expand Down Expand Up @@ -520,7 +523,7 @@ def process_asset(asset, start_year, last_year, replacement_project_type, rehabi
# Adds an asset to a capital project. If the project does not
# exist it is created first. Future projects are projects generated by a
# replacement of a replacement or rehab of a replacement -- these are dependent
# on the first event happening so are kept seperate and are not editab;e
# on the first event happening so are kept seperate and are not editable
#-----------------------------------------------------------------------------
def add_to_project(organization, asset, ali_code, year, project_type, sogr=true, notional=false, fuel_type_id=nil)
Rails.logger.debug "add_to_project: asset=#{asset} ali_code=#{ali_code} year=#{year} project_type=#{project_type}"
Expand All @@ -536,7 +539,8 @@ def add_to_project(organization, asset, ali_code, year, project_type, sogr=true,
transit_asset = asset.transit_asset
end

if transit_asset.id.in? @scenario.draft_project_phase_assets.pluck(:transit_asset_id)
# If we're coming in from some route other than `build`, such as `update_asset_schedule`, then @scenario will be nil
if @scenario && transit_asset.id.in?(@scenario.draft_project_phase_assets.pluck(:transit_asset_id))
return [nil, nil]
end
else
Expand All @@ -562,12 +566,15 @@ def add_to_project(organization, asset, ali_code, year, project_type, sogr=true,
#########################################
# Scenario Work (Create Draft Project)
#########################################
if asset.fuel_type_id.present?
phase = @scenario.draft_project_phases.where(team_ali_code: ali_code, fy_year: year, fuel_type: asset.fuel_type).first
else
phase = @scenario.draft_project_phases.where(team_ali_code: ali_code, fy_year: year).first
# If we're coming in from some route other than `build`, such as `update_asset_schedule`, then @scenario will be nil
if @scenario
if asset.fuel_type_id.present?
phase = @scenario.draft_project_phases.where(team_ali_code: ali_code, fy_year: year, fuel_type: asset.fuel_type).first
else
phase = @scenario.draft_project_phases.where(team_ali_code: ali_code, fy_year: year).first
end
end

if phase.nil?

#We don't have a phase. let's create a new project and a new phase for this asset
Expand Down
1 change: 1 addition & 0 deletions app/views/scenarios/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
=f.input :ending_fy_year, :collection => @fiscal_years, :include_blank => false, :label => "Ending Fiscal Year"
=f.input :description
=f.input :organization_id, collection: @organizations.collect { |o| [o.name, o.id] }
=f.input :reviewer_organization, as: :hidden
=f.submit 'Save', class: 'btn btn-primary'
2 changes: 1 addition & 1 deletion lib/transam_cpt/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module TransamCpt
VERSION = "2.20.0"
VERSION = "2.21.0"
end
Loading