You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: order_shipping.rb
    path of file: ./repos/solidus/core/app/models/spree
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

# A service layer that handles generating Carton objects when inventory units
# are actually shipped.  It also takes care of things like updating order and
# shipment states and delivering shipment emails as needed.
class Spree::OrderShipping
  def initialize(order)
    @order = order
  end

  # A shortcut method that sh
    
  def ship(inventory_units:, stock_location:, address:, shipping_method:,
           shipped_at: Time.current, external_number: nil, tracking_number: nil, suppress_mailer: false)

    carton = nil

    Spree::InventoryUnit.transaction do
      inventory_units.each(&:ship!)

      carton = Spree::Carton.create!(
        stock_location: stock_location,
        address: address,
        shipping_method: shipping_method,
        inventory_units: inventory_units,
        shipped_at: shipped_at,
        external_number: external_number,
        tracking: tracking_number
      )
    end

    inventory_units.map(&:shipment).uniq.each do |shipment|
      if shipment.inventory_units.reload.all? { |iu| iu.shipped? || iu.canceled? }
        shipment.update!(state: "shipped", shipped_at: Time.current, tracking: tracking_number)
      else
        shipment.update!(tracking: tracking_number)
      end
    end