diff --git a/CHANGELOG.md b/CHANGELOG.md index deb153c68..6c3e2650c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - Ability to configure and export the accounting data to the ACD accounting software - Compute the VAT per item in each invoices, instead of globally - Fix a bug: invoices with total = 0, are marked as paid on site even if paid by card +- Fix a bug: after disabling a group, its associated plans are hidden from the interface - Fix a bug: in case of unexpected server error during stripe payment process, the confirm button is not unlocked - [TODO DEPLOY] `rake db:migrate` diff --git a/app/assets/templates/admin/pricing/subscriptions.html.erb b/app/assets/templates/admin/pricing/subscriptions.html.erb index 602176e08..bcb98f4bc 100644 --- a/app/assets/templates/admin/pricing/subscriptions.html.erb +++ b/app/assets/templates/admin/pricing/subscriptions.html.erb @@ -36,8 +36,7 @@ + ng-init="group = getGroupFromId(groups, plan.group_id)"> {{getPlanType(plan.type)}} {{plan.base_name}} {{ plan.interval | planIntervalFilter:plan.interval_count }} @@ -47,4 +46,4 @@ - \ No newline at end of file + diff --git a/app/models/group.rb b/app/models/group.rb index ee2abfaad..3b7414441 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -1,3 +1,6 @@ +# frozen_string_literal: true + +# Group is way to bind users with prices. Different prices can be defined for each plan/reservable, for each group class Group < ActiveRecord::Base has_many :plans has_many :users @@ -12,15 +15,21 @@ class Group < ActiveRecord::Base friendly_id :name, use: :slugged validates :name, :slug, presence: true + validates :disabled, inclusion: { in: [false] }, if: :group_has_users? after_create :create_prices after_create :create_statistic_subtype after_update :update_statistic_subtype, if: :name_changed? + after_update :disable_plans, if: :disabled_changed? def destroyable? users.empty? and plans.empty? end + def group_has_users? + users.count.positive? + end + private def create_prices @@ -60,4 +69,10 @@ class Group < ActiveRecord::Base subtype.label = name subtype.save! end + + def disable_plans + plans.each do |plan| + plan.update_attributes(disabled: disabled) + end + end end diff --git a/app/models/plan.rb b/app/models/plan.rb index 42ba0aca8..5ede79990 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -53,13 +53,13 @@ class Plan < ActiveRecord::Base def create_machines_prices Machine.all.each do |machine| - Price.create(priceable: machine, plan: self, group_id: self.group_id, amount: 0) + Price.create(priceable: machine, plan: self, group_id: group_id, amount: 0) end end def create_spaces_prices Space.all.each do |space| - Price.create(priceable: space, plan: self, group_id: self.group_id, amount: 0) + Price.create(priceable: space, plan: self, group_id: group_id, amount: 0) end end