diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cde57d63..df4d3f16d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## next release +- Fix a bug: New groups does not have their spaces prices initialized +- Fix a bug: Unable to delete a group when its space prices are set +- [TODO DEPLOY] `rake fablab:fix:new_group_space_prices` only if module 'Spaces' is/was enabled ## v2.5.4 2017 May 4 diff --git a/app/models/group.rb b/app/models/group.rb index 6167bd327..ed1ddc1c4 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -3,6 +3,7 @@ class Group < ActiveRecord::Base has_many :users has_many :trainings_pricings, dependent: :destroy has_many :machines_prices, ->{ where(priceable_type: 'Machine') }, class_name: 'Price', dependent: :destroy + has_many :spaces_prices, ->{ where(priceable_type: 'Space') }, class_name: 'Price', dependent: :destroy extend FriendlyId friendly_id :name, use: :slugged @@ -21,6 +22,7 @@ class Group < ActiveRecord::Base def create_prices create_trainings_pricings create_machines_prices + create_spaces_prices end def create_trainings_pricings @@ -35,6 +37,12 @@ class Group < ActiveRecord::Base end end + def create_spaces_prices + Space.all.each do |space| + Price.create(priceable: space, group: self, amount: 0) + end + end + def create_statistic_subtype user_index = StatisticIndex.find_by(es_type_key: 'user') StatisticSubType.create!({statistic_types: user_index.statistic_types, key: self.slug, label: self.name}) diff --git a/lib/tasks/fablab/fix.rake b/lib/tasks/fablab/fix.rake index cc35f5c0b..aff34d4e1 100644 --- a/lib/tasks/fablab/fix.rake +++ b/lib/tasks/fablab/fix.rake @@ -35,5 +35,17 @@ namespace :fablab do end end end + + task new_group_space_prices: :environment do + Space.all.each do |space| + Group.all.each do |group| + begin + Price.find(priceable: space, group: group) + rescue ActiveRecord::RecordNotFound + Price.create(priceable: space, group: group, amount: 0) + end + end + end + end end end