Refactor concept of current budget

When there was only one budget this implementation worked fine

Nowadays there can be multiple budgets, and therefore the definition of
the current_budget has changed. It is no longer a budget that has not
finished, but rather, the last budget created that is not in the
initial drafting phase.

Budgets in the drafting phase are not considered the current_budget,
but rather a budget that is still being prepared and that soon will
become the current_budget
This commit is contained in:
rgarcia
2018-01-15 18:37:03 +01:00
parent 77e10ac297
commit 9176de949a
2 changed files with 28 additions and 5 deletions

View File

@@ -31,7 +31,9 @@ class Budget < ActiveRecord::Base
scope :reviewing_ballots, -> { where(phase: "reviewing_ballots") }
scope :finished, -> { where(phase: "finished") }
scope :current, -> { where.not(phase: "finished") }
def self.current
where.not(phase: "drafting").last
end
def description
send("description_#{phase}").try(:html_safe)
@@ -93,10 +95,6 @@ class Budget < ActiveRecord::Base
balloting_process? || finished?
end
def current?
!finished?
end
def heading_price(heading)
heading_ids.include?(heading.id) ? heading.price : -1
end