Skip to content

Commit

Permalink
Merge pull request #488 from Vizzuality/feat/cp_alignment_2027
Browse files Browse the repository at this point in the history
feat: Adding cp_alignment_2027 to company cp assessments
  • Loading branch information
martintomas committed Feb 2, 2024
2 parents 265802d + d5f4cd3 commit 0a3ca2e
Show file tree
Hide file tree
Showing 30 changed files with 360 additions and 262 deletions.
2 changes: 2 additions & 0 deletions app/admin/companies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,13 @@
row :publication_date
row :assessment_date
row :cp_alignment_2025
row :cp_alignment_2027
row :cp_alignment_2035
row :cp_alignment_2050
if a.region.present?
row :region
row :cp_regional_alignment_2025
row :cp_regional_alignment_2027
row :cp_regional_alignment_2035
row :cp_regional_alignment_2050
end
Expand Down
8 changes: 6 additions & 2 deletions app/admin/cp_assessments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
decorate_with CP::AssessmentDecorator

permit_params :sector_id, :assessment_date, :publication_date, :cp_assessmentable_id, :last_reported_year,
:assumptions, :cp_alignment_2025, :cp_alignment_2035, :cp_alignment_2050,
:region, :cp_regional_alignment_2025, :cp_regional_alignment_2035,
:assumptions, :cp_alignment_2025, :cp_alignment_2027, :cp_alignment_2035, :cp_alignment_2050,
:region, :cp_regional_alignment_2025, :cp_regional_alignment_2027, :cp_regional_alignment_2035,
:cp_regional_alignment_2050, :years_with_targets_string, :emissions,
cp_matrices_attributes: [:id, :portfolio, :cp_alignment_2025, :cp_alignment_2035, :cp_alignment_2050, :_destroy]

Expand Down Expand Up @@ -64,9 +64,11 @@
row :last_reported_year
row :cp_alignment_2050
row :cp_alignment_2025
row :cp_alignment_2027
row :cp_alignment_2035
row :region
row :cp_regional_alignment_2025
row :cp_regional_alignment_2027
row :cp_regional_alignment_2035
row :cp_regional_alignment_2050
row :years_with_targets
Expand Down Expand Up @@ -101,6 +103,7 @@
column :sector
column :cp_alignment_2050
column :cp_alignment_2025
column :cp_alignment_2027
column :cp_alignment_2035
column :assessment_date
column :publication_date
Expand Down Expand Up @@ -132,6 +135,7 @@

if params[:cp_assessmentable_type] == 'Company'
column :cp_alignment_2025
column :cp_alignment_2027
column :cp_alignment_2035
column :cp_alignment_2050
column :cp_regional_alignment_2025
Expand Down
4 changes: 2 additions & 2 deletions app/models/company.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class Company < ApplicationRecord

delegate :level, :status, :status_description_short,
to: :latest_mq_assessment, prefix: :mq, allow_nil: true
delegate :cp_alignment_2050, :cp_alignment_2025, :cp_alignment_2035,
:cp_regional_alignment_2050, :cp_regional_alignment_2025, :cp_regional_alignment_2035,
delegate :cp_alignment_2050, :cp_alignment_2025, :cp_alignment_2027, :cp_alignment_2035,
:cp_regional_alignment_2050, :cp_regional_alignment_2025, :cp_regional_alignment_2027, :cp_regional_alignment_2035,
to: :latest_cp_assessment, allow_nil: true

validates :ca100, inclusion: {in: [true, false]}
Expand Down
4 changes: 4 additions & 0 deletions app/models/cp/assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
# cp_assessmentable_id :bigint
# sector_id :bigint
# final_disclosure_year :integer
# cp_alignment_2027 :string
# cp_regional_alignment_2027 :string
#

module CP
Expand Down Expand Up @@ -59,9 +61,11 @@ class Assessment < ApplicationRecord

with_options allow_nil: true, allow_blank: true, inclusion: {in: CP::Alignment::ALLOWED_NAMES} do
validates :cp_alignment_2025
validates :cp_alignment_2027
validates :cp_alignment_2035
validates :cp_alignment_2050
validates :cp_regional_alignment_2025
validates :cp_regional_alignment_2027
validates :cp_regional_alignment_2035
validates :cp_regional_alignment_2050
end
Expand Down
19 changes: 10 additions & 9 deletions app/models/news_article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
#
# Table name: news_articles
#
# id :bigint not null, primary key
# title :string
# content :text
# publication_date :datetime
# created_by_id :bigint
# updated_by_id :bigint
# created_at :datetime not null
# updated_at :datetime not null
# is_insight :boolean default(FALSE)
# id :bigint not null, primary key
# title :string
# content :text
# publication_date :datetime
# created_by_id :bigint
# updated_by_id :bigint
# created_at :datetime not null
# updated_at :datetime not null
# is_insight :boolean default(FALSE)
# short_description :text
#

class NewsArticle < ApplicationRecord
Expand Down
12 changes: 12 additions & 0 deletions app/services/api/presenters/company.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ def cp_alignment_2025
CP::Alignment.new(name: @company.cp_alignment_2025, sector: @company.sector.name)
end

def cp_alignment_2027
return unless @company.cp_alignment_2027.present?

CP::Alignment.new(name: @company.cp_alignment_2027, sector: @company.sector.name)
end

def cp_alignment_2035
return unless @company.cp_alignment_2035.present?

Expand All @@ -58,6 +64,12 @@ def cp_regional_alignment_2025
CP::Alignment.new(name: @company.cp_regional_alignment_2025, sector: @company.sector.name)
end

def cp_regional_alignment_2027
return unless @company.cp_regional_alignment_2027.present?

CP::Alignment.new(name: @company.cp_regional_alignment_2027, sector: @company.sector.name)
end

def cp_regional_alignment_2035
return unless @company.cp_regional_alignment_2035.present?

Expand Down
2 changes: 2 additions & 0 deletions app/services/csv_export/user/company_cp_assessments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def call
'Publication Date',
'Assessment Date',
'Carbon Performance Alignment 2025',
'Carbon Performance Alignment 2027',
'Carbon Performance Alignment 2035',
'Carbon Performance Alignment 2050',
'Benchmark ID',
Expand Down Expand Up @@ -48,6 +49,7 @@ def call
assessment.publication_date,
assessment.assessment_date,
assessment.cp_alignment_2025,
assessment.cp_alignment_2027,
assessment.cp_alignment_2035,
assessment.cp_alignment_2050,
assessment.cp_benchmark_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def call
'Assessment Date',
'Region',
'Carbon Performance Regional Alignment 2025',
'Carbon Performance Regional Alignment 2027',
'Carbon Performance Regional Alignment 2035',
'Carbon Performance Regional Alignment 2050',
'Regional Benchmark ID',
Expand Down Expand Up @@ -52,6 +53,7 @@ def call
assessment.assessment_date,
assessment.region,
assessment.cp_regional_alignment_2025,
assessment.cp_regional_alignment_2027,
assessment.cp_regional_alignment_2035,
assessment.cp_regional_alignment_2050,
assessment.cp_regional_benchmark_id,
Expand Down
4 changes: 4 additions & 0 deletions app/services/csv_export/user/company_latest_assessments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ def call
'CP Assessment Date',
'Benchmark ID',
'Carbon Performance Alignment 2025',
'Carbon Performance Alignment 2027',
'Carbon Performance Alignment 2035',
'Carbon Performance Alignment 2050',
'Years with targets',
'Previous Carbon Performance Alignment 2025',
'Previous Carbon Performance Alignment 2027',
'Previous Carbon Performance Alignment 2035',
'Previous Carbon Performance Alignment 2050',
'Previous Years with targets',
Expand Down Expand Up @@ -74,10 +76,12 @@ def call
cp_assessment&.assessment_date,
cp_assessment&.cp_benchmark_id,
cp_assessment&.cp_alignment_2025,
cp_assessment&.cp_alignment_2027,
cp_assessment&.cp_alignment_2035,
cp_assessment&.cp_alignment_2050,
cp_assessment&.years_with_targets&.join(';'),
prev_cp_assessment&.cp_alignment_2025,
prev_cp_assessment&.cp_alignment_2027,
prev_cp_assessment&.cp_alignment_2035,
prev_cp_assessment&.cp_alignment_2050,
prev_cp_assessment&.years_with_targets&.join(';'),
Expand Down
4 changes: 4 additions & 0 deletions app/services/csv_import/company_cp_assessments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ def import
assessment.emissions = parse_emissions(row) if emission_headers?(row)
assessment.last_reported_year = row[:last_reported_year] if row.header?(:last_reported_year)
assessment.cp_alignment_2025 = CP::Alignment.format_name(row[:cp_alignment_2025]) if row.header?(:cp_alignment_2025)
assessment.cp_alignment_2027 = CP::Alignment.format_name(row[:cp_alignment_2027]) if row.header?(:cp_alignment_2027)
assessment.cp_alignment_2035 = CP::Alignment.format_name(row[:cp_alignment_2035]) if row.header?(:cp_alignment_2035)
assessment.cp_alignment_2050 = CP::Alignment.format_name(row[:cp_alignment_2050]) if row.header?(:cp_alignment_2050)
assessment.region = parse_cp_benchmark_region(row[:region]) if row.header?(:region)
if row.header?(:cp_regional_alignment_2025)
assessment.cp_regional_alignment_2025 = CP::Alignment.format_name(row[:cp_regional_alignment_2025])
end
if row.header?(:cp_regional_alignment_2027)
assessment.cp_regional_alignment_2027 = CP::Alignment.format_name(row[:cp_regional_alignment_2027])
end
if row.header?(:cp_regional_alignment_2035)
assessment.cp_regional_alignment_2035 = CP::Alignment.format_name(row[:cp_regional_alignment_2035])
end
Expand Down
2 changes: 2 additions & 0 deletions app/views/admin/cp_assessments/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
<%= f.input :last_reported_year %>
<%= f.input :assumptions %>
<%= f.input :cp_alignment_2025 %>
<%= f.input :cp_alignment_2027 %>
<%= f.input :cp_alignment_2035 %>
<%= f.input :cp_alignment_2050 %>
<%= f.input :region, as: :select, collection: CP::Assessment::REGIONS, required: false %>
<%= f.input :cp_regional_alignment_2025 %>
<%= f.input :cp_regional_alignment_2027 %>
<%= f.input :cp_regional_alignment_2035 %>
<%= f.input :cp_regional_alignment_2050 %>
<%= f.input :years_with_targets_string, label: 'Years with targets', as: :tags, hint: 'Type a year and press ENTER. Non integers will be rejected.' %>
Expand Down
12 changes: 10 additions & 2 deletions app/views/tpi/companies/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,23 @@
<div class="cp-alignments">
<% long_term_header = "Long-term<br/> alignment in #{@company.sector.name.downcase == 'electricity utilities' ? '2040-50' : '2050'}" %>
<%= render 'cp_alignment', header: 'Short-term<br/> alignment in 2025', alignment: @company_presenter.cp_alignment_2025 %>
<% if @company_presenter.cp_alignment_2027.present? %>
<%= render 'cp_alignment', header: 'Short-term<br/> alignment in 2027', alignment: @company_presenter.cp_alignment_2027 %>
<% else %>
<%= render 'cp_alignment', header: 'Short-term<br/> alignment in 2025', alignment: @company_presenter.cp_alignment_2025 %>
<% end %>
<%= render 'cp_alignment', header: 'Medium-term<br/> alignment in 2035', alignment: @company_presenter.cp_alignment_2035 %>
<%= render 'cp_alignment', header: long_term_header, alignment: @company_presenter.cp_alignment_2050 %>
</div>
<% else %>
<div class="cp-alignments">
<% long_term_header = "Long-term<br/> alignment in #{@company.sector.name.downcase == 'electricity utilities' ? '2040-50' : '2050'}" %>
<%= render 'cp_alignment', header: 'Short-term<br/> alignment in 2025', alignment: @company_presenter.cp_regional_alignment_2025 %>
<% if @company_presenter.cp_regional_alignment_2027.present? %>
<%= render 'cp_alignment', header: 'Short-term<br/> alignment in 2027', alignment: @company_presenter.cp_regional_alignment_2027 %>
<% else %>
<%= render 'cp_alignment', header: 'Short-term<br/> alignment in 2025', alignment: @company_presenter.cp_regional_alignment_2025 %>
<% end %>
<%= render 'cp_alignment', header: 'Medium-term<br/> alignment in 2035', alignment: @company_presenter.cp_regional_alignment_2035 %>
<%= render 'cp_alignment', header: long_term_header, alignment: @company_presenter.cp_regional_alignment_2050 %>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddCPAlignment2027ToCPAssessments < ActiveRecord::Migration[6.1]
def change
add_column :cp_assessments, :cp_alignment_2027, :string
add_column :cp_assessments, :cp_regional_alignment_2027, :string
end
end
Loading

0 comments on commit 0a3ca2e

Please sign in to comment.