Merge pull request #2296 from consul/feature/2278#budget_price_show_phase

New Budget's phase to publish investment prices
This commit is contained in:
BertoCQ
2018-01-10 23:46:41 +01:00
committed by GitHub
11 changed files with 167 additions and 43 deletions

View File

@@ -3,8 +3,11 @@ class Budget < ActiveRecord::Base
include Measurable
include Sluggable
PHASES = %w(drafting accepting reviewing selecting valuating balloting
reviewing_ballots finished).freeze
PHASES = %w(drafting accepting reviewing selecting valuating publishing_prices
balloting reviewing_ballots finished).freeze
ON_HOLD_PHASES = %w(reviewing valuating publishing_prices reviewing_ballots).freeze
PUBLISHED_PRICES_PHASES = %w(publishing_prices balloting reviewing_ballots finished).freeze
CURRENCY_SYMBOLS = %w(€ $ £ ¥).freeze
validates :name, presence: true, uniqueness: true
@@ -19,17 +22,18 @@ class Budget < ActiveRecord::Base
before_validation :sanitize_descriptions
scope :on_hold, -> { where(phase: %w(reviewing valuating reviewing_ballots")) }
scope :drafting, -> { where(phase: "drafting") }
scope :on_hold, -> { where(phase: ON_HOLD_PHASES) }
scope :drafting, -> { where(phase: "drafting") }
scope :accepting, -> { where(phase: "accepting") }
scope :reviewing, -> { where(phase: "reviewing") }
scope :selecting, -> { where(phase: "selecting") }
scope :valuating, -> { where(phase: "valuating") }
scope :publishing_prices, -> { where(phase: "publishing_prices") }
scope :balloting, -> { where(phase: "balloting") }
scope :reviewing_ballots, -> { where(phase: "reviewing_ballots") }
scope :finished, -> { where(phase: "finished") }
scope :finished, -> { where(phase: "finished") }
scope :current, -> { where.not(phase: "finished") }
scope :current, -> { where.not(phase: "finished") }
def description
send("description_#{phase}").try(:html_safe)
@@ -63,6 +67,10 @@ class Budget < ActiveRecord::Base
phase == "valuating"
end
def publishing_prices?
phase == "publishing_prices"
end
def balloting?
phase == "balloting"
end
@@ -75,6 +83,10 @@ class Budget < ActiveRecord::Base
phase == "finished"
end
def published_prices?
PUBLISHED_PRICES_PHASES.include?(phase)
end
def balloting_process?
balloting? || reviewing_ballots?
end
@@ -84,7 +96,7 @@ class Budget < ActiveRecord::Base
end
def on_hold?
reviewing? || valuating? || reviewing_ballots?
ON_HOLD_PHASES.include?(phase)
end
def current?
@@ -118,7 +130,7 @@ class Budget < ActiveRecord::Base
case phase
when 'accepting', 'reviewing'
%w{random}
when 'balloting', 'reviewing_ballots'
when 'publishing_prices', 'balloting', 'reviewing_ballots'
%w{random price}
else
%w{random confidence_score}

View File

@@ -240,15 +240,11 @@ class Budget
end
def should_show_price?
feasible? &&
selected? &&
(budget.reviewing_ballots? || budget.finished?)
selected? && price.present? && budget.published_prices?
end
def should_show_price_info?
feasible? &&
price_explanation.present? &&
(budget.balloting? || budget.reviewing_ballots? || budget.finished?)
def should_show_price_explanation?
should_show_price? && price_explanation.present?
end
def formatted_price

View File

@@ -71,7 +71,7 @@
<p><%= investment.unfeasibility_explanation %></p>
<% end %>
<% if investment.should_show_price_info? %>
<% if investment.should_show_price_explanation? %>
<h2><%= t('budgets.investments.show.price_explanation') %></h2>
<p><%= investment.price_explanation %></p>
<% end %>