Sha256: c24bb27af792fc0c4025e9e65f4b845d699a5dd69f533c5beb6309a31442a28f

Contents?: true

Size: 674 Bytes

Versions: 6

Compression:

Stored size: 674 Bytes

Contents

class Charge < Adjustment
  before_save :ensure_positive_amount

  private
  # Ensures Charge has always positive amount.
  #
  # Amount should be modified ONLY when it's going to be saved to the database
  # (read_attribute returns value)
  #
  # WARNING! It does not protect from Credits getting negative amounts while
  # amount is autocalculated! Descending classes should ensure amount is always
  # negative in their calculate_adjustment methods.
  # This method should be threated as a last resort for keeping integrity of adjustments
  def ensure_positive_amount
    if (db_amount = read_attribute(:amount)) && db_amount < 0
      self.amount *= -1
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spree-0.11.1 app/models/charge.rb
spree-0.11.0 app/models/charge.rb
spree-0.10.2 app/models/charge.rb
spree-0.10.1 app/models/charge.rb
spree-0.10.0 app/models/charge.rb
spree-0.10.0.beta app/models/charge.rb