Sha256: b94b0fc1586cf3e63ab4831842b94c2d264a066fedd99a6ab4234aaaa5fc9ec9

Contents?: true

Size: 967 Bytes

Versions: 14

Compression:

Stored size: 967 Bytes

Contents

# frozen_string_literal: true

require 'discard'

module Spree
  class TaxCategory < Spree::Base
    acts_as_paranoid
    include Spree::ParanoiaDeprecations

    include Discard::Model
    self.discard_column = :deleted_at

    after_discard do
      self.tax_rate_tax_categories = []
    end

    validates :name, presence: true
    validates_uniqueness_of :name, unless: :deleted_at

    has_many :tax_rate_tax_categories,
      class_name: 'Spree::TaxRateTaxCategory',
      dependent: :destroy,
      inverse_of: :tax_category
    has_many :tax_rates,
      through: :tax_rate_tax_categories,
      class_name: 'Spree::TaxRate',
      inverse_of: :tax_categories

    after_save :ensure_one_default

    def self.default
      find_by(is_default: true)
    end

    def ensure_one_default
      if is_default
        Spree::TaxCategory.where(is_default: true).where.not(id: id).update_all(is_default: false, updated_at: Time.current)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
solidus_core-2.10.5 app/models/spree/tax_category.rb
solidus_core-2.10.3 app/models/spree/tax_category.rb
solidus_core-2.10.2 app/models/spree/tax_category.rb
solidus_core-2.9.6 app/models/spree/tax_category.rb
solidus_core-2.10.1 app/models/spree/tax_category.rb
solidus_core-2.9.5 app/models/spree/tax_category.rb
solidus_core-2.10.0 app/models/spree/tax_category.rb
solidus_core-2.9.4 app/models/spree/tax_category.rb
solidus_core-2.9.3 app/models/spree/tax_category.rb
solidus_core-2.9.2 app/models/spree/tax_category.rb
solidus_core-2.10.0.beta1 app/models/spree/tax_category.rb
solidus_core-2.9.1 app/models/spree/tax_category.rb
solidus_core-2.9.0 app/models/spree/tax_category.rb
solidus_core-2.9.0.rc.1 app/models/spree/tax_category.rb