Sha256: 624a66e8bfd505e8c8a376b1d5fa6b50cb9d474c5c24d0201582cf7028df18e8

Contents?: true

Size: 1.46 KB

Versions: 28

Compression:

Stored size: 1.46 KB

Contents

module Workarea
  module Admin
    class FulfillmentViewModel < ApplicationViewModel
      def order
        options[:order] || OrderViewModel.wrap(Order.find(model.id))
      end

      def packages
        @packages ||= model.packages.map do |package|
          PackageViewModel.new(package, order: order)
        end
      end

      def pending_items
        @pending_items ||= model.pending_items.map do |fulfillment_item|
          next unless order_item = order
            .items
            .detect { |i| i.id.to_s == fulfillment_item.order_item_id }

          FulfillmentItemViewModel.new(
            order_item,
            quantity: fulfillment_item.quantity_pending
          )
        end.compact
      end

      def cancellations
        @cancellations ||= model.canceled_items.map do |fulfillment_item|
          next unless order_item = order
            .items
            .detect { |i| i.id.to_s == fulfillment_item.order_item_id }

          FulfillmentItemViewModel.new(
            order_item,
            quantity: fulfillment_item.quantity_canceled
          )
        end.compact
      end

      def skus
        @skus ||= FulfillmentSkusViewModel.wrap(
          Fulfillment::Sku.in(id: order.items.map(&:sku).uniq).to_a,
          options
        )
      end

      def tokens
        @tokens ||= FulfillmentTokenViewModel.wrap(
          Fulfillment::Token.by_order(order.id).to_a,
          options.merge(order: order)
        )
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
workarea-admin-3.5.27 app/view_models/workarea/admin/fulfillment_view_model.rb
workarea-admin-3.5.26 app/view_models/workarea/admin/fulfillment_view_model.rb
workarea-admin-3.5.25 app/view_models/workarea/admin/fulfillment_view_model.rb
workarea-admin-3.5.23 app/view_models/workarea/admin/fulfillment_view_model.rb
workarea-admin-3.5.22 app/view_models/workarea/admin/fulfillment_view_model.rb
workarea-admin-3.5.21 app/view_models/workarea/admin/fulfillment_view_model.rb
workarea-admin-3.5.20 app/view_models/workarea/admin/fulfillment_view_model.rb
workarea-admin-3.5.19 app/view_models/workarea/admin/fulfillment_view_model.rb
workarea-admin-3.5.18 app/view_models/workarea/admin/fulfillment_view_model.rb
workarea-admin-3.5.17 app/view_models/workarea/admin/fulfillment_view_model.rb
workarea-admin-3.5.16 app/view_models/workarea/admin/fulfillment_view_model.rb
workarea-admin-3.5.15 app/view_models/workarea/admin/fulfillment_view_model.rb
workarea-admin-3.5.14 app/view_models/workarea/admin/fulfillment_view_model.rb
workarea-admin-3.5.13 app/view_models/workarea/admin/fulfillment_view_model.rb
workarea-admin-3.5.12 app/view_models/workarea/admin/fulfillment_view_model.rb
workarea-admin-3.5.11 app/view_models/workarea/admin/fulfillment_view_model.rb
workarea-admin-3.5.10 app/view_models/workarea/admin/fulfillment_view_model.rb
workarea-admin-3.5.9 app/view_models/workarea/admin/fulfillment_view_model.rb
workarea-admin-3.5.8 app/view_models/workarea/admin/fulfillment_view_model.rb
workarea-admin-3.5.7 app/view_models/workarea/admin/fulfillment_view_model.rb