Sha256: 4f121fba4439947f5445a1dfd5c112701470275df04a7e53ce07cf95afc0e23a

Contents?: true

Size: 636 Bytes

Versions: 6

Compression:

Stored size: 636 Bytes

Contents

module Spree
  class TaxCategory < ActiveRecord::Base
    validates :name, :presence => true, :uniqueness => { :scope => :deleted_at }

    has_many :tax_rates, :dependent => :destroy

    before_save :set_default_category

    default_scope where(:deleted_at => nil)

    def set_default_category
      #set existing default tax category to false if this one has been marked as default

      if is_default && tax_category = self.class.where(:is_default => true).first
        tax_category.update_attribute(:is_default, false)
      end
    end

    def mark_deleted!
      self.deleted_at = Time.now
      self.save
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spree_core-1.0.4 app/models/spree/tax_category.rb
spree_core-1.0.3 app/models/spree/tax_category.rb
spree_core-1.0.2 app/models/spree/tax_category.rb
spree_core-1.0.1 app/models/spree/tax_category.rb
spree_core-1.0.0 app/models/spree/tax_category.rb
spree_core-1.0.0.rc4 app/models/spree/tax_category.rb