Sha256: d90babd299b1b441facd331f6a9389ec1211476100d657fd5acf584bb4d5d9e2

Contents?: true

Size: 1.21 KB

Versions: 62

Compression:

Stored size: 1.21 KB

Contents

module Workarea
  class PriceAdjustment
    include ApplicationDocument

    # The type of price being adjusted.
    # One of - item, shipping, tax, order
    field :price, type: String

    # The quantity being adjusted. Used to calculate
    # unit.
    field :quantity, type: Integer, default: 1

    # Front-end display description of what caused
    # the price adjustment.
    field :description, type: String

    # The class that generated this price adjustment.
    field :calculator, type: String

    # Miscellaneous meta data around the price adjustment.
    # Used for discount qualification, tax_code, etc.
    field :data, type: Hash, default: {}

    # How much (positive or negative) this adjustment
    # changes the price.
    field :amount, type: Money

    # The cost per-unit of this price adjustment.
    #
    # @return [Money]
    #
    def unit
      amount / quantity
    end

    # Whether this adjustment was a discount.
    # A price adjustment is considered a discount if its amount is less than
    # zero and not a pricing override, or it has discount data.
    #
    # @return [Boolean]
    #
    def discount?
      (amount < 0 && data['override'].nil?) || data['discount_value'].present?
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/models/workarea/price_adjustment.rb
workarea-core-3.5.26 app/models/workarea/price_adjustment.rb
workarea-core-3.4.45 app/models/workarea/price_adjustment.rb
workarea-core-3.5.25 app/models/workarea/price_adjustment.rb
workarea-core-3.5.23 app/models/workarea/price_adjustment.rb
workarea-core-3.4.44 app/models/workarea/price_adjustment.rb
workarea-core-3.5.22 app/models/workarea/price_adjustment.rb
workarea-core-3.4.43 app/models/workarea/price_adjustment.rb
workarea-core-3.5.21 app/models/workarea/price_adjustment.rb
workarea-core-3.4.42 app/models/workarea/price_adjustment.rb
workarea-core-3.5.20 app/models/workarea/price_adjustment.rb
workarea-core-3.4.41 app/models/workarea/price_adjustment.rb
workarea-core-3.5.19 app/models/workarea/price_adjustment.rb
workarea-core-3.4.40 app/models/workarea/price_adjustment.rb
workarea-core-3.5.18 app/models/workarea/price_adjustment.rb
workarea-core-3.4.39 app/models/workarea/price_adjustment.rb
workarea-core-3.5.17 app/models/workarea/price_adjustment.rb
workarea-core-3.4.38 app/models/workarea/price_adjustment.rb
workarea-core-3.5.16 app/models/workarea/price_adjustment.rb
workarea-core-3.4.37 app/models/workarea/price_adjustment.rb