From d6e5c0b3463db10f4835d3b92fa6d837958dcfb4 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 9 Dec 2016 00:44:01 +1100 Subject: [PATCH] Adding extra scopes to StandingOrder model --- app/models/standing_order.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/standing_order.rb b/app/models/standing_order.rb index bec04b520a..49d05e7213 100644 --- a/app/models/standing_order.rb +++ b/app/models/standing_order.rb @@ -23,7 +23,10 @@ class StandingOrder < ActiveRecord::Base validate :standing_line_items_available validate :check_associations - scope :active, where('standing_orders.paused_at IS NULL AND standing_orders.canceled_at IS NULL AND standing_orders.begins_at <= (?) AND (standing_orders.ends_at > (?) OR standing_orders.ends_at IS NULL)', Time.zone.now, Time.zone.now) + scope :not_ended, -> { where('standing_orders.ends_at > (?) OR standing_orders.ends_at IS NULL', Time.zone.now) } + scope :not_canceled, where('standing_orders.canceled_at IS NULL') + scope :not_paused, where('standing_orders.paused_at IS NULL') + scope :active, -> { not_canceled.not_ended.not_paused.where('standing_orders.begins_at <= (?)', Time.zone.now) } def closed_standing_order_orders standing_order_orders.closed