1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-18 07:52:23 +01:00

(style) replace Setting.find_by(name... by Setting.get

This commit is contained in:
Sylvain 2022-03-23 13:30:55 +01:00
parent 2fcda8a0ce
commit ee97b93a49
6 changed files with 32 additions and 30 deletions

View File

@ -25,7 +25,7 @@ class PDF::Invoice < Prawn::Document
)
# logo
img_b64 = Setting.find_by(name: 'invoice_logo')
img_b64 = Setting.get('invoice_logo')
begin
image StringIO.new(Base64.decode64(img_b64.value)), fit: [415, 40]
rescue StandardError => e

View File

@ -28,7 +28,7 @@ class PDF::PaymentSchedule < Prawn::Document
)
# logo
img_b64 = Setting.find_by(name: 'invoice_logo')
img_b64 = Setting.get('invoice_logo')
begin
image StringIO.new(Base64.decode64(img_b64.value)), fit: [415, 40]
rescue StandardError => e

View File

@ -207,35 +207,35 @@ class AccountingExportService
def account(invoice, account, type: :code, means: :other)
case account
when :projets
Setting.find_by(name: "accounting_#{means}_client_#{type}")&.value
Setting.get("accounting_#{means}_client_#{type}")
when :vat
Setting.find_by(name: "accounting_VAT_#{type}")&.value
Setting.get("accounting_VAT_#{type}")
when :subscription
if invoice.subscription_invoice?
Setting.find_by(name: "accounting_subscription_#{type}")&.value
Setting.get("accounting_subscription_#{type}")
else
puts "WARN: Invoice #{invoice.id} has no subscription"
end
when :reservation
if invoice.main_item.object_type == 'Reservation'
Setting.find_by(name: "accounting_#{invoice.main_item.object.reservable_type}_#{type}")&.value
Setting.get("accounting_#{invoice.main_item.object.reservable_type}_#{type}")
else
puts "WARN: Invoice #{invoice.id} has no reservation"
end
when :wallet
if invoice.main_item.object_type == 'WalletTransaction'
Setting.find_by(name: "accounting_wallet_#{type}")&.value
Setting.get("accounting_wallet_#{type}")
else
puts "WARN: Invoice #{invoice.id} is not a wallet credit"
end
when :pack
if invoice.main_item.object_type == 'StatisticProfilePrepaidPack'
Setting.find_by(name: "accounting_Pack_#{type}")&.value
Setting.get("accounting_Pack_#{type}")
else
puts "WARN: Invoice #{invoice.id} has no prepaid-pack"
end
when :error
Setting.find_by(name: "accounting_Error_#{type}")&.value
Setting.get("accounting_Error_#{type}")
else
puts "Unsupported account #{account}"
end || ''

View File

@ -1,3 +1,6 @@
# frozen_string_literal: true
# Send a reminder email to the user who has made a reservation
class ReservationReminderWorker
include Sidekiq::Worker
@ -5,25 +8,24 @@ class ReservationReminderWorker
DEFAULT_REMINDER_DELAY = 24.hours
def perform
enabled = Setting.find_by(name: 'reminder_enable').try(:value)
if enabled == 'true'
delay = Setting.find_by(name: 'reminder_delay').try(:value).try(:to_i).try(:hours) || DEFAULT_REMINDER_DELAY
return unless Setting.get('reminder_enable')
starting = DateTime.current.beginning_of_hour + delay
ending = starting + 1.hour
delay = Setting.find_by(name: 'reminder_delay').try(:value).try(:to_i).try(:hours) || DEFAULT_REMINDER_DELAY
Reservation.joins(:slots).where('slots.start_at >= ? AND slots.start_at <= ? AND slots.canceled_at IS NULL', starting, ending).each do |r|
already_sent = Notification.where(
attached_object_type: Reservation.name,
attached_object_id: r.id,
notification_type_id: NotificationType.find_by_name('notify_member_reservation_reminder')
).count
unless already_sent > 0
NotificationCenter.call type: 'notify_member_reservation_reminder',
receiver: r.user,
attached_object: r
end
end
starting = DateTime.current.beginning_of_hour + delay
ending = starting + 1.hour
Reservation.joins(:slots).where('slots.start_at >= ? AND slots.start_at <= ? AND slots.canceled_at IS NULL', starting, ending).each do |r|
already_sent = Notification.where(
attached_object_type: Reservation.name,
attached_object_id: r.id,
notification_type_id: NotificationType.find_by_name('notify_member_reservation_reminder')
).count
next if already_sent.positive?
NotificationCenter.call type: 'notify_member_reservation_reminder',
receiver: r.user,
attached_object: r
end
end
end
end

View File

@ -19,11 +19,11 @@ class Events::AsUserTest < ActionDispatch::IntegrationTest
wallet_transactions_count = WalletTransaction.count
# Enable the VAT at 19.6%
vat_active = Setting.find_by(name: 'invoice_VAT-active')
vat_active = Setting.get('invoice_VAT-active')
vat_active.value = 'true'
vat_active.save!
vat_rate = Setting.find_by(name: 'invoice_VAT-rate')
vat_rate = Setting.get('invoice_VAT-rate')
vat_rate.value = '19.6'
vat_rate.save!

View File

@ -22,7 +22,7 @@ class SettingsTest < ActionDispatch::IntegrationTest
assert_equal 'Test Fablab', resp[:setting][:value]
# Check record
setting = Setting.find_by_name(resp[:setting][:name])
setting = Setting.get(resp[:setting][:name])
assert_not_nil setting, 'setting was not found in database'
assert_equal 2, setting.history_values.count, 'all historical values were not found'
assert_includes setting.history_values.map(&:value), 'Fab Lab de La Casemate', 'previous parameter was not saved'