From caee2eb3e9c93a0e1507a9eb91abc916bb8b7dde Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Fri, 23 Apr 2021 10:23:40 +0100 Subject: [PATCH 1/2] Remove dead code in order These aren't used anywhere --- app/models/spree/order.rb | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index 2a919c5463..bd4f31f8f0 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -135,18 +135,6 @@ module Spree scope :finalized, -> { where(state: FINALIZED_STATES) } - def self.by_number(number) - where(number: number) - end - - def self.between(start_date, end_date) - where(created_at: start_date..end_date) - end - - def self.by_customer(customer) - joins(:user).where("#{Spree.user_class.table_name}.email" => customer) - end - def self.by_state(state) where(state: state) end From 4938285dd7127c366e00d4c632c244a6fb259c89 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Fri, 23 Apr 2021 10:29:48 +0100 Subject: [PATCH 2/2] Move order query methods to chainable scopes --- app/models/spree/order.rb | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index bd4f31f8f0..b3980058a8 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -126,26 +126,14 @@ module Spree joins('LEFT OUTER JOIN spree_products ON (spree_products.id = spree_variants.product_id)') } - scope :not_state, lambda { |state| - where.not(state: state) - } - # All the states an order can be in after completing the checkout FINALIZED_STATES = %w(complete canceled resumed awaiting_return returned).freeze scope :finalized, -> { where(state: FINALIZED_STATES) } - - def self.by_state(state) - where(state: state) - end - - def self.complete - where('completed_at IS NOT NULL') - end - - def self.incomplete - where(completed_at: nil) - end + scope :complete, -> { where.not(completed_at: nil) } + scope :incomplete, -> { where(completed_at: nil) } + scope :by_state, lambda { |state| where(state: state) } + scope :not_state, lambda { |state| where.not(state: state) } # For compatiblity with Calculator::PriceSack def amount