diff --git a/.fabmanager-version b/.fabmanager-version index fe16b348d..0cadbc1e3 100644 --- a/.fabmanager-version +++ b/.fabmanager-version @@ -1 +1 @@ -2.5.4 +2.5.5 diff --git a/CHANGELOG.md b/CHANGELOG.md index a561254e0..c00b1b210 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog Fab Manager +## v2.5.5 2017 May 15 + +- 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 - Fix a bug: Unable to define application locale other than `fr` or `en`. 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