This commit is contained in:
rgarcia
2018-02-09 22:08:52 +01:00
parent 2d3c4e1fbd
commit 00c965b715
31 changed files with 206 additions and 158 deletions

View File

@@ -4,6 +4,7 @@ module Abilities
def initialize(user)
valuator = user.valuator
can [:read, :update, :valuate], SpendingProposal
can [:read, :update, :comment_valuation], Budget::Investment, id: valuator.investment_ids + valuator.valuator_group.investment_ids
can [:valuate], Budget::Investment, { id: valuator.investment_ids + valuator.valuator_group.investment_ids, valuation_finished: false }

View File

@@ -62,9 +62,9 @@ class Budget
scope :valuation_open, -> { where(valuation_finished: false) }
scope :without_admin, -> { valuation_open.where(administrator_id: nil) }
scope :without_valuator, -> { valuation_open.where(valuator_assignments_count: 0) }
scope :under_valuation, -> { valuation_open.where("valuator_assignments_count > 0 AND administrator_id IS NOT ?", nil) }
scope :under_valuation, -> { valuation_open.valuating.where("administrator_id IS NOT ?", nil) }
scope :managed, -> { valuation_open.where(valuator_assignments_count: 0).where("administrator_id IS NOT ?", nil) }
scope :valuating, -> { valuation_open.where("valuator_assignments_count > 0") }
scope :valuating, -> { valuation_open.where("valuator_assignments_count > 0 OR valuator_group_assignments_count > 0" ) }
scope :valuation_finished, -> { where(valuation_finished: true) }
scope :valuation_finished_feasible, -> { where(valuation_finished: true, feasibility: "feasible") }
scope :feasible, -> { where(feasibility: "feasible") }

View File

@@ -1,6 +1,6 @@
class Budget
class ValuatorGroupAssignment < ActiveRecord::Base
belongs_to :valuator_group
belongs_to :investment
belongs_to :valuator_group, counter_cache: :budget_investments_count
belongs_to :investment, counter_cache: true
end
end

View File

@@ -18,4 +18,9 @@ class Valuator < ActiveRecord::Base
def description_or_name
description.present? ? description : name
end
def assigned_investment_ids
investment_ids + [valuator_group.try(:investment_ids)].flatten
end
end