Skip to content

Commit

Permalink
Find better names for constants and scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
sauloperez committed Jan 20, 2021
1 parent 6502ea4 commit cf89864
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
13 changes: 8 additions & 5 deletions app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,16 @@ def states
where("state != ?", state)
}

# All the states of a complete order but that shouldn't count towards the balance (the customer
# didn't get the order for whatever reason). Note it does not include complete
FINALIZED_STATES = %w(canceled returned).freeze
# All the states an order can be in before completing the checkout
PRIOR_TO_COMPLETION_STATES = %w(cart address delivery payment).freeze
# All the states of a complete order but that shouldn't count towards the balance. Those that
# the customer won't enjoy.
NON_FULFILLED_STATES = %w(canceled returned).freeze
UNFINALIZED_STATES = %w(cart address delivery payment).freeze

scope :in_incomplete_state, -> { where(state: PRIOR_TO_COMPLETION_STATES) }
scope :finalized, -> { where(state: FINALIZED_STATES) }
scope :unfinalized, -> { where(state: UNFINALIZED_STATES) }

scope :in_incomplete_state, -> { where(state: UNFINALIZED_STATES) }

def self.by_number(number)
where(number: number)
Expand Down
3 changes: 1 addition & 2 deletions app/queries/customers_with_balance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ def left_join_complete_orders
end

def complete_orders
states = Spree::Order::PRIOR_TO_COMPLETION_STATES
.map { |state| Arel::Nodes.build_quoted(state) }
states = Spree::Order::UNFINALIZED_STATES.map { |state| Arel::Nodes.build_quoted(state) }
Arel::Nodes::NotIn.new(Spree::Order.arel_table[:state], states)
end
end
2 changes: 1 addition & 1 deletion app/queries/outstanding_balance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def statement
attr_reader :relation

def non_fulfilled_states_group
states = Spree::Order::NON_FULFILLED_STATES.map { |state| Arel::Nodes.build_quoted(state) }
states = Spree::Order::FINALIZED_STATES.map { |state| Arel::Nodes.build_quoted(state) }
Arel::Nodes::Grouping.new(states)
end
end

0 comments on commit cf89864

Please sign in to comment.