Sha256: 53a2122bd2c3ece5ed4357330a0a7d2986db39984023f225042fd54769e424d8

Contents?: true

Size: 771 Bytes

Versions: 34

Compression:

Stored size: 771 Bytes

Contents

# frozen_string_literal: true

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

    has_many :tax_rate_tax_categories,
      class_name: 'Spree::TaxRateTaxCategory',
      dependent: :destroy,
      inverse_of: :tax_category
    has_many :tax_rates,
      through: :tax_rate_tax_categories,
      class_name: 'Spree::TaxRate',
      inverse_of: :tax_categories

    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: id).update_all(is_default: false, updated_at: Time.current)
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
solidus_core-2.8.6 app/models/spree/tax_category.rb
solidus_core-2.6.6 app/models/spree/tax_category.rb
solidus_core-2.7.4 app/models/spree/tax_category.rb
solidus_core-2.8.5 app/models/spree/tax_category.rb
solidus_core-2.7.3 app/models/spree/tax_category.rb
solidus_core-2.6.5 app/models/spree/tax_category.rb
solidus_core-2.8.4 app/models/spree/tax_category.rb
solidus_core-2.8.3 app/models/spree/tax_category.rb
solidus_core-2.7.2 app/models/spree/tax_category.rb
solidus_core-2.6.4 app/models/spree/tax_category.rb
solidus_core-2.8.2 app/models/spree/tax_category.rb
solidus_core-2.8.1 app/models/spree/tax_category.rb
solidus_core-2.6.3 app/models/spree/tax_category.rb
solidus_core-2.8.0 app/models/spree/tax_category.rb
solidus_core-2.7.1 app/models/spree/tax_category.rb
solidus_core-2.6.2 app/models/spree/tax_category.rb
solidus_core_devise_token_auth-2.8.0.alpha.14 app/models/spree/tax_category.rb
solidus_core_devise_token_auth-2.8.0.alpha.13 app/models/spree/tax_category.rb
solidus_core_devise_token_auth-2.8.0.alpha.12 app/models/spree/tax_category.rb
solidus_core_devise_token_auth-2.8.0.alpha.11 app/models/spree/tax_category.rb