1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-26 20:54:21 +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

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

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

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

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

@ -19,11 +19,11 @@ class Events::AsUserTest < ActionDispatch::IntegrationTest
wallet_transactions_count = WalletTransaction.count wallet_transactions_count = WalletTransaction.count
# Enable the VAT at 19.6% # 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.value = 'true'
vat_active.save! 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.value = '19.6'
vat_rate.save! vat_rate.save!

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