Sha256: 57458100f60b86e4dfe76d614435eca1cbd7b5bea014ded75b52cf13f2378452

Contents?: true

Size: 616 Bytes

Versions: 7

Compression:

Stored size: 616 Bytes

Contents

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

    has_many :tax_rates, dependent: :destroy

    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

7 entries across 7 versions & 1 rubygems

Version Path
spree_core-2.4.0.rc2 app/models/spree/tax_category.rb
spree_core-2.4.0.rc1 app/models/spree/tax_category.rb
spree_core-2.3.4 app/models/spree/tax_category.rb
spree_core-2.3.3 app/models/spree/tax_category.rb
spree_core-2.3.2 app/models/spree/tax_category.rb
spree_core-2.3.1 app/models/spree/tax_category.rb
spree_core-2.3.0 app/models/spree/tax_category.rb