Class: Spree::Adjustment
- Inherits:
-
Object
- Object
- Spree::Adjustment
- Extended by:
- DisplayMoney
- Defined in:
- app/models/spree/adjustment.rb
Instance Method Summary collapse
- #additional? ⇒ Boolean
- #amount=(amount) ⇒ Object
- #currency ⇒ Object
- #promotion? ⇒ Boolean
- #tax? ⇒ Boolean
-
#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.
Methods included from DisplayMoney
Instance Method Details
#additional? ⇒ Boolean
95 96 97 |
# File 'app/models/spree/adjustment.rb', line 95 def additional? !included? end |
#amount=(amount) ⇒ Object
79 80 81 |
# File 'app/models/spree/adjustment.rb', line 79 def amount=(amount) self[:amount] = Spree::LocalizedNumber.parse(amount) end |
#currency ⇒ Object
83 84 85 |
# File 'app/models/spree/adjustment.rb', line 83 def currency adjustable ? adjustable.currency : order.currency end |
#promotion? ⇒ Boolean
87 88 89 |
# File 'app/models/spree/adjustment.rb', line 87 def promotion? source_type == 'Spree::PromotionAction' end |
#tax? ⇒ Boolean
91 92 93 |
# File 'app/models/spree/adjustment.rb', line 91 def tax? source_type == 'Spree::TaxRate' 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.
102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/models/spree/adjustment.rb', line 102 def update!(target = adjustable) return amount if closed? || source.blank? amount = source.compute_amount(target) attributes = { amount: amount, updated_at: Time.current } attributes[:eligible] = source.promotion.eligible?(target) if promotion? update_columns(attributes) amount end |