Sha256: 3dc4cdf9f8579bb5386917120926c83e99ca674d80dbc2425e6264a66465d1dc

Contents?: true

Size: 1007 Bytes

Versions: 61

Compression:

Stored size: 1007 Bytes

Contents

module Workarea
  module Pricing
    class Override
      include ApplicationDocument

      # This will be the order id
      field :_id, type: String, default: -> { BSON::ObjectId.new.to_s }
      field :created_by_id, type: String
      field :subtotal_adjustment, type: Money, default: 0
      field :shipping_adjustment, type: Money, default: 0
      field :item_prices, type: Hash, default: {}

      def has_adjustments?
        adjusts_shipping? || adjusts_subtotal? || adjusts_items?
      end

      def adjusts_shipping?
        shipping_adjustment.present? && !shipping_adjustment.zero?
      end

      def adjusts_subtotal?
        subtotal_adjustment.present? && !subtotal_adjustment.zero?
      end

      def adjusts_items?
        item_prices.present? &&
          item_prices.values.reject(&:blank?).any?(&:present?)
      end

      def item_price_for_id(item_id)
        price = item_prices.fetch(item_id.to_s, nil)
        price.present? ? price.to_m : nil
      end
    end
  end
end

Version data entries

61 entries across 61 versions & 1 rubygems

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