Sha256: f84288c29069af8871c850b2a7cc2658886dd39d80ebe2aae304e39cdd8ae7a8

Contents?: true

Size: 662 Bytes

Versions: 36

Compression:

Stored size: 662 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

    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).first
        unless tax_category == self
          tax_category.update_columns(
            is_default: false,
            updated_at: Time.now,
          )
        end
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
spree_core-3.0.10 app/models/spree/tax_category.rb
spree_core-3.0.9 app/models/spree/tax_category.rb
spree_core-3.0.8 app/models/spree/tax_category.rb
spree_core-3.0.7 app/models/spree/tax_category.rb
spree_core-3.0.6.1 app/models/spree/tax_category.rb
spree_core-3.0.6 app/models/spree/tax_category.rb
spree_core-3.0.5 app/models/spree/tax_category.rb
spree_core-3.0.4 app/models/spree/tax_category.rb
spree_core-2.4.10 app/models/spree/tax_category.rb
spree_core-2.3.13 app/models/spree/tax_category.rb
spree_core-3.0.3 app/models/spree/tax_category.rb
spree_core-2.4.9 app/models/spree/tax_category.rb
spree_core-2.3.12 app/models/spree/tax_category.rb
spree_core-3.0.2 app/models/spree/tax_category.rb
spree_core-2.4.8 app/models/spree/tax_category.rb
spree_core-2.3.11 app/models/spree/tax_category.rb
spree_core-3.0.1 app/models/spree/tax_category.rb
spree_core-2.4.7 app/models/spree/tax_category.rb
spree_core-2.3.10 app/models/spree/tax_category.rb
spree_core-3.0.0 app/models/spree/tax_category.rb