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-3.6.3 app/models/spree/tax_category.rb
spree_core-3.6.2 app/models/spree/tax_category.rb
spree_core-3.6.1 app/models/spree/tax_category.rb
spree_core-3.6.0 app/models/spree/tax_category.rb
spree_core-3.5.0 app/models/spree/tax_category.rb
spree_core-3.6.0.rc1 app/models/spree/tax_category.rb
spree_core-3.5.0.rc2 app/models/spree/tax_category.rb
spree_core-3.5.0.rc1 app/models/spree/tax_category.rb
spree_core-3.4.5 app/models/spree/tax_category.rb
spree_core-3.4.4 app/models/spree/tax_category.rb
spree_core-3.4.3 app/models/spree/tax_category.rb
spree_core-3.4.2 app/models/spree/tax_category.rb
spree_core-3.4.1 app/models/spree/tax_category.rb
spree_core-3.4.0 app/models/spree/tax_category.rb
spree_core-3.4.0.rc2 app/models/spree/tax_category.rb
spree_core-3.4.0.rc1 app/models/spree/tax_category.rb