Sha256: 9796215e7d8e8af55682179a15f5545b23fc268216f5dd57f8d3f64aa3df48d1

Contents?: true

Size: 1007 Bytes

Versions: 1

Compression:

Stored size: 1007 Bytes

Contents

module Workarea
  module FlowIo
    class FulfillmentCancellationForm
      def self.from(id:, quantities:)
        order = Workarea::Order.find id

        new(order: order, quantities: quantities).to_flow_model
      end

      attr_reader :order, :quantities

      def initialize(order:, quantities:)
        @order = order
        @quantities = quantities
      end

      # @return ::Io::Flow::V0::Models::FulfillmentCancellationForm
      def to_flow_model
        ::Io::Flow::V0::Models::FulfillmentCancellationForm.new(
          reason: "consumer_requested",
          lines: lines
        )
      end

      private

        def lines
          @lines ||= quantities.map do |order_item_id, quantity|
            order_item = order.items.detect { |item| item.id.to_s == order_item_id.to_s }
            next unless order_item.present?

            {
              item_number: order_item.sku,
              quantity: quantity.to_i
            }
          end.compact
        end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
workarea-flow_io-1.2.1 app/services/workarea/flow_io/fulfillment_cancellation_form.rb