Sha256: 1ed6a62b9905020a2a9dc27d201c80e6db4e8cb870be02ce80d408e7f68c4dcb

Contents?: true

Size: 531 Bytes

Versions: 21

Compression:

Stored size: 531 Bytes

Contents

module Spree
  class TaxCategory < Spree::Base
    acts_as_paranoid
    validates :name, presence: true, uniqueness: { scope: :deleted_at, allow_blank: true }

    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.now)
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
solidus_core-1.1.4 app/models/spree/tax_category.rb
solidus_core-1.0.7 app/models/spree/tax_category.rb
solidus_core-1.0.6 app/models/spree/tax_category.rb
solidus_core-1.1.3 app/models/spree/tax_category.rb
solidus_core-1.0.5 app/models/spree/tax_category.rb
solidus_core-1.0.4 app/models/spree/tax_category.rb
solidus_core-1.1.2 app/models/spree/tax_category.rb
solidus_core-1.0.3 app/models/spree/tax_category.rb
solidus_core-1.1.1 app/models/spree/tax_category.rb
solidus_core-1.1.0 app/models/spree/tax_category.rb
solidus_core-1.1.0.pre2 app/models/spree/tax_category.rb
solidus_core-1.1.0.pre1 app/models/spree/tax_category.rb
solidus_core-1.1.0.beta1 app/models/spree/tax_category.rb
solidus_core-1.0.2 app/models/spree/tax_category.rb
solidus_core-1.0.1 app/models/spree/tax_category.rb
solidus_core-1.0.0 app/models/spree/tax_category.rb
solidus_core-1.0.0.rc2 app/models/spree/tax_category.rb
solidus_core-1.0.0.rc1 app/models/spree/tax_category.rb
solidus_core-1.0.0.pre3 app/models/spree/tax_category.rb
solidus_core-1.0.0.pre2 app/models/spree/tax_category.rb