From 6aa3c0caebe52f7b60cfa300e5f534034b2a4275 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Mon, 9 Dec 2019 11:55:31 +0100 Subject: [PATCH] Notify all admins on the creation of a refund invoice --- CHANGELOG.md | 1 + app/models/avoir.rb | 10 ++++++++++ app/models/notification_type.rb | 1 + .../_notify_admin_refund_created.json.jbuilder | 5 +++++ .../notify_admin_refund_created.html.erb | 8 ++++++++ config/locales/en.yml | 3 +++ config/locales/es.yml | 3 +++ config/locales/fr.yml | 2 ++ config/locales/mails.en.yml | 6 ++++++ config/locales/mails.es.yml | 10 ++++++++-- config/locales/mails.fr.yml | 6 ++++++ config/locales/mails.pt.yml | 10 ++++++++-- config/locales/pt.yml | 6 ++++-- 13 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 app/views/api/notifications/_notify_admin_refund_created.json.jbuilder create mode 100644 app/views/notifications_mailer/notify_admin_refund_created.html.erb diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d8eb994f..61a9ec7e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Configuration of phone number in members registration forms: can be required or optional, depending on `PHONE_REQUIRED` configuration - Improved user experience in defining slots in the calendar management - Improved notification email to the member when a rolling subscription is taken +- Notify all admins on the creation of a refund invoice - Calendar management: improved legend display and visual behavior - Handle Ctrl^C in upgrade scripts - Updated moment-timezone diff --git a/app/models/avoir.rb b/app/models/avoir.rb index e8d6bd98f..641a80ce9 100644 --- a/app/models/avoir.rb +++ b/app/models/avoir.rb @@ -5,6 +5,8 @@ class Avoir < Invoice belongs_to :invoice + after_create :notify_admins_refund_created + validates :payment_method, inclusion: { in: %w[stripe cheque transfer none cash wallet] } attr_accessor :invoice_items_ids @@ -16,4 +18,12 @@ class Avoir < Invoice def expire_subscription user.subscription.expire(DateTime.current) end + + private + + def notify_admins_refund_created + NotificationCenter.call type: 'notify_admin_refund_created', + receiver: User.admins, + attached_object: self + end end diff --git a/app/models/notification_type.rb b/app/models/notification_type.rb index f73f76463..45efb7ae3 100644 --- a/app/models/notification_type.rb +++ b/app/models/notification_type.rb @@ -47,6 +47,7 @@ class NotificationType notify_admin_archive_complete notify_privacy_policy_changed notify_admin_import_complete + notify_admin_refund_created ] # deprecated: # - notify_member_subscribed_plan_is_changed diff --git a/app/views/api/notifications/_notify_admin_refund_created.json.jbuilder b/app/views/api/notifications/_notify_admin_refund_created.json.jbuilder new file mode 100644 index 000000000..17b8588de --- /dev/null +++ b/app/views/api/notifications/_notify_admin_refund_created.json.jbuilder @@ -0,0 +1,5 @@ +json.title notification.notification_type +json.description t('.refund_created', + AMOUNT: number_to_currency(notification.attached_object.total / 100.00), + USER: notification.attached_object.invoicing_profile&.full_name) +json.url notification_url(notification, format: :json) diff --git a/app/views/notifications_mailer/notify_admin_refund_created.html.erb b/app/views/notifications_mailer/notify_admin_refund_created.html.erb new file mode 100644 index 000000000..d0ec9e8ad --- /dev/null +++ b/app/views/notifications_mailer/notify_admin_refund_created.html.erb @@ -0,0 +1,8 @@ +<%= render 'notifications_mailer/shared/hello', recipient: @recipient %> + +

<%= t('.body.refund_created', + AMOUNT: number_to_currency(@attached_object.total / 100.00), + INVOICE: @attached_object.invoice.reference, + USER: @attached_object.invoicing_profile&.full_name) %> +

+

" target="_blank"><%= t('.body.download') %>

diff --git a/config/locales/en.yml b/config/locales/en.yml index 3868fd2c0..c54560d8d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -351,6 +351,9 @@ en: notify_privacy_policy_changed: policy_updated: "Privacy policy updated." click_to_show: "Click here to consult" + notify_admin_refund_created: + refund_created: "A refund of %{AMOUNT} has been created for user %{USER}" + statistics: # statistics tools for admins subscriptions: "Subscriptions" diff --git a/config/locales/es.yml b/config/locales/es.yml index d6eac0d60..05aefa471 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -351,6 +351,9 @@ es: notify_privacy_policy_changed: policy_updated: "Privacy policy updated." # missing translation click_to_show: "Click here to consult" # missing translation + notify_admin_refund_created: + refund_created: "A refund of %{AMOUNT} has been created for user %{USER}" # missing translation + statistics: # statistics tools for admins subscriptions: "Suscripciones" diff --git a/config/locales/fr.yml b/config/locales/fr.yml index fef290c6d..44585e45b 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -351,6 +351,8 @@ fr: notify_privacy_policy_changed: policy_updated: "Nouvelle mise à jour de la Politique de confidentialité." click_to_show: "Cliquez ici pour la consulter" + notify_admin_refund_created: + refund_created: "Un avoir de %{AMOUNT} a été généré pour l'utilisateur %{USER}" statistics: # outil de statistiques pour les administrateurs diff --git a/config/locales/mails.en.yml b/config/locales/mails.en.yml index a97595db0..1709f0226 100644 --- a/config/locales/mails.en.yml +++ b/config/locales/mails.en.yml @@ -313,5 +313,11 @@ en: content_html: "

We wish to inform you that we have just updated our privacy policy.

We may change our privacy policy regularly. In accordance with the regulations, you will receive a notification for each update.

By accessing or using our services after the privacy policy update, we will consider that you agree its terms, updates included.

" link_to_policy: "Cliquez ici pour consultez la politique de confidentialité." + notify_admin_refund_created: + subject: "A refund has been generated" + body: + refund_created: "A refund of %{AMOUNT} has been generated on invoice %{INVOICE} of user %{USER}" + download: "Click here to download this refund invoice" + shared: hello: "Hello %{user_name}" diff --git a/config/locales/mails.es.yml b/config/locales/mails.es.yml index edf65a3c0..4e3e70175 100644 --- a/config/locales/mails.es.yml +++ b/config/locales/mails.es.yml @@ -299,7 +299,7 @@ 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 + 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." @@ -307,11 +307,17 @@ es: 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." - notify_privacy_policy_changed: #translation_missing + notify_privacy_policy_changed: #translation_missing subject: "Privacy policy updated" body: content_html: "

We wish to inform you that we have just updated our privacy policy.

We may change our privacy policy regularly. In accordance with the regulations, you will receive a notification for each update.

By accessing or using our services after the privacy policy update, we will consider that you agree its terms, updates included.

" link_to_policy: "Cliquez ici pour consultez la politique de confidentialité." + notify_admin_refund_created: #translation_missing + subject: "A refund has been generated" + body: + refund_created: "A refund of %{AMOUNT} has been generated on invoice %{INVOICE} of user %{USER}" + download: "Click here to download this refund invoice" + shared: hello: "¡Hola %{user_name}!" diff --git a/config/locales/mails.fr.yml b/config/locales/mails.fr.yml index e4d0c2d1b..0c7fc4852 100644 --- a/config/locales/mails.fr.yml +++ b/config/locales/mails.fr.yml @@ -313,5 +313,11 @@ fr: content_html: "

Nous souhaitons vous signaler que nous venons de mettre à jour notre politique de confidentialité.

Nous pouvons apporter régulièrement des modifications à notre politique de confidentialité. Conformément à la réglementation, une notification vous sera envoyée à chaque mise à jour.

En accédant ou en utilisant nos services après la mise à jour de la Politique de confidentialité, nous considérerons que vous acceptez les termes de celle-ci, mises à jour comprises.

" link_to_policy: "Cliquez ici pour consultez la politique de confidentialité." + notify_admin_refund_created: + subject: "Un avoir a été généré" + body: + refund_created: "Un avoir de %{AMOUNT} a été généré sur la facture %{INVOICE} de l'utilisateur %{USER}" + download: "Cliquez ici pour télécharger cet avoir" + shared: hello: "Bonjour %{user_name}" diff --git a/config/locales/mails.pt.yml b/config/locales/mails.pt.yml index fee5cf5e6..32cbee51a 100755 --- a/config/locales/mails.pt.yml +++ b/config/locales/mails.pt.yml @@ -299,7 +299,7 @@ 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 + 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." @@ -307,11 +307,17 @@ pt: 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." - notify_privacy_policy_changed: #translation_missing + notify_privacy_policy_changed: #translation_missing subject: "Privacy policy updated" body: content_html: "

We wish to inform you that we have just updated our privacy policy.

We may change our privacy policy regularly. In accordance with the regulations, you will receive a notification for each update.

By accessing or using our services after the privacy policy update, we will consider that you agree its terms, updates included.

" link_to_policy: "Cliquez ici pour consultez la politique de confidentialité." + notify_admin_refund_created: #translation_missing + subject: "A refund has been generated" + body: + refund_created: "A refund of %{AMOUNT} has been generated on invoice %{INVOICE} of user %{USER}" + download: "Click here to download this refund invoice" + shared: hello: "Olá %{user_name}" diff --git a/config/locales/pt.yml b/config/locales/pt.yml index 4e71e1dde..b6ece70a6 100755 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -349,8 +349,10 @@ pt: 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 notify_privacy_policy_changed: - policy_updated: "Privacy policy updated." # missing translation - click_to_show: "Click here to consult" # missing translation + policy_updated: "Privacy policy updated." # missing translation + click_to_show: "Click here to consult" # missing translation + notify_admin_refund_created: + refund_created: "A refund of %{AMOUNT} has been created for user %{USER}" # missing translation statistics: # statistics tools for admins