Skip to content
Draft
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
6 changes: 5 additions & 1 deletion app/models/dr_rai/action_plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class DrRai::ActionPlan < ApplicationRecord
belongs_to :dr_rai_target, class_name: "DrRai::Target"
belongs_to :region

validates :statement, presence: true
validates :statement, presence: true, if: :target_uses_statement?

def indicator
dr_rai_indicator
Expand Down Expand Up @@ -44,4 +44,8 @@ def unprocessible?
denominator.negative? ||
numerator.nil?
end

def target_uses_statement?
DrRai::Target::NEEDS_STATEMENT.include?(indicator.type)
end
end
2 changes: 1 addition & 1 deletion app/models/dr_rai/bp_fudging_indicator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def display_name
end

def target_type_frontend
"percent"
"boolean"
end

def numerator_key all: nil
Expand Down
2 changes: 2 additions & 0 deletions app/models/dr_rai/target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class DrRai::Target < ApplicationRecord
"boolean" => "DrRai::BooleanTarget"
}

NEEDS_STATEMENT = %w[ percent numeric ].map { |t| TYPES[t] }.freeze

belongs_to :indicator, class_name: "DrRai::Indicator", foreign_key: "dr_rai_indicators_id"

validates :period, presence: true, format: {with: /\AQ\d-\d{4}\Z/}
Expand Down