Class: Decidim::Budgets::Order
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Budgets::Order
- 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
-
#budget_percent ⇒ Object
Public: Returns the order budget percent from the settings total budget.
-
#can_checkout? ⇒ Boolean
Public: Check if the order total budget is enough to checkout.
-
#checked_out? ⇒ Boolean
Public: Returns true if the order has been checked out.
-
#minimum_budget ⇒ Object
Public: Returns the required minimum budget to checkout.
-
#total_budget ⇒ Object
Public: Returns the sum of project budgets.
Instance Method Details
#budget_percent ⇒ Object
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
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
25 26 27 |
# File 'app/models/decidim/budgets/order.rb', line 25 def checked_out? checked_out_at.present? end |
#minimum_budget ⇒ Object
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_budget ⇒ Object
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 |