1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-20 14:54:15 +01:00

(bug) unable to update an event category

This commit is contained in:
Sylvain 2023-01-09 09:24:11 +01:00
parent b14329497b
commit d191712ec0
2 changed files with 5 additions and 6 deletions

View File

@ -3,6 +3,7 @@
- Improved fix_invoice_item task
- Fix a bug: cryptic error message when failed to create a manager
- Fix a bug: unable to restore accounting periods closed by a deleted admin
- Fix a bug: unable to udpate an event category
## v5.6.1 2023 January 6

View File

@ -12,17 +12,15 @@ class Category < ApplicationRecord
after_update :update_statistic_subtype, if: :saved_change_to_name?
after_destroy :remove_statistic_subtype
def create_statistic_subtype
index = StatisticIndex.where(es_type_key: 'event')
StatisticSubType.create!(statistic_types: index.first.statistic_types, key: slug, label: name)
index = StatisticIndex.find_by(es_type_key: 'event')
StatisticSubType.create!(statistic_types: index.statistic_types, key: slug, label: name)
end
def update_statistic_subtype
index = StatisticIndex.where(es_type_key: 'event')
index = StatisticIndex.find_by(es_type_key: 'event')
subtype = StatisticSubType.joins(statistic_type_sub_types: :statistic_type)
.where(key: slug, statistic_types: { statistic_index_id: index.first.id })
.first
.find_by(key: previous_changes[:name][0], statistic_types: { statistic_index_id: index.id })
subtype.label = name
subtype.save!
end