Sha256: 2339b31702f3e9ed8832547502004b8cc4bcebd41670564fb36c5079d037d876

Contents?: true

Size: 602 Bytes

Versions: 96

Compression:

Stored size: 602 Bytes

Contents

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

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

    before_save :set_default_category

    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

96 entries across 96 versions & 1 rubygems

Version Path
spree_core-4.0.9 app/models/spree/tax_category.rb
spree_core-4.1.15 app/models/spree/tax_category.rb
spree_core-4.2.7 app/models/spree/tax_category.rb
spree_core-4.3.3 app/models/spree/tax_category.rb
spree_core-4.2.6 app/models/spree/tax_category.rb
spree_core-4.3.2 app/models/spree/tax_category.rb
spree_core-4.3.1 app/models/spree/tax_category.rb
spree_core-4.3.0 app/models/spree/tax_category.rb
spree_core-4.3.0.rc3 app/models/spree/tax_category.rb
spree_core-4.3.0.rc2 app/models/spree/tax_category.rb
spree_core-4.3.0.rc1 app/models/spree/tax_category.rb
spree_core-4.2.5 app/models/spree/tax_category.rb
spree_core-4.1.14 app/models/spree/tax_category.rb
spree_core-4.0.8 app/models/spree/tax_category.rb
spree_core-4.2.4 app/models/spree/tax_category.rb
spree_core-3.7.14.1 app/models/spree/tax_category.rb
spree_core-4.2.3.1 app/models/spree/tax_category.rb
spree_core-4.1.13.1 app/models/spree/tax_category.rb
spree_core-4.0.7.1 app/models/spree/tax_category.rb
spree_core-4.2.3 app/models/spree/tax_category.rb