lib/friendly_shipping/services/ups/serialize_shipment_confirm_request.rb
# Item options (only necessary for international shipping)
#
# @option description [String] A description of the item for the intl. invoice
# @option commodity_code [String] Commodity code for the item. See https://www.tariffnumber.com/
# @option value [Money] Price of the item
# @option unit_of_item_count [String] What kind of thing is one of this item? Example: Barrel, m3.
#   See UPS docs for codes.
#
Item options (only necessary for international shipping)
Item options ( only necessary for international shipping )
def build_international_forms(xml, shipment, options)
            return unless options.paperless_invoice
            reason_for_export = options.return_service_code ? "RETURN" : options.reason_for_export
            invoice_date = options.invoice_date || Date.current
            xml.InternationalForms do
              xml.FormType('01') 
              xml.InvoiceDate(invoice_date.strftime('%Y%m%d'))
              xml.ReasonForExport(reason_for_export)
              xml.CurrencyCode(options.billing_options.currency || 'USD')
              if options.terms_of_shipment_code
                xml.TermsOfShipment(options.terms_of_shipment_code)
              end
              all_items = shipment.packages.map(&:items).map(&:to_a).flatten
              all_item_options = shipment.packages.flat_map do |package|
                package_options = options.options_for_package(package)
                package.items.flat_map do |item|
                  package_options.options_for_item(item)
                end
              end
              all_items.group_by(&:description).each do |description, items|
                reference_item = items.first
                item_options = all_item_options.detect { |o| o.item_id == reference_item.id } || LabelItemOptions.new(item_id: nil)
                xml.Product do
                  cost = reference_item.cost || Money.new(0, 'USD')
                  xml.Description(description)
                  xml.CommodityCode(item_options.commodity_code)
                  xml.OriginCountryCode(shipment.origin.country.code)
                  xml.Unit do
                    xml.Value(cost * items.length)
                    xml.Number(items.length)
                    xml.UnitOfMeasurement do
                      xml.Code(item_options.product_unit_of_measure_code)
                    end
                  end
                end
              end
            end
          end
def build_international_forms ( xml , shipment , options ) return unless options . paperless_invoice reason_for_export = options . return_service_code ? "RETURN" : options . reason_for_export invoice_date = options . invoice_date || Date . current xml . InternationalForms do xml . FormType ( '01' ) xml . InvoiceDate ( invoice_date . strftime ( '%Y%m%d' ) ) xml . ReasonForExport ( reason_for_export ) xml . CurrencyCode ( options . billing_options . currency || 'USD' ) if options . terms_of_shipment_code xml . TermsOfShipment ( options . terms_of_shipment_code ) end all_items = shipment . packages . map ( & :items ) . map ( & :to_a ) . flatten all_item_options = shipment . packages . flat_map do | package | package_options = options . options_for_package ( package ) package . items . flat_map do | item | package_options . options_for_item ( item ) end end all_items . group_by ( & :description ) . each do | description , items | reference_item = items . first item_options = all_item_options . detect { | o | o . item_id == reference_item . id } || LabelItemOptions . new ( item_id : nil ) xml . Product do cost = reference_item . cost || Money . new ( 0 , 'USD' ) xml . Description ( description ) xml . CommodityCode ( item_options . commodity_code ) xml . OriginCountryCode ( shipment . origin . country . code ) xml . Unit do xml . Value ( cost * items . length ) xml . Number ( items . length ) xml . UnitOfMeasurement do xml . Code ( item_options . product_unit_of_measure_code ) end end end end end end
Item options (only necessary for international shipping)
Item options ( only necessary for international shipping )
# 01 is "Invoice" # This is a group of identically described items # Get the options for this item
xml
<not_specific>
shipment
<not_specific>
options
<not_specific>
description
<not_specific>
A description of the item for the intl. invoice
A description of the item for the intl . invoice
commodity_code
<not_specific>
Commodity code for the item.
Commodity code for the item .
value
<not_specific>
Price of the item
Price of the item
unit_of_item_count
<not_specific>
None