Class: Decidim::Budgets::Order
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Budgets::Order
- Includes:
- DataPortability, HasComponent, NewsletterParticipant
- 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
- .export_serializer ⇒ Object
- .newsletter_participant_ids(component) ⇒ Object
- .user_collection(user) ⇒ Object
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
71 72 73 |
# File 'app/models/decidim/budgets/order.rb', line 71 def self.export_serializer Decidim::Budgets::DataPortabilityBudgetsOrderSerializer end |
.newsletter_participant_ids(component) ⇒ Object
75 76 77 78 79 |
# File 'app/models/decidim/budgets/order.rb', line 75 def self.(component) Decidim::Budgets::Order.where(component: component).joins(:component) .finished .pluck(:decidim_user_id).flatten.compact.uniq end |
.user_collection(user) ⇒ Object
67 68 69 |
# File 'app/models/decidim/budgets/order.rb', line 67 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
49 50 51 |
# File 'app/models/decidim/budgets/order.rb', line 49 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
44 45 46 |
# File 'app/models/decidim/budgets/order.rb', line 44 def can_checkout? total_budget.to_f >= minimum_budget end |
#checked_out? ⇒ Boolean
Public: Returns true if the order has been checked out
39 40 41 |
# File 'app/models/decidim/budgets/order.rb', line 39 def checked_out? checked_out_at.present? end |
#maximum_budget ⇒ Object
Public: Returns the required maximum budget to checkout
61 62 63 64 65 |
# File 'app/models/decidim/budgets/order.rb', line 61 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
54 55 56 57 58 |
# File 'app/models/decidim/budgets/order.rb', line 54 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
34 35 36 |
# File 'app/models/decidim/budgets/order.rb', line 34 def total_budget projects.to_a.sum(&:budget) end |