app/models/order.rb
def create_shipment(user_id, save_to_db = true)

    raise "There are no items in this order" if total_items == 0

    seq = 1
    max_seq = shipments.maximum(:sequence)
    seq = max_seq + 1 unless max_seq.nil?

    shipment = Shipment.new(order_id: id,
                            sequence: seq,
                            recipient_company: shipping_company,
                            recipient_name: shipping_name,
                            recipient_street1: shipping_street1,
                            recipient_street2: shipping_street2,
                            recipient_city: shipping_city,
                            recipient_state: shipping_state,
                            recipient_zip: shipping_zip,
                            recipient_country: shipping_country,
                            status: 'pending')

    loc_id = Cache.setting(domain_id, :shipping, "Ship From Location ID")
    loc = Location.find(loc_id) if loc_id

    unless loc.nil?
      shipment.assign_attributes(ship_from_company: loc.name,
                                 ship_from_street1: loc.street1,
                                 ship_from_street2: loc.street2,
                                 ship_from_city: loc.city,
                                 ship_from_state: loc.state,
                                 ship_from_zip: loc.zip,
                                 ship_from_country: loc.country,
                                 ship_from_email: loc.email,
                                 ship_from_phone: loc.phone)
    end

    # set invoice amount
    # shipment.invoice_amount = shipment.order.total if seq == 1

    # build the shipment items                
    items.each do |item|

      # regular order item, not a daily deal
      if item.product_id
        shipment.items.build(order_item_id: item.id,
                             quantity: item.quantity_accepted - item.quantity_shipped)

      elsif item.daily_deal_id

        if item.custom_text.blank?
          item.daily_deal.items.each do |di|
            shipment.items.build(order_item_id: item.id,
                                 quantity: item.quantity * di.quantity)
          end
        else
          # user may have selected a specific item from drowndown
          p = Product.find_by(item_number: item.custom_text.split(":").first)
          shipment.items.build(order_item_id: item.id, quantity: item.quantity)
        end

      end

    end

    if save_to_db && shipment.save!
      OrderHistory.create(order_id: id, user_id: user_id, event_type: :shipment_created,
                          system_name: 'Rhombus', identifier: shipment.id, comment: "shipment created: #{shipment}")
    end

    shipment
  end
# create shipment for the order.  doesn't take inventory into consideration currently
create shipment for the order.  doesn't take inventory into consideration currently
create shipment for the order . doesn ' t take inventory into consideration currently
def create_shipment(user_id, save_to_db = true)
    raise "There are no items in this order" if total_items == 0
    seq = 1
    max_seq = shipments.maximum(:sequence)
    seq = max_seq + 1 unless max_seq.nil?
    shipment = Shipment.new(order_id: id,
                            sequence: seq,
                            recipient_company: shipping_company,
                            recipient_name: shipping_name,
                            recipient_street1: shipping_street1,
                            recipient_street2: shipping_street2,
                            recipient_city: shipping_city,
                            recipient_state: shipping_state,
                            recipient_zip: shipping_zip,
                            recipient_country: shipping_country,
                            status: 'pending')
    loc_id = Cache.setting(domain_id, :shipping, "Ship From Location ID")
    loc = Location.find(loc_id) if loc_id
    unless loc.nil?
      shipment.assign_attributes(ship_from_company: loc.name,
                                 ship_from_street1: loc.street1,
                                 ship_from_street2: loc.street2,
                                 ship_from_city: loc.city,
                                 ship_from_state: loc.state,
                                 ship_from_zip: loc.zip,
                                 ship_from_country: loc.country,
                                 ship_from_email: loc.email,
                                 ship_from_phone: loc.phone)
    end
    items.each do |item|
      if item.product_id
        shipment.items.build(order_item_id: item.id,
                             quantity: item.quantity_accepted - item.quantity_shipped)
      elsif item.daily_deal_id
        if item.custom_text.blank?
          item.daily_deal.items.each do |di|
            shipment.items.build(order_item_id: item.id,
                                 quantity: item.quantity * di.quantity)
          end
        else
          p = Product.find_by(item_number: item.custom_text.split(":").first)
          shipment.items.build(order_item_id: item.id, quantity: item.quantity)
        end
      end
    end
    if save_to_db && shipment.save!
      OrderHistory.create(order_id: id, user_id: user_id, event_type: :shipment_created,
                          system_name: 'Rhombus', identifier: shipment.id, comment: "shipment created: #{shipment}")
    end
    shipment
  end
def create_shipment ( user_id , save_to_db = true ) raise "There are no items in this order" if total_items == 0 seq = 1 max_seq = shipments . maximum ( :sequence ) seq = max_seq + 1 unless max_seq . nil? shipment = Shipment . new ( order_id : id , sequence : seq , recipient_company : shipping_company , recipient_name : shipping_name , recipient_street1 : shipping_street1 , recipient_street2 : shipping_street2 , recipient_city : shipping_city , recipient_state : shipping_state , recipient_zip : shipping_zip , recipient_country : shipping_country , status : 'pending' ) loc_id = Cache . setting ( domain_id , :shipping , "Ship From Location ID" ) loc = Location . find ( loc_id ) if loc_id unless loc . nil? shipment . assign_attributes ( ship_from_company : loc . name , ship_from_street1 : loc . street1 , ship_from_street2 : loc . street2 , ship_from_city : loc . city , ship_from_state : loc . state , ship_from_zip : loc . zip , ship_from_country : loc . country , ship_from_email : loc . email , ship_from_phone : loc . phone ) end items . each do | item | if item . product_id shipment . items . build ( order_item_id : item . id , quantity : item . quantity_accepted - item . quantity_shipped ) elsif item . daily_deal_id if item . custom_text . blank? item . daily_deal . items . each do | di | shipment . items . build ( order_item_id : item . id , quantity : item . quantity * di . quantity ) end else p = Product . find_by ( item_number : item . custom_text . split ( ":" ) . first ) shipment . items . build ( order_item_id : item . id , quantity : item . quantity ) end end end if save_to_db && shipment . save! OrderHistory . create ( order_id : id , user_id : user_id , event_type : :shipment_created , system_name : 'Rhombus' , identifier : shipment . id , comment : "shipment created: #{shipment}" ) end shipment end
create shipment for the order.
create shipment for the order .
# set invoice amount # shipment.invoice_amount = shipment.order.total if seq == 1 # build the shipment items                 # regular order item, not a daily deal # user may have selected a specific item from drowndown
user_id
save_to_db