mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-17 06:52:27 +01:00
replaces almost all Time.now by DateTime.current
This commit is contained in:
parent
90b3564138
commit
77cf8c8218
@ -14,7 +14,7 @@ class API::AccountingPeriodsController < API::ApiController
|
||||
|
||||
def create
|
||||
authorize AccountingPeriod
|
||||
@accounting_period = AccountingPeriod.new(period_params.merge(closed_at: DateTime.now, closed_by: current_user.id))
|
||||
@accounting_period = AccountingPeriod.new(period_params.merge(closed_at: DateTime.current, closed_by: current_user.id))
|
||||
if @accounting_period.save
|
||||
render :show, status: :created, location: @accounting_period
|
||||
else
|
||||
|
@ -17,11 +17,11 @@ class API::EventsController < API::ApiController
|
||||
if current_user&.admin?
|
||||
@events = case params[:scope]
|
||||
when 'future'
|
||||
@events.where('availabilities.start_at >= ?', Time.now).order('availabilities.start_at DESC')
|
||||
@events.where('availabilities.start_at >= ?', DateTime.current).order('availabilities.start_at DESC')
|
||||
when 'future_asc'
|
||||
@events.where('availabilities.start_at >= ?', Time.now).order('availabilities.start_at ASC')
|
||||
@events.where('availabilities.start_at >= ?', DateTime.current).order('availabilities.start_at ASC')
|
||||
when 'passed'
|
||||
@events.where('availabilities.start_at < ?', Time.now).order('availabilities.start_at DESC')
|
||||
@events.where('availabilities.start_at < ?', DateTime.current).order('availabilities.start_at DESC')
|
||||
else
|
||||
@events.order('availabilities.start_at DESC')
|
||||
end
|
||||
@ -36,7 +36,7 @@ class API::EventsController < API::ApiController
|
||||
limit = params[:limit]
|
||||
@events = Event.includes(:event_image, :event_files, :availability, :category)
|
||||
.where('events.nb_total_places != -1 OR events.nb_total_places IS NULL')
|
||||
.where('availabilities.start_at >= ?', Time.now)
|
||||
.where('availabilities.start_at >= ?', DateTime.current)
|
||||
.order('availabilities.start_at ASC').references(:availabilities)
|
||||
.limit(limit)
|
||||
end
|
||||
|
@ -6,7 +6,7 @@ class OpenAPI::V1::EventsController < OpenAPI::V1::BaseController
|
||||
|
||||
if upcoming
|
||||
@events = Event.includes(:event_image, :event_files, :availability, :category)
|
||||
.where('availabilities.end_at >= ?', Time.now)
|
||||
.where('availabilities.end_at >= ?', DateTime.current)
|
||||
.order('availabilities.start_at ASC').references(:availabilities)
|
||||
else
|
||||
@events = Event.includes(:event_image, :event_files, :availability, :category).order(created_at: :desc)
|
||||
|
@ -5,7 +5,7 @@ class Rss::EventsController < Rss::RssController
|
||||
|
||||
def index
|
||||
@events = Event.includes(:event_image, :event_files, :availability, :category)
|
||||
.where('availabilities.start_at >= ?', Time.now)
|
||||
.where('availabilities.start_at >= ?', DateTime.current)
|
||||
.order('availabilities.start_at ASC').references(:availabilities).limit(10)
|
||||
@fab_name = Setting.find_by(name: 'fablab_name').value
|
||||
end
|
||||
|
@ -14,6 +14,6 @@ class Avoir < Invoice
|
||||
end
|
||||
|
||||
def expire_subscription
|
||||
user.subscription.expire(Time.now)
|
||||
user.subscription.expire(DateTime.current)
|
||||
end
|
||||
end
|
||||
|
@ -17,7 +17,7 @@ class Coupon < ActiveRecord::Base
|
||||
validates_with CouponExpirationValidator
|
||||
|
||||
scope :disabled, -> { where(active: false) }
|
||||
scope :expired, -> { where('valid_until IS NOT NULL AND valid_until < ?', DateTime.now) }
|
||||
scope :expired, -> { where('valid_until IS NOT NULL AND valid_until < ?', DateTime.current) }
|
||||
scope :sold_out, lambda {
|
||||
joins(:invoices).select('coupons.*, COUNT(invoices.id) as invoices_count').group('coupons.id')
|
||||
.where.not(max_usages: nil).having('COUNT(invoices.id) >= coupons.max_usages')
|
||||
@ -26,7 +26,7 @@ class Coupon < ActiveRecord::Base
|
||||
joins('LEFT OUTER JOIN invoices ON invoices.coupon_id = coupons.id')
|
||||
.select('coupons.*, COUNT(invoices.id) as invoices_count')
|
||||
.group('coupons.id')
|
||||
.where('active = true AND (valid_until IS NULL OR valid_until >= ?)', DateTime.now)
|
||||
.where('active = true AND (valid_until IS NULL OR valid_until >= ?)', DateTime.current)
|
||||
.having('COUNT(invoices.id) < coupons.max_usages OR coupons.max_usages IS NULL')
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ class Coupon < ActiveRecord::Base
|
||||
def status(user_id = nil, amount = nil)
|
||||
if !active?
|
||||
'disabled'
|
||||
elsif !valid_until.nil? && valid_until.at_end_of_day < DateTime.now
|
||||
elsif !valid_until.nil? && valid_until.at_end_of_day < DateTime.current
|
||||
'expired'
|
||||
elsif !max_usages.nil? && invoices.count >= max_usages
|
||||
'sold_out'
|
||||
|
@ -37,7 +37,7 @@ class Event < ActiveRecord::Base
|
||||
|
||||
def recurrence_events
|
||||
Event.includes(:availability)
|
||||
.where('events.recurrence_id = ? AND events.id != ? AND availabilities.start_at >= ?', recurrence_id, id, Time.now)
|
||||
.where('events.recurrence_id = ? AND events.id != ? AND availabilities.start_at >= ?', recurrence_id, id, DateTime.current)
|
||||
.references(:availabilities)
|
||||
end
|
||||
|
||||
|
@ -151,7 +151,7 @@ class Project < ActiveRecord::Base
|
||||
def after_save_and_publish
|
||||
return unless state_changed? && published?
|
||||
|
||||
update_columns(published_at: Time.now)
|
||||
update_columns(published_at: DateTime.current)
|
||||
notify_admin_when_project_published
|
||||
end
|
||||
end
|
||||
|
@ -52,7 +52,7 @@ class Slot < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def can_be_modified?
|
||||
return false if (start_at - Time.now) / 1.day < 1
|
||||
return false if (start_at - DateTime.current) / 1.day < 1
|
||||
|
||||
true
|
||||
end
|
||||
|
@ -81,7 +81,7 @@ class Subscription < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def cancel
|
||||
update_columns(canceled_at: Time.now)
|
||||
update_columns(canceled_at: DateTime.current)
|
||||
end
|
||||
|
||||
def expire(time)
|
||||
@ -96,7 +96,7 @@ class Subscription < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def expired?
|
||||
expired_at <= Time.now
|
||||
expired_at <= DateTime.current
|
||||
end
|
||||
|
||||
def expired_at
|
||||
@ -179,7 +179,7 @@ class Subscription < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def set_expiration_date
|
||||
start_at = Time.now
|
||||
start_at = DateTime.current
|
||||
self.expiration_date = start_at + plan.duration
|
||||
end
|
||||
|
||||
|
@ -108,7 +108,7 @@ class User < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def subscribed_plan
|
||||
return nil if subscription.nil? || subscription.expired_at < Time.now
|
||||
return nil if subscription.nil? || subscription.expired_at < DateTime.current
|
||||
|
||||
subscription.plan
|
||||
end
|
||||
@ -240,7 +240,7 @@ class User < ActiveRecord::Base
|
||||
|
||||
# remove the token
|
||||
self.auth_token = nil
|
||||
self.merged_at = DateTime.now
|
||||
self.merged_at = DateTime.current
|
||||
|
||||
# check that the email duplication was resolved
|
||||
if sso_user.email.end_with? '-duplicate'
|
||||
|
@ -7,7 +7,7 @@ class EventPolicy < ApplicationPolicy
|
||||
def resolve
|
||||
if user.nil? || (user && !user.admin?)
|
||||
scope.includes(:event_image, :event_files, :availability, :category)
|
||||
.where('availabilities.start_at >= ?', Time.now)
|
||||
.where('availabilities.start_at >= ?', DateTime.current)
|
||||
.order('availabilities.start_at ASC')
|
||||
.references(:availabilities)
|
||||
else
|
||||
|
@ -6,7 +6,7 @@ class SlotPolicy < ApplicationPolicy
|
||||
|
||||
# these condition does not apply to admins
|
||||
user.admin? or
|
||||
(record.reservation.user == user and enabled and ((record.start_at - Time.now).to_i / 3600 >= delay))
|
||||
(record.reservation.user == user and enabled and ((record.start_at - DateTime.current).to_i / 3600 >= delay))
|
||||
end
|
||||
|
||||
def cancel?
|
||||
|
@ -18,7 +18,7 @@ class Availabilities::AvailabilitiesService
|
||||
slots = []
|
||||
availabilities.each do |a|
|
||||
((a.end_at - a.start_at) / ApplicationHelper::SLOT_DURATION.minutes).to_i.times do |i|
|
||||
next unless (a.start_at + (i * ApplicationHelper::SLOT_DURATION).minutes) > Time.now
|
||||
next unless (a.start_at + (i * ApplicationHelper::SLOT_DURATION).minutes) > DateTime.current
|
||||
|
||||
slot = Slot.new(
|
||||
start_at: a.start_at + (i * ApplicationHelper::SLOT_DURATION).minutes,
|
||||
@ -44,7 +44,7 @@ class Availabilities::AvailabilitiesService
|
||||
slots = []
|
||||
availabilities.each do |a|
|
||||
((a.end_at - a.start_at) / ApplicationHelper::SLOT_DURATION.minutes).to_i.times do |i|
|
||||
next unless (a.start_at + (i * ApplicationHelper::SLOT_DURATION).minutes) > Time.now
|
||||
next unless (a.start_at + (i * ApplicationHelper::SLOT_DURATION).minutes) > DateTime.current
|
||||
|
||||
slot = Slot.new(
|
||||
start_at: a.start_at + (i * ApplicationHelper::SLOT_DURATION).minutes,
|
||||
@ -69,7 +69,7 @@ class Availabilities::AvailabilitiesService
|
||||
# first, we get the already-made reservations
|
||||
reservations = user.reservations.where("reservable_type = 'Training'")
|
||||
reservations = reservations.where('reservable_id = :id', id: training_id.to_i) if training_id.is_number?
|
||||
reservations = reservations.joins(:slots).where('slots.start_at > ?', Time.now)
|
||||
reservations = reservations.joins(:slots).where('slots.start_at > ?', DateTime.current)
|
||||
|
||||
# visible availabilities depends on multiple parameters
|
||||
availabilities = training_availabilities(training_id, user)
|
||||
@ -83,7 +83,7 @@ class Availabilities::AvailabilitiesService
|
||||
private
|
||||
|
||||
def subscription_year?(user)
|
||||
user.subscription && user.subscription.plan.interval == 'year' && user.subscription.expired_at >= Time.now
|
||||
user.subscription && user.subscription.plan.interval == 'year' && user.subscription.expired_at >= DateTime.current
|
||||
end
|
||||
|
||||
# member must have validated at least 1 training and must have a valid yearly subscription.
|
||||
@ -95,21 +95,21 @@ class Availabilities::AvailabilitiesService
|
||||
Reservation.where('reservable_type = ? and reservable_id = ?', reservable.class.name, reservable.id)
|
||||
.includes(:slots, statistic_profile: [user: [:profile]])
|
||||
.references(:slots, :user)
|
||||
.where('slots.start_at > ?', Time.now)
|
||||
.where('slots.start_at > ?', DateTime.current)
|
||||
end
|
||||
|
||||
def availabilities(reservable, type, user)
|
||||
if user.admin?
|
||||
reservable.availabilities
|
||||
.includes(:tags)
|
||||
.where('end_at > ? AND available_type = ?', Time.now, type)
|
||||
.where('end_at > ? AND available_type = ?', DateTime.current, type)
|
||||
.where(lock: false)
|
||||
else
|
||||
end_at = @maximum_visibility[:other]
|
||||
end_at = @maximum_visibility[:year] if subscription_year?(user)
|
||||
reservable.availabilities
|
||||
.includes(:tags)
|
||||
.where('end_at > ? AND end_at < ? AND available_type = ?', Time.now, end_at, type)
|
||||
.where('end_at > ? AND end_at < ? AND available_type = ?', DateTime.current, end_at, type)
|
||||
.where('availability_tags.tag_id' => user.tag_ids.concat([nil]))
|
||||
.where(lock: false)
|
||||
end
|
||||
@ -126,14 +126,14 @@ class Availabilities::AvailabilitiesService
|
||||
# 1) an admin (he can see all future availabilities)
|
||||
if @current_user.admin?
|
||||
availabilities.includes(:tags, :slots, trainings: [:machines])
|
||||
.where('availabilities.start_at > ?', Time.now)
|
||||
.where('availabilities.start_at > ?', DateTime.current)
|
||||
.where(lock: false)
|
||||
# 2) an user (he cannot see availabilities further than 1 (or 3) months)
|
||||
else
|
||||
end_at = @maximum_visibility[:other]
|
||||
end_at = @maximum_visibility[:year] if show_extended_slots?(user)
|
||||
availabilities.includes(:tags, :slots, :availability_tags, trainings: [:machines])
|
||||
.where('availabilities.start_at > ? AND availabilities.start_at < ?', Time.now, end_at)
|
||||
.where('availabilities.start_at > ? AND availabilities.start_at < ?', DateTime.current, end_at)
|
||||
.where('availability_tags.tag_id' => user.tag_ids.concat([nil]))
|
||||
.where(lock: false)
|
||||
end
|
||||
|
@ -47,7 +47,7 @@ class Availabilities::PublicAvailabilitiesService
|
||||
availabilities.each do |a|
|
||||
space = a.spaces.first
|
||||
((a.end_at - a.start_at) / ApplicationHelper::SLOT_DURATION.minutes).to_i.times do |i|
|
||||
next unless (a.start_at + (i * ApplicationHelper::SLOT_DURATION).minutes) > Time.now
|
||||
next unless (a.start_at + (i * ApplicationHelper::SLOT_DURATION).minutes) > DateTime.current
|
||||
|
||||
slot = Slot.new(
|
||||
start_at: a.start_at + (i * ApplicationHelper::SLOT_DURATION).minutes,
|
||||
|
@ -3,7 +3,7 @@
|
||||
# Provides methods to generate invoice references
|
||||
class InvoiceReferenceService
|
||||
class << self
|
||||
def generate_reference(invoice, date: Time.now, avoir: false)
|
||||
def generate_reference(invoice, date: DateTime.current, avoir: false)
|
||||
pattern = Setting.find_by(name: 'invoice_reference').value
|
||||
|
||||
reference = replace_invoice_number_pattern(pattern, invoice)
|
||||
|
@ -4,7 +4,7 @@
|
||||
class SlotService
|
||||
def cancel(slot)
|
||||
# first we mark ths slot as cancelled in DB, to free a ticket
|
||||
slot.update_attributes(canceled_at: DateTime.now)
|
||||
slot.update_attributes(canceled_at: DateTime.current)
|
||||
|
||||
# then we try to remove this reservation from ElasticSearch, to keep the statistics up-to-date
|
||||
model_name = slot.reservation.reservable.class.name
|
||||
|
@ -19,7 +19,7 @@ class UserService
|
||||
)
|
||||
user.build_statistic_profile(
|
||||
gender: true,
|
||||
birthday: Time.now
|
||||
birthday: DateTime.current
|
||||
)
|
||||
|
||||
saved = user.save
|
||||
|
@ -27,7 +27,7 @@ class VatHistoryService
|
||||
|
||||
def vat_history
|
||||
chronology = []
|
||||
end_date = DateTime.now
|
||||
end_date = DateTime.current
|
||||
Setting.find_by(name: 'invoice_VAT-active').history_values.order(created_at: 'DESC').each do |v|
|
||||
chronology.push(start: v.created_at, end: end_date, enabled: v.value == 'true')
|
||||
end_date = v.created_at
|
||||
|
@ -6,7 +6,7 @@ class ClosedPeriodValidator < ActiveModel::Validator
|
||||
date = if record.is_a?(Avoir)
|
||||
record.avoir_date
|
||||
else
|
||||
DateTime.now
|
||||
DateTime.current
|
||||
end
|
||||
|
||||
|
||||
|
@ -7,7 +7,7 @@ class CouponExpirationValidator < ActiveModel::Validator
|
||||
current = record.valid_until
|
||||
|
||||
unless current.blank?
|
||||
if current.end_of_day < Time.now
|
||||
if current.end_of_day < DateTime.current
|
||||
record.errors[:valid_until] << I18n.t('errors.messages.cannot_be_in_the_past')
|
||||
end
|
||||
|
||||
|
@ -56,8 +56,8 @@ wb.add_worksheet(name: t('export_members.members')) do |sheet|
|
||||
member.profile.interest,
|
||||
member.profile.software_mastered,
|
||||
member.group&.name,
|
||||
expiration && Time.now < expiration ? member.subscription.plan.name : t('export_members.without_subscriptions'),
|
||||
expiration && Time.now < expiration ? member.subscription.expired_at.to_date : nil,
|
||||
expiration && DateTime.current < expiration ? member.subscription.plan.name : t('export_members.without_subscriptions'),
|
||||
expiration && DateTime.current < expiration ? member.subscription.expired_at.to_date : nil,
|
||||
member.trainings.map(&:name).join("\n"),
|
||||
member.tags.map(&:name).join("\n"),
|
||||
member.invoices.size,
|
||||
|
@ -45,7 +45,7 @@ class ArchiveWorker
|
||||
last_archive_checksum: last_checksum,
|
||||
previous_file: previous_file,
|
||||
software_version: Version.current,
|
||||
date: Time.now.iso8601
|
||||
date: DateTime.current.iso8601
|
||||
},
|
||||
formats: [:json],
|
||||
handlers: [:jbuilder]
|
||||
|
@ -4,7 +4,7 @@ class OpenAPITraceCallsCountWorker < Sidekiq::Workers
|
||||
|
||||
def perform
|
||||
OpenAPI::Client.find_each do |client|
|
||||
OpenAPI::CallsCountTracing.create!(client: client, calls_count: client.calls_count, at: DateTime.now)
|
||||
OpenAPI::CallsCountTracing.create!(client: client, calls_count: client.calls_count, at: DateTime.current)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -9,7 +9,7 @@ class ReservationReminderWorker
|
||||
if enabled == 'true'
|
||||
delay = Setting.find_by(name: 'reminder_delay').try(:value).try(:to_i).try(:hours) || DEFAULT_REMINDER_DELAY
|
||||
|
||||
starting = Time.now.beginning_of_hour + delay
|
||||
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|
|
||||
|
@ -2,8 +2,8 @@ class SubscriptionExpireWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
def perform(expire_in)
|
||||
Subscription.where('expiration_date >= ?', Time.now.at_beginning_of_day).each do |s|
|
||||
if (s.expired_at - expire_in.days).to_date == Time.now.to_date
|
||||
Subscription.where('expiration_date >= ?', DateTime.current.at_beginning_of_day).each do |s|
|
||||
if (s.expired_at - expire_in.days).to_date == DateTime.current.to_date
|
||||
if expire_in != 0
|
||||
NotificationCenter.call type: 'notify_member_subscription_will_expire_in_7_days',
|
||||
receiver: s.user,
|
||||
|
@ -15,8 +15,8 @@ ActiveRecord::Schema.define(version: 20191113103352) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
enable_extension "pg_trgm"
|
||||
enable_extension "unaccent"
|
||||
enable_extension "pg_trgm"
|
||||
|
||||
create_table "abuses", force: :cascade do |t|
|
||||
t.integer "signaled_id"
|
||||
|
@ -90,7 +90,7 @@ if Role.where(name: 'admin').joins(:users).count.zero?
|
||||
admin = User.new(username: 'admin', email: ENV['ADMIN_EMAIL'], password: ENV['ADMIN_PASSWORD'],
|
||||
password_confirmation: Rails.application.secrets.admin_password, group_id: Group.find_by(slug: 'admins').id,
|
||||
profile_attributes: { first_name: 'admin', last_name: 'admin', phone: '0123456789' },
|
||||
statistic_profile_attributes: { gender: true, birthday: Time.now })
|
||||
statistic_profile_attributes: { gender: true, birthday: DateTime.current })
|
||||
admin.add_role 'admin'
|
||||
admin.save!
|
||||
end
|
||||
|
@ -170,7 +170,7 @@ namespace :fablab do
|
||||
|
||||
days = args.period.to_i
|
||||
if days.zero?
|
||||
StatisticService.new.generate_statistic(start_date: DateTime.now.beginning_of_day, end_date: DateTime.now.end_of_day)
|
||||
StatisticService.new.generate_statistic(start_date: DateTime.current.beginning_of_day, end_date: DateTime.current.end_of_day)
|
||||
else
|
||||
days.times.each do |i|
|
||||
StatisticService.new.generate_statistic(start_date: i.day.ago.beginning_of_day, end_date: i.day.ago.end_of_day)
|
||||
|
@ -6,7 +6,7 @@ namespace :fablab do
|
||||
|
||||
desc 'Cancel stripe subscriptions'
|
||||
task cancel_subscriptions: :environment do
|
||||
Subscription.where('expiration_date >= ?', Time.now.at_beginning_of_day).each do |s|
|
||||
Subscription.where('expiration_date >= ?', DateTime.current.at_beginning_of_day).each do |s|
|
||||
puts "-> Start cancel subscription of #{s.user.email}"
|
||||
s.cancel
|
||||
puts '-> Done'
|
||||
|
Loading…
x
Reference in New Issue
Block a user