Sha256: b48f3cfd3171b8ab1a254fa04a23d771e53d8b25cc7ce92617d4c0c62f332196

Contents?: true

Size: 535 Bytes

Versions: 7

Compression:

Stored size: 535 Bytes

Contents

module Spree
  class TaxCategory < Spree::Base
    acts_as_paranoid
    validates :name, presence: true
    validates_uniqueness_of :name, unless: :deleted_at

    has_many :tax_rates, dependent: :destroy, inverse_of: :tax_category
    after_save :ensure_one_default

    def self.default
      find_by(is_default: true)
    end

    def ensure_one_default
      if is_default
        Spree::TaxCategory.where(is_default: true).where.not(id: self.id).update_all(is_default: false, updated_at: Time.current)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
solidus_core-1.2.3 app/models/spree/tax_category.rb
solidus_core-1.2.2 app/models/spree/tax_category.rb
solidus_core-1.2.1 app/models/spree/tax_category.rb
solidus_core-1.2.0 app/models/spree/tax_category.rb
solidus_core-1.2.0.rc2 app/models/spree/tax_category.rb
solidus_core-1.2.0.rc1 app/models/spree/tax_category.rb
solidus_core-1.2.0.beta1 app/models/spree/tax_category.rb