Class: Decidim::Budgets::Order
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Budgets::Order
- Includes:
- HasFeature
- Defined in:
- decidim-budgets/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.
-
#maximum_budget ⇒ Object
Public: Returns the required maximum budget to checkout.
-
#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
46 47 48 |
# File 'decidim-budgets/app/models/decidim/budgets/order.rb', line 46 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
41 42 43 |
# File 'decidim-budgets/app/models/decidim/budgets/order.rb', line 41 def can_checkout? total_budget.to_f >= minimum_budget end |
#checked_out? ⇒ Boolean
Public: Returns true if the order has been checked out
36 37 38 |
# File 'decidim-budgets/app/models/decidim/budgets/order.rb', line 36 def checked_out? checked_out_at.present? end |
#maximum_budget ⇒ Object
Public: Returns the required maximum budget to checkout
57 58 59 60 |
# File 'decidim-budgets/app/models/decidim/budgets/order.rb', line 57 def maximum_budget return 0 unless feature feature.settings.total_budget.to_f end |
#minimum_budget ⇒ Object
Public: Returns the required minimum budget to checkout
51 52 53 54 |
# File 'decidim-budgets/app/models/decidim/budgets/order.rb', line 51 def minimum_budget return 0 unless feature 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
31 32 33 |
# File 'decidim-budgets/app/models/decidim/budgets/order.rb', line 31 def total_budget projects.to_a.sum(&:budget) end |