Class: Decidim::Budgets::Order

Inherits:
ApplicationRecord show all
Includes:
HasFeature
Defined in:
app/models/decidim/budgets/order.rb

Overview

The data store for a Order in the Decidim::Budgets component. It is unique for each user and feature and contains a collection of projects

Instance Method Summary collapse

Instance Method Details

#budget_percentObject

Public: Returns the order budget percent from the settings total budget



35
36
37
# File 'app/models/decidim/budgets/order.rb', line 35

def budget_percent
  (total_budget.to_f / feature.settings.total_budget.to_f) * 100
end

#can_checkout?Boolean

Public: Check if the order total budget is enough to checkout

Returns:

  • (Boolean)


30
31
32
# File 'app/models/decidim/budgets/order.rb', line 30

def can_checkout?
  total_budget.to_f >= minimum_budget
end

#checked_out?Boolean

Public: Returns true if the order has been checked out

Returns:

  • (Boolean)


25
26
27
# File 'app/models/decidim/budgets/order.rb', line 25

def checked_out?
  checked_out_at.present?
end

#minimum_budgetObject

Public: Returns the required minimum budget to checkout



40
41
42
# File 'app/models/decidim/budgets/order.rb', line 40

def minimum_budget
  feature.settings.total_budget.to_f * (feature.settings.vote_threshold_percent.to_f / 100)
end

#total_budgetObject

Public: Returns the sum of project budgets



20
21
22
# File 'app/models/decidim/budgets/order.rb', line 20

def total_budget
  @total_budget ||= projects.sum(&:budget)
end