Style Rails/WhereRange

This commit is contained in:
Maikel Linke
2025-01-10 08:43:58 +11:00
parent 2937595a33
commit 49ec9a3136
4 changed files with 9 additions and 10 deletions

View File

@@ -32,6 +32,6 @@ class Invoice < ApplicationRecord
end
def previous_invoice
order.invoices.where("id < ?", id).first
order.invoices.where(id: ...id).first
end
end

View File

@@ -53,7 +53,7 @@ class OrderCycle < ApplicationRecord
Time.zone.now,
Time.zone.now)
}
scope :active_or_complete, lambda { where('order_cycles.orders_open_at <= ?', Time.zone.now) }
scope :active_or_complete, lambda { where(order_cycles: { orders_open_at: ..Time.zone.now }) }
scope :inactive, lambda {
where('order_cycles.orders_open_at > ? OR order_cycles.orders_close_at < ?',
Time.zone.now,
@@ -64,8 +64,8 @@ class OrderCycle < ApplicationRecord
where('order_cycles.orders_close_at > ? OR order_cycles.orders_close_at IS NULL', Time.zone.now)
}
scope :closed, lambda {
where('order_cycles.orders_close_at < ?',
Time.zone.now).order("order_cycles.orders_close_at DESC")
where(order_cycles: { orders_close_at: ...Time.zone.now })
.order("order_cycles.orders_close_at DESC")
}
scope :unprocessed, -> { where(processed_at: nil) }
scope :undated, -> { where('order_cycles.orders_open_at IS NULL OR orders_close_at IS NULL') }

View File

@@ -90,9 +90,8 @@ module OrderManagement
end
def in_range_order_cycles
order_cycles.where("orders_close_at >= ? AND orders_close_at <= ?",
begins_at,
ends_at || 100.years.from_now)
ends_at_or_limit = ends_at || 100.years.from_now
order_cycles.where(orders_close_at: begins_at..ends_at_or_limit )
end
end
end

View File

@@ -18,9 +18,9 @@ class RemoveTransientData
def call
Rails.logger.info("#{self.class.name}: processing")
Spree::StateChange.where("created_at < ?", expiration_date).delete_all
Spree::LogEntry.where("created_at < ?", expiration_date).delete_all
Session.where("updated_at < ?", expiration_date).delete_all
Spree::StateChange.where(created_at: ...expiration_date).delete_all
Spree::LogEntry.where(created_at: ...expiration_date).delete_all
Session.where(updated_at: ...expiration_date).delete_all
clear_old_cart_data!
end