Permalink
Browse files

Adjustment Scope Refactor

[Fixes #1597]
  • Loading branch information...
1 parent 163cdde commit df9407928741813b8b388e8bb2add3b58ae7dfc8 @GeekOnCoffee GeekOnCoffee committed with radar May 24, 2012
Showing with 30 additions and 8 deletions.
  1. +30 −8 core/app/models/spree/adjustment.rb
@@ -31,14 +31,6 @@ class Adjustment < ActiveRecord::Base
validates :label, :presence => true
validates :amount, :numericality => true
- scope :tax, lambda { where(:originator_type => 'Spree::TaxRate', :adjustable_type => 'Spree::Order') }
- scope :price, lambda { where(:adjustable_type => 'Spree::LineItem') }
- scope :shipping, lambda { where(:originator_type => 'Spree::ShippingMethod') }
- scope :optional, where(:mandatory => false)
- scope :eligible, where(:eligible => true)
- scope :charge, where("amount >= 0")
- scope :credit, where("amount < 0")
-
after_save :update_adjustable
after_destroy :update_adjustable
@@ -79,5 +71,35 @@ def update_adjustable
adjustable.update! if adjustable.is_a? Order
end
+ class << self
+ def tax
+ where(:originator_type => 'Spree::TaxRate', :adjustable_type => 'Spree::Order')
+ end
+
+ def price
+ where(:adjustable_type => 'Spree::LineItem')
+ end
+
+ def shipping
+ where(:originator_type => 'Spree::ShippingMethod')
+ end
+
+ def optional
+ where(:mandatory => false)
+ end
+
+ def eligible
+ where(:eligible => true)
+ end
+
+ def charge
+ where('amount >= 0')
+ end
+
+ def credit
+ where('amount < 0')
+ end
+ end
+
end
end

0 comments on commit df94079

Please sign in to comment.