Sha256: 5a66eb553d2fe35f70a3be1cdf0a530b988ee527883b9b38e823c00a70f203bf

Contents?: true

Size: 885 Bytes

Versions: 17

Compression:

Stored size: 885 Bytes

Contents

module Spree
  class TaxCategory < Spree::Base
    if defined?(Spree::Webhooks)
      include Spree::Webhooks::HasWebhooks
    end

    acts_as_paranoid
    validates :name, presence: true, uniqueness: { case_sensitive: false, scope: spree_base_uniqueness_scope.push(:deleted_at) }

    has_many :tax_rates, dependent: :destroy, inverse_of: :tax_category
    has_many :products, dependent: :nullify
    has_many :variants, dependent: :nullify

    before_save :set_default_category

    self.whitelisted_ransackable_attributes = %w[name is_default tax_code]

    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).where.not(id: id).first
        tax_category.update_columns(is_default: false, updated_at: Time.current)
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
spree_core-4.7.3 app/models/spree/tax_category.rb
spree_core-4.6.6 app/models/spree/tax_category.rb
spree_core-4.5.5 app/models/spree/tax_category.rb
spree_core-4.5.4 app/models/spree/tax_category.rb
spree_core-4.6.5 app/models/spree/tax_category.rb
spree_core-4.7.2 app/models/spree/tax_category.rb
spree_core-4.7.1 app/models/spree/tax_category.rb
spree_core-4.6.4 app/models/spree/tax_category.rb
spree_core-4.7.0 app/models/spree/tax_category.rb
spree_core-4.6.3 app/models/spree/tax_category.rb
spree_core-4.6.2 app/models/spree/tax_category.rb
spree_core-4.6.1 app/models/spree/tax_category.rb
spree_core-4.6.0 app/models/spree/tax_category.rb
spree_core-4.5.3 app/models/spree/tax_category.rb
spree_core-4.5.2 app/models/spree/tax_category.rb
spree_core-4.5.1 app/models/spree/tax_category.rb
spree_core-4.5.0 app/models/spree/tax_category.rb