Allow editing the name of budget phases

Co-authored-by: decabeza <alberto@decabeza.es>
This commit is contained in:
Julian Herrero
2020-03-16 12:54:00 +01:00
committed by Javi Martín
parent d20e521ee9
commit 909071c48b
17 changed files with 146 additions and 11 deletions

View File

@@ -42,4 +42,27 @@ namespace :budgets do
end
end
end
desc "Add name to existing budget phases"
task add_name_to_existing_phases: :environment do
ApplicationLogger.new.info "Adding names to budgets phases"
Budget::Phase.find_each do |phase|
if phase.translations.present?
phase.translations.each do |translation|
unless translation.name.present?
if I18n.available_locales.include? translation.locale
locale = translation.locale
else
locale = I18n.default_locale
end
translation.update!(name: I18n.t("budgets.phase.#{phase.kind}", locale: locale))
end
end
else
phase.translations.create!(name: I18n.t("budgets.phase.#{phase.kind}"), locale: I18n.default_locale)
end
end
end
end