mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-29 18:52:22 +01:00
notify admins when no accounting period closed for 1 year
This commit is contained in:
parent
ccd63ecfe1
commit
7b0824a4a3
@ -36,7 +36,7 @@ class AccountingPeriod < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def archive_folder
|
||||
dir = 'accounting'
|
||||
dir = "accounting/#{id}"
|
||||
|
||||
# create directory if it doesn't exists (accounting)
|
||||
FileUtils.mkdir_p dir
|
||||
@ -48,7 +48,7 @@ class AccountingPeriod < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def archive_json_file
|
||||
"#{archive_folder}/#{start_at.iso8601}_#{end_at.iso8601}.json"
|
||||
"#{start_at.iso8601}_#{end_at.iso8601}.json"
|
||||
end
|
||||
|
||||
def check_footprint
|
||||
|
@ -43,6 +43,7 @@ class NotificationType
|
||||
notify_member_about_coupon
|
||||
notify_member_reservation_reminder
|
||||
notify_admin_free_disk_space
|
||||
notify_admin_close_period_reminder
|
||||
]
|
||||
# deprecated:
|
||||
# - notify_member_subscribed_plan_is_changed
|
||||
|
@ -0,0 +1,7 @@
|
||||
json.title notification.notification_type
|
||||
if notification.attached_object.class.name == AccountingPeriod.name
|
||||
json.description t('warning_last_closed_period_over_1_year', LAST_END: notification.attached_object.end_at)
|
||||
else
|
||||
json.description t('warning_no_closed_periods', FIRST_DATE: notification.attached_object.created_at.to_date)
|
||||
end
|
||||
json.url notification_url(notification, format: :json)
|
@ -0,0 +1,8 @@
|
||||
<%= render 'notifications_mailer/shared/hello', recipient: @recipient %>
|
||||
|
||||
<% if @attached_object.class.name == AccountingPeriod.name %>
|
||||
<p><%= t('.body.warning_last_closed_period_over_1_year', LAST_END: @attached_object.end_at) %></p>
|
||||
<% else %>
|
||||
<p><%= t('.body.warning_no_closed_periods', FIRST_DATE: @attached_object.created_at.to_date) %></p>
|
||||
<% end %>
|
||||
|
12
app/workers/close_period_reminder_worker.rb
Normal file
12
app/workers/close_period_reminder_worker.rb
Normal file
@ -0,0 +1,12 @@
|
||||
class ClosePeriodReminderWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
def perform
|
||||
last_period = AccountingPeriod.order(closed_at: :desc).limit(1).last
|
||||
return if Invoice.count == 0 || (last_period && last_period.end_at > (Time.current - 1.year))
|
||||
|
||||
NotificationCenter.call type: 'notify_admin_close_period_reminder',
|
||||
receiver: User.admins,
|
||||
attached_object: last_period || Invoice.order(:created_at).first
|
||||
end
|
||||
end
|
@ -311,6 +311,9 @@ en:
|
||||
enjoy_a_discount_of_AMOUNT_with_code_CODE: "Enjoy a discount of %{AMOUNT} with code %{CODE}"
|
||||
notify_admin_free_disk_space:
|
||||
warning_disk_space_under_threshold: "Warning: the server's available disk space is now %{AVAILABLE} MiB"
|
||||
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}"
|
||||
|
||||
statistics:
|
||||
# statistics tools for admins
|
||||
|
@ -311,6 +311,9 @@ es:
|
||||
enjoy_a_discount_of_AMOUNT_with_code_CODE: "Disfruta de un descuento de %{AMOUNT} con el código %{CODE}"
|
||||
notify_admin_free_disk_space:
|
||||
warning_disk_space_under_threshold: "Warning: the server's available disk space is now %{AVAILABLE} MiB" # missing translation
|
||||
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
|
||||
|
||||
statistics:
|
||||
# statistics tools for admins
|
||||
|
@ -311,6 +311,9 @@ fr:
|
||||
enjoy_a_discount_of_AMOUNT_with_code_CODE: "Bénéficiez d'une remise de %{AMOUNT} avec le code %{CODE}"
|
||||
notify_admin_free_disk_space:
|
||||
warning_disk_space_under_threshold: "Attention: l'espace disque disponible sur le serveur est désormais de %{AVAILABLE} MiO"
|
||||
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}"
|
||||
|
||||
statistics:
|
||||
# outil de statistiques pour les administrateurs
|
||||
|
@ -280,5 +280,11 @@ en:
|
||||
subject: "Low disk space"
|
||||
body: "Warning: available disk space on the server hosting fab-manager is less than %{THRESHOLD} MiB. This can affect its operation and prevent saving some data. Currently, %{AVAILABLE} MiB of free disk space remains available on the mount point."
|
||||
|
||||
notify_admin_close_period_reminder:
|
||||
subject: "Remind to close your accounting periods"
|
||||
body:
|
||||
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}."
|
||||
|
||||
shared:
|
||||
hello: "Hello %{user_name}"
|
||||
|
@ -279,5 +279,11 @@ es:
|
||||
subject: "Low disk space"
|
||||
body: "Warning: available disk space on the server hosting fab-manager is less than %{THRESHOLD} MiB. This can affect its operation and prevent saving some data. Currently, %{AVAILABLE} MiB of free disk space remains available on the mount point."
|
||||
|
||||
notify_admin_close_period_reminder: #translation_missing
|
||||
subject: "Remind to close your accounting periods"
|
||||
body:
|
||||
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}."
|
||||
|
||||
shared:
|
||||
hello: "¡Hola %{user_name}!"
|
||||
|
@ -280,6 +280,11 @@ fr:
|
||||
subject: "Espace disque faible"
|
||||
body: "Attention : l'espace disque disponible sur le serveur hébergeant fab-manager est inférieur à %{THRESHOLD} MiO. Cela peut nuire à son bon fonctionnement et empêcher la sauvegarde de certaines données. Actuellement, il reste %{AVAILABLE} MiO d'espace libre sur le point de montage."
|
||||
|
||||
notify_admin_close_period_reminder:
|
||||
subject: "Pensez à clôturer vos périodes comptables"
|
||||
body:
|
||||
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}."
|
||||
|
||||
shared:
|
||||
hello: "Bonjour %{user_name}"
|
||||
|
@ -280,5 +280,11 @@ pt:
|
||||
subject: "Low disk space"
|
||||
body: "Warning: available disk space on the server hosting fab-manager is less than %{THRESHOLD} MiB. This can affect its operation and prevent saving some data. Currently, %{AVAILABLE} MiB of free disk space remains available on the mount point."
|
||||
|
||||
notify_admin_close_period_reminder: #translation_missing
|
||||
subject: "Remind to close your accounting periods"
|
||||
body:
|
||||
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}."
|
||||
|
||||
shared:
|
||||
hello: "Olá %{user_name}"
|
||||
|
@ -311,6 +311,9 @@ pt:
|
||||
enjoy_a_discount_of_AMOUNT_with_code_CODE: "Desfrute de um desconto de %{AMOUNT} com o código %{CODE}"
|
||||
notify_admin_free_disk_space:
|
||||
warning_disk_space_under_threshold: "Warning: the server's available disk space is now %{AVAILABLE} MiB" # missing translation
|
||||
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
|
||||
|
||||
statistics:
|
||||
# statistics tools for admins
|
||||
|
@ -24,6 +24,11 @@ reservation_reminder:
|
||||
class: "ReservationReminderWorker"
|
||||
queue: default
|
||||
|
||||
close_period_reminder_worker:
|
||||
cron: "0 12 * * 1" # every monday at 12pm
|
||||
class: "ClosePeriodReminderWorker"
|
||||
queue: default
|
||||
|
||||
free_disk_space:
|
||||
cron: "0 5 * * 0" # every sunday at 5am
|
||||
class: "FreeDiskSpaceWorker"
|
||||
|
@ -35,7 +35,7 @@ class AccountingPeriodTest < ActionDispatch::IntegrationTest
|
||||
# Extract archive
|
||||
require 'tmpdir'
|
||||
require 'fileutils'
|
||||
dest = "#{Dir.tmpdir}/#{accounting_period.archive_file[0..-5]}"
|
||||
dest = "#{Dir.tmpdir}/accounting/#{accounting_period.id}"
|
||||
FileUtils.mkdir_p "#{dest}/accounting"
|
||||
Zip::File.open(accounting_period.archive_file) do |zip_file|
|
||||
# Handle entries one by one
|
||||
@ -63,8 +63,9 @@ class AccountingPeriodTest < ActionDispatch::IntegrationTest
|
||||
require 'version'
|
||||
assert_equal Version.current, archive_json['software']['version']
|
||||
|
||||
# we clean up the extraction dir before quitting
|
||||
# we clean up the files before quitting
|
||||
FileUtils.rm_rf(dest)
|
||||
FileUtils.rm_rf(accounting_period.archive_folder)
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user