From c786ba6edb4196802d45f24bfa70d64e8fc58937 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Thu, 4 Apr 2019 11:37:23 +0200 Subject: [PATCH] notify user about archiving --- app/models/accounting_period.rb | 2 +- app/models/notification_type.rb | 1 + .../_notify_admin_archive_complete.json.jbuilder | 7 +++++++ .../notify_admin_archive_complete.html.erb | 12 ++++++++++++ app/workers/archive_worker.rb | 2 +- config/locales/app.admin.en.yml | 2 +- config/locales/app.admin.es.yml | 2 +- config/locales/app.admin.fr.yml | 2 +- config/locales/app.admin.pt.yml | 2 +- config/locales/en.yml | 2 ++ config/locales/es.yml | 2 ++ config/locales/fr.yml | 2 ++ config/locales/mails.en.yml | 8 ++++++++ config/locales/mails.es.yml | 8 ++++++++ config/locales/mails.fr.yml | 8 ++++++++ config/locales/mails.pt.yml | 8 ++++++++ config/locales/pt.yml | 2 ++ 17 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 app/views/api/notifications/_notify_admin_archive_complete.json.jbuilder create mode 100644 app/views/notifications_mailer/notify_admin_archive_complete.html.erb diff --git a/app/models/accounting_period.rb b/app/models/accounting_period.rb index 9a43a55d2..85ff371a2 100644 --- a/app/models/accounting_period.rb +++ b/app/models/accounting_period.rb @@ -10,7 +10,7 @@ class AccountingPeriod < ActiveRecord::Base before_destroy { false } before_update { false } before_create :compute_totals - after_create :archive_closed_data + after_commit :archive_closed_data, on: [:create] validates :start_at, :end_at, :closed_at, :closed_by, presence: true validates_with DateRangeValidator diff --git a/app/models/notification_type.rb b/app/models/notification_type.rb index 200cbf65e..19ea34456 100644 --- a/app/models/notification_type.rb +++ b/app/models/notification_type.rb @@ -44,6 +44,7 @@ class NotificationType notify_member_reservation_reminder notify_admin_free_disk_space notify_admin_close_period_reminder + notify_admin_archive_complete ] # deprecated: # - notify_member_subscribed_plan_is_changed diff --git a/app/views/api/notifications/_notify_admin_archive_complete.json.jbuilder b/app/views/api/notifications/_notify_admin_archive_complete.json.jbuilder new file mode 100644 index 000000000..aa1677d2d --- /dev/null +++ b/app/views/api/notifications/_notify_admin_archive_complete.json.jbuilder @@ -0,0 +1,7 @@ +json.title notification.notification_type +json.description t('.archive_complete', + START: notification.attached_object.start_at, + END: notification.attached_object.end_at, + ID: notification.attached_object.id + ) +json.url notification_url(notification, format: :json) diff --git a/app/views/notifications_mailer/notify_admin_archive_complete.html.erb b/app/views/notifications_mailer/notify_admin_archive_complete.html.erb new file mode 100644 index 000000000..98f0520b7 --- /dev/null +++ b/app/views/notifications_mailer/notify_admin_archive_complete.html.erb @@ -0,0 +1,12 @@ +<%= render 'notifications_mailer/shared/hello', recipient: @recipient %> + +

+ <%= t('.body.archive_complete', START: @attached_object.start_at, END: @attached_object.end_at) %> +

+

+ <%= t('.body.click_to_download') %> + <%=link_to( t('.body.here'), "#{root_url}api/accounting_periods/#{@attached_object.id}/archive", target: "_blank" )%> +

+

+ <%= t('.body.save_on_secured') %> +

diff --git a/app/workers/archive_worker.rb b/app/workers/archive_worker.rb index 6058aea18..8dc432b8a 100644 --- a/app/workers/archive_worker.rb +++ b/app/workers/archive_worker.rb @@ -26,7 +26,7 @@ class ArchiveWorker end NotificationCenter.call type: :notify_admin_archive_complete, - receiver: period.closed_by, + receiver: User.find(period.closed_by), attached_object: period end diff --git a/config/locales/app.admin.en.yml b/config/locales/app.admin.en.yml index c9dee138c..a28e3906e 100644 --- a/config/locales/app.admin.en.yml +++ b/config/locales/app.admin.en.yml @@ -424,7 +424,7 @@ en: confirm_close_START_END: "Do you really want to close the accounting period between {{START}} and {{END}}? Any subsequent changes will be impossible." period_must_match_fiscal_year: "A closing must occur at the end of a minimum annual period, or per financial year when it is not calendar-based." this_may_take_a_while: "This operation will take some time to complete." - period_START_END_closed_success: "The accounting period from {{START}} to {{END}} has been successfully closed" + period_START_END_closed_success: "The accounting period from {{START}} to {{END}} has been successfully closed. Archive generation is running, you'll be notified when it's done." failed_to_close_period: "An error occurred, unable to close the accounting period" no_periods: "No closings for now" diff --git a/config/locales/app.admin.es.yml b/config/locales/app.admin.es.yml index 825a1dfdb..d6ca06265 100644 --- a/config/locales/app.admin.es.yml +++ b/config/locales/app.admin.es.yml @@ -424,7 +424,7 @@ es: confirm_close_START_END: "Do you really want to close the accounting period between {{START}} and {{END}}? Any subsequent changes will be impossible." # translation_missing period_must_match_fiscal_year: "A closing must occur at the end of a minimum annual period, or per financial year when it is not calendar-based." # translation_missing this_may_take_a_while: "This operation will take some time to complete." # translation_missing - period_START_END_closed_success: "The accounting period from {{START}} to {{END}} has been successfully closed" # translation_missing + period_START_END_closed_success: "The accounting period from {{START}} to {{END}} has been successfully closed. Archive generation is running, you'll be notified when it's done." # translation_missing failed_to_close_period: "An error occurred, unable to close the accounting period" # translation_missing no_periods: "No closings for now" # translation_missing diff --git a/config/locales/app.admin.fr.yml b/config/locales/app.admin.fr.yml index d04470e92..09397b687 100644 --- a/config/locales/app.admin.fr.yml +++ b/config/locales/app.admin.fr.yml @@ -424,7 +424,7 @@ fr: confirm_close_START_END: "Êtes-vous sur de vouloir clôturer la période comptable du {{START}} au {{END}} ? Toute modification ultérieure sera impossible." period_must_match_fiscal_year: "Une clôture doit intervenir à l'issue d'une période au minimum annuelle, ou par exercice lorsque celui-ci n'est pas calé sur l'année civile." this_may_take_a_while: "Cette opération va prendre un certain temps." - period_START_END_closed_success: "La période comptable du {{START}} au {{END}} a bien été clôturée" + period_START_END_closed_success: "La période comptable du {{START}} au {{END}} a bien été clôturée. La génération de l'archive est en cours, vous serez prévenu lorsque celle-ci sera terminée." failed_to_close_period: "Une erreur est survenue, impossible de clôturer la période comptable" no_periods: "Aucune clôture pour le moment" diff --git a/config/locales/app.admin.pt.yml b/config/locales/app.admin.pt.yml index 6291094bf..101dd0c3e 100755 --- a/config/locales/app.admin.pt.yml +++ b/config/locales/app.admin.pt.yml @@ -424,7 +424,7 @@ pt: confirm_close_START_END: "Do you really want to close the accounting period between {{START}} and {{END}}? Any subsequent changes will be impossible" # translation_missing period_must_match_fiscal_year: "A closing must occur at the end of a minimum annual period, or per financial year when it is not calendar-based." # translation_missing this_may_take_a_while: "This operation will take some time to complete." # translation_missing - period_START_END_closed_success: "The accounting period from {{START}} to {{END}} has been successfully closed" # translation_missing + period_START_END_closed_success: "The accounting period from {{START}} to {{END}} has been successfully closed. Archive generation is running, you'll be notified when it's done." # translation_missing failed_to_close_period: "An error occurred, unable to close the accounting period" # translation_missing no_periods: "No closings for now" # translation_missing diff --git a/config/locales/en.yml b/config/locales/en.yml index fe0045b6b..bbe5d44e8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -316,6 +316,8 @@ en: notify_admin_close_period_reminder: warning_last_closed_period_over_1_year: "Please remind to periodically close your accounting periods. Last closed period ended at %{LAST_END}" warning_no_closed_periods: "Please remind to periodically close your accounting periods. You have to close periods from %{FIRST_DATE}" + notify_admin_archive_complete: + archive_complete: "Data archiving from %{START} to %{END} is done. click here to download. Remember to save it on an external secured media." statistics: # statistics tools for admins diff --git a/config/locales/es.yml b/config/locales/es.yml index 337f91cc3..2f8159387 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -316,6 +316,8 @@ es: notify_admin_close_period_reminder: warning_last_closed_period_over_1_year: "Please remind to periodically close your accounting periods. Last closed period ended at %{LAST_END}" # missing translation warning_no_closed_periods: "Please remind to periodically close your accounting periods. You have to close periods from %{FIRST_DATE}" # missing translation + notify_admin_archive_complete: # missing translation + archive_complete: "Data archiving from %{START} to %{END} is done. click here to download. Remember to save it on an external secured media." # missing translation statistics: # statistics tools for admins diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 53416ccca..7f6aabbef 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -316,6 +316,8 @@ fr: notify_admin_close_period_reminder: warning_last_closed_period_over_1_year: "Pensez à clôturer régulièrement vos périodes comptables. Les comptes sont actuellement clôturés jusqu'au %{LAST_END}" warning_no_closed_periods: "Pensez à clôturer régulièrement vos périodes comptables. Vous devez clôturer des périodes depuis le %{FIRST_DATE}" + notify_admin_archive_complete: + archive_complete: "L'archivage des données du %{START} au %{END} est terminé. Cliquez ici pour la télécharger. Pensez à l'enregistrer sur un support externe sécurisé." statistics: # outil de statistiques pour les administrateurs diff --git a/config/locales/mails.en.yml b/config/locales/mails.en.yml index 580c74eab..cb7befdd0 100644 --- a/config/locales/mails.en.yml +++ b/config/locales/mails.en.yml @@ -286,5 +286,13 @@ en: warning_last_closed_period_over_1_year: "Please remind to periodically close your accounting periods. Last closed period ended at %{LAST_END}." warning_no_closed_periods: "Please remind to periodically close your accounting periods. You have to close periods from %{FIRST_DATE}." + notify_admin_archive_complete: + subject: "Archiving completed" + body: + archive_complete: "You have closed the accounting period from %{START} to %{END}. Archiving of data is now complete." + click_to_download: "To download the ZIP archive, click" + here: "here." + save_on_secured: "Remember that you must save this archive on a secured external support, which may be requested by the tax authorities during a check." + shared: hello: "Hello %{user_name}" diff --git a/config/locales/mails.es.yml b/config/locales/mails.es.yml index 5605007a1..2c7bf207d 100644 --- a/config/locales/mails.es.yml +++ b/config/locales/mails.es.yml @@ -285,5 +285,13 @@ es: warning_last_closed_period_over_1_year: "Please remind to periodically close your accounting periods. Last closed period ended at %{LAST_END}." warning_no_closed_periods: "Please remind to periodically close your accounting periods. You have to close periods from %{FIRST_DATE}." + notify_admin_archive_complete: #translation_missing + subject: "Archiving completed" + body: + archive_complete: "You have closed the accounting period from %{START} to %{END}. Archiving of data is now complete." + click_to_download: "To download the ZIP archive, click" + here: "here." + save_on_secured: "Remember that you must save this archive on a secured external support, which may be requested by the tax authorities during a check." + shared: hello: "¡Hola %{user_name}!" diff --git a/config/locales/mails.fr.yml b/config/locales/mails.fr.yml index 25a85599b..6bd198b2e 100644 --- a/config/locales/mails.fr.yml +++ b/config/locales/mails.fr.yml @@ -286,5 +286,13 @@ fr: warning_last_closed_period_over_1_year: "Pensez à clôturer régulièrement vos périodes comptables. Les comptes sont actuellement clôturés jusqu'au %{LAST_END}." warning_no_closed_periods: "Pensez à clôturer régulièrement vos périodes comptables. Vous devez clôturer des périodes depuis le %{FIRST_DATE}." + notify_admin_archive_complete: + subject: "Archivage terminé" + body: + archive_complete: "Vous avez clôturé la période comptable du %{START} au %{END}. L'archivage des données est maintenant terminé." + click_to_download: "Pour télécharger l'archive ZIP, cliquez" + here: "ici." + save_on_secured: "N'oubliez pas que vous devez obligatoirement enregistrer cette archive sur un support externe sécurisé, qui peut vous être demandé par l'administration fiscale lors d'un contrôle." + shared: hello: "Bonjour %{user_name}" diff --git a/config/locales/mails.pt.yml b/config/locales/mails.pt.yml index 26df865fa..18ae430c5 100755 --- a/config/locales/mails.pt.yml +++ b/config/locales/mails.pt.yml @@ -286,5 +286,13 @@ pt: warning_last_closed_period_over_1_year: "Please remind to periodically close your accounting periods. Last closed period ended at %{LAST_END}." warning_no_closed_periods: "Please remind to periodically close your accounting periods. You have to close periods from %{FIRST_DATE}." + notify_admin_archive_complete: #translation_missing + subject: "Archiving completed" + body: + archive_complete: "You have closed the accounting period from %{START} to %{END}. Archiving of data is now complete." + click_to_download: "To download the ZIP archive, click" + here: "here." + save_on_secured: "Remember that you must save this archive on a secured external support, which may be requested by the tax authorities during a check." + shared: hello: "Olá %{user_name}" diff --git a/config/locales/pt.yml b/config/locales/pt.yml index f7f45fd37..a6b0c4fd2 100755 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -316,6 +316,8 @@ pt: notify_admin_close_period_reminder: warning_last_closed_period_over_1_year: "Please remind to periodically close your accounting periods. Last closed period ended at %{LAST_END}" # missing translation warning_no_closed_periods: "Please remind to periodically close your accounting periods. You have to close periods from %{FIRST_DATE}" # missing translation + notify_admin_archive_complete: # missing translation + archive_complete: "Data archiving from %{START} to %{END} is done. click here to download. Remember to save it on an external secured media." # missing translation statistics: # statistics tools for admins