Sha256: 7c7f9e2322efea421811ab0f455fa95aeecd9ccffdac252488c68e359073a22d

Contents?: true

Size: 521 Bytes

Versions: 1

Compression:

Stored size: 521 Bytes

Contents

module Workarea
  decorate OrderMetrics, with: :global_e do
    def all_price_adjustments
      super + @order.discount_adjustments
    end

    def discounts_by(field)
      all_price_adjustments.select(&:discount?).reduce({}) do |memo, price_adjustment|
        next memo unless price_adjustment.data.has_key? 'discount_id'
        discount_id = price_adjustment.data['discount_id']

        memo[discount_id] ||= 0
        memo[discount_id] += price_adjustment.send(field).abs
        memo
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
workarea-global_e-1.3.0 app/queries/workarea/order_metrics.decorator