Class: Decidim::Budgets::Order
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Budgets::Order
- Includes:
- DataPortability, HasComponent
- 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 component and contains a collection of projects
Class Method Summary collapse
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.
Class Method Details
.export_serializer ⇒ Object
68 69 70 |
# File 'app/models/decidim/budgets/order.rb', line 68 def self.export_serializer Decidim::Budgets::DataPortabilityBudgetsOrderSerializer end |
.user_collection(user) ⇒ Object
64 65 66 |
# File 'app/models/decidim/budgets/order.rb', line 64 def self.user_collection(user) where(decidim_user_id: user.id) end |
Instance Method Details
#budget_percent ⇒ Object
Public: Returns the order budget percent from the settings total budget
48 49 50 |
# File 'app/models/decidim/budgets/order.rb', line 48 def budget_percent (total_budget.to_f / component.settings.total_budget.to_f) * 100 end |
#can_checkout? ⇒ Boolean
Public: Check if the order total budget is enough to checkout
43 44 45 |
# File 'app/models/decidim/budgets/order.rb', line 43 def can_checkout? total_budget.to_f >= minimum_budget end |
#checked_out? ⇒ Boolean
Public: Returns true if the order has been checked out
38 39 40 |
# File 'app/models/decidim/budgets/order.rb', line 38 def checked_out? checked_out_at.present? end |
#maximum_budget ⇒ Object
Public: Returns the required maximum budget to checkout
59 60 61 62 |
# File 'app/models/decidim/budgets/order.rb', line 59 def maximum_budget return 0 unless component component.settings.total_budget.to_f end |
#minimum_budget ⇒ Object
Public: Returns the required minimum budget to checkout
53 54 55 56 |
# File 'app/models/decidim/budgets/order.rb', line 53 def minimum_budget return 0 unless component component.settings.total_budget.to_f * (component.settings.vote_threshold_percent.to_f / 100) end |
#total_budget ⇒ Object
Public: Returns the sum of project budgets
33 34 35 |
# File 'app/models/decidim/budgets/order.rb', line 33 def total_budget projects.to_a.sum(&:budget) end |