Sha256: 7d5bbc28645e9b8f0e872ca986a10a2e3cf9c94a28cc94076fee1ca0ad05f9be

Contents?: true

Size: 685 Bytes

Versions: 30

Compression:

Stored size: 685 Bytes

Contents

module Piggybak
  class Adjustment < ActiveRecord::Base
    belongs_to :order
    belongs_to :source, :polymorphic => true
    attr_accessor :user_id
    acts_as_changer

    validates_presence_of :order_id, :total
    validates_numericality_of :total
    validates_presence_of :source

    before_validation :set_source

    def set_source
      if self.source.nil? && self.user_id.present?
        self.source = User.find(self.user_id)
      end
    end

    def admin_label
      if !self.new_record? 
        return "Adjustment ##{self.id} (#{self.created_at.strftime("%m-%d-%Y")}): " + 
          "$#{"%.2f" % self.total}"
      else
        return ""
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
piggybak-0.5.5 app/models/piggybak/adjustment.rb
piggybak-0.5.4 app/models/piggybak/adjustment.rb
piggybak-0.5.3 app/models/piggybak/adjustment.rb
piggybak-0.5.2 app/models/piggybak/adjustment.rb
piggybak-0.5.1 app/models/piggybak/adjustment.rb
piggybak-0.5.0 app/models/piggybak/adjustment.rb
piggybak-0.4.39 app/models/piggybak/adjustment.rb
piggybak-0.4.38 app/models/piggybak/adjustment.rb
piggybak-0.4.37 app/models/piggybak/adjustment.rb
piggybak-0.4.36 app/models/piggybak/adjustment.rb
piggybak-0.4.35 app/models/piggybak/adjustment.rb
piggybak-0.4.34 app/models/piggybak/adjustment.rb
piggybak-0.4.33 app/models/piggybak/adjustment.rb
piggybak-0.4.32 app/models/piggybak/adjustment.rb
piggybak-0.4.31 app/models/piggybak/adjustment.rb
piggybak-0.4.30 app/models/piggybak/adjustment.rb
piggybak-0.4.29 app/models/piggybak/adjustment.rb
piggybak-0.4.28 app/models/piggybak/adjustment.rb
piggybak-0.4.27 app/models/piggybak/adjustment.rb
piggybak-0.4.26 app/models/piggybak/adjustment.rb