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
97 98 99 |
# File 'app/models/spree/adjustment.rb', line 97 def additional? !included? end |
#amount=(amount) ⇒ Object
81 82 83 |
# File 'app/models/spree/adjustment.rb', line 81 def amount=(amount) self[:amount] = Spree::LocalizedNumber.parse(amount) end |
#currency ⇒ Object
85 86 87 |
# File 'app/models/spree/adjustment.rb', line 85 def currency adjustable ? adjustable.currency : order.currency end |
#promotion? ⇒ Boolean
89 90 91 |
# File 'app/models/spree/adjustment.rb', line 89 def promotion? source_type == 'Spree::PromotionAction' end |
#tax? ⇒ Boolean
93 94 95 |
# File 'app/models/spree/adjustment.rb', line 93 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.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'app/models/spree/adjustment.rb', line 104 def update!(target = adjustable) src = source return amount if closed? || src.blank? new_amount = src.compute_amount(target) new_eligible = promotion? ? src.promotion.eligible?(target) : eligible changed_attributes = {} changed_attributes[:amount] = new_amount if new_amount != amount changed_attributes[:eligible] = new_eligible if new_eligible != eligible if changed_attributes.any? changed_attributes[:updated_at] = Time.current update_columns(changed_attributes) end new_amount end |