Sha256: 15bdd99301668d1cc4cc74da0bcdc772773efa5aa1430105efb54541595e78ae

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

module Workarea
  decorate Order::Item, with: :flow do
    decorated do
      field :flow_total_value, type: Money
      field :flow_total_price, type: Money

      embeds_many :flow_price_adjustments,
        class_name: 'Workarea::PriceAdjustment',
        extend: PriceAdjustmentExtension
    end

    def reset_price_adjustments
      __build__(:price_adjustments, [], relations["price_adjustments"])
    end

    def reset_flow_price_adjustments
      __build__(:flow_price_adjustments, [], relations["flow_price_adjustments"])
    end

    # Adds a flow price adjustment to the item. Does not persist.
    #
    # @return [self]
    #
    def adjust_flow_pricing(options = {})
      flow_price_adjustments.build(options)
    end

    # The flow unit price of the item including all currently attached
    # flow price adjustments.
    #
    # @return [Money]
    #
    def current_flow_unit_price
      return 0.to_m(order.currency) if flow_price_adjustments.blank?

      flow_price_adjustments
        .adjusting('item')
        .map(&:unit)
        .sum
        .to_m(order.currency)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
workarea-flow_io-1.2.1 app/models/workarea/order/item.decorator