Class: Spree::Adjustment
- Inherits:
-
Base
- Object
- ActiveRecord::Base
- Base
- Spree::Adjustment
show all
- Extended by:
- DisplayMoney
- Defined in:
- app/models/spree/adjustment.rb
Instance Method Summary
collapse
money_methods
Methods inherited from Base
page
#clear_preferences, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference
Instance Method Details
#closed? ⇒ Boolean
74
75
76
|
# File 'app/models/spree/adjustment.rb', line 74
def closed?
state == "closed"
end
|
#currency ⇒ Object
78
79
80
|
# File 'app/models/spree/adjustment.rb', line 78
def currency
adjustable ? adjustable.currency : Spree::Config[:currency]
end
|
82
83
84
|
# File 'app/models/spree/adjustment.rb', line 82
def promotion?
source_type == 'Spree::PromotionAction'
end
|
#update!(target = adjustable) ⇒ Object
Passing a target here would always be recommended as it would avoid hitting the database again and would ensure you’re compute values over the specific object amount passed here.
89
90
91
92
93
94
95
96
|
# File 'app/models/spree/adjustment.rb', line 89
def update!(target = adjustable)
return amount if closed? || source.blank?
amount = source.compute_amount(target)
attributes = { amount: amount, updated_at: Time.now }
attributes[:eligible] = source.promotion.eligible?(target) if promotion?
update_columns(attributes)
amount
end
|