mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-17 06:52:27 +01:00
[bug] price init for new groups & delete group
This commit is contained in:
parent
5fcc36e959
commit
b403f86187
@ -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
|
||||
|
||||
|
@ -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})
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user