Sha256: 8ccab0a464bfa28765f55e44db8abdcf3120a3eb4f8f23f31261476a77f0316d

Contents?: true

Size: 1.24 KB

Versions: 74

Compression:

Stored size: 1.24 KB

Contents

module Spree
  class Price < Spree::Base
    include VatPriceCalculation

    acts_as_paranoid

    MAXIMUM_AMOUNT = BigDecimal('99_999_999.99')

    belongs_to :variant, class_name: 'Spree::Variant', inverse_of: :prices, touch: true

    before_validation :ensure_currency

    validates :amount, allow_nil: true, numericality: {
      greater_than_or_equal_to: 0,
      less_than_or_equal_to: MAXIMUM_AMOUNT
    }

    extend DisplayMoney
    money_methods :amount, :price

    self.whitelisted_ransackable_attributes = ['amount']

    def money
      Spree::Money.new(amount || 0, currency: currency)
    end

    def amount=(amount)
      self[:amount] = Spree::LocalizedNumber.parse(amount)
    end

    alias_attribute :price, :amount

    def price_including_vat_for(price_options)
      options = price_options.merge(tax_category: variant.tax_category)
      gross_amount(price, options)
    end

    def display_price_including_vat_for(price_options)
      Spree::Money.new(price_including_vat_for(price_options), currency: currency)
    end

    # Remove variant default_scope `deleted_at: nil`
    def variant
      Spree::Variant.unscoped { super }
    end

    private

    def ensure_currency
      self.currency ||= Spree::Config[:currency]
    end
  end
end

Version data entries

74 entries across 74 versions & 1 rubygems

Version Path
spree_core-4.0.0 app/models/spree/price.rb
spree_core-4.0.0.rc3 app/models/spree/price.rb
spree_core-3.7.6 app/models/spree/price.rb
spree_core-3.7.5 app/models/spree/price.rb
spree_core-4.0.0.rc2 app/models/spree/price.rb
spree_core-4.0.0.rc1 app/models/spree/price.rb
spree_core-4.0.0.beta app/models/spree/price.rb
spree_core-3.7.4 app/models/spree/price.rb
spree_core-3.7.3 app/models/spree/price.rb
spree_core-3.7.2 app/models/spree/price.rb
spree_core-3.7.1 app/models/spree/price.rb
spree_core-3.7.0 app/models/spree/price.rb
spree_core-3.7.0.rc3 app/models/spree/price.rb
spree_core-3.7.0.rc2 app/models/spree/price.rb
spree_core-3.7.0.rc1 app/models/spree/price.rb
spree_core-3.6.6 app/models/spree/price.rb
spree_core-3.6.5 app/models/spree/price.rb
spree_core-3.6.4 app/models/spree/price.rb
spree_core-3.6.3 app/models/spree/price.rb
spree_core-3.6.2 app/models/spree/price.rb