Example #1
0
    def get_package(country="GB",
                    package_type_code='02',
                    weight='14.1',
                    dimensions=None):
        """UPS really expects units that are used in the country
        
        :param package_type_code: Str of the Code
        :param weight: Str eg '14.1' 
        :param dimensions: A dict with length, width and height
            eg {'length': 10, 'width': 10, 'height': 10}
        """
        if dimensions is None:
            dimensions = {
                'length': '10',
                'width': '10',
                'height': '10',
            }
        if country == "GB":
            package_weight = ShipmentConfirm.package_weight_type(
                Weight=weight, Code="KGS", Description="Kilograms")
            dimensions = ShipmentConfirm.dimensions_type(
                Code="CM",
                Length=dimensions['length'],
                Width=dimensions['width'],
                Height=dimensions['height'],
            )
        elif country == "US":
            package_weight = ShipmentConfirm.package_weight_type(
                Weight=weight, Code="LBS", Description="Pounds")
            dimensions = ShipmentConfirm.dimensions_type(
                Code="IN",
                Length=dimensions['length'],
                Width=dimensions['width'],
                Height=dimensions['height'],
            )
        else:
            raise Exception("This country is not supported")

        package_type = ShipmentConfirm.packaging_type(Code=package_type_code)

        return ShipmentConfirm.package_type(
            package_type,
            package_weight,
            dimensions,
        )
Example #2
0
    def _add_packages(self, cursor, user, register_id, context=None):
        """
        Adds the UPS style packages and return the XML element

        :param cursor: Database Cursor
        :param user: ID of User
        :param register_id: Shipment Register ID
        :param context: Context directly uses active id.
        """
        company_obj = self.pool.get('res.company')

        packages = []
        ups_uoms = company_obj.get_ups_uoms(cursor, user, context)
        register_record = self.browse(cursor, user, register_id, context)

        for package in register_record.package_det:
            package_type = ShipmentConfirm.packaging_type(
                Code=package.package_type.code)
            package_weight = ShipmentConfirm.package_weight_type(
                Weight=str(package.weight),
                Code=ups_uoms[0],
                Description=package.description or 'None')
            package_service_options = \
                ShipmentConfirm.package_service_options_type(
                    ShipmentConfirm.insured_value_type(
                        MonetaryValue=str(package.insured_value) or ''))
            if package.length and package.height and package.width:
                package_dimension = ShipmentConfirm.dimensions_type(
                    Code=ups_uoms[1],
                    Length=str(package.length),
                    Height=str(package.height),
                    Width=str(package.width),
                    Description=package.description or 'None')
            else:
                raise osv.except_osv(('Error : '),
                                     ("Package Dimensions are required"))
            package_container = ShipmentConfirm.package_type(
                package_type, package_weight, package_dimension,
                package_service_options)
            packages.append(package_container)
        shipment_service = ShipmentConfirm.shipment_service_option_type(
            SaturdayDelivery=1 if register_record.saturday_delivery \
            else 'None')
        return (packages, shipment_service)
Example #3
0
    def get_package(country="GB", package_type_code='02', 
            weight='14.1', dimensions=None):
        """UPS really expects units that are used in the country
        
        :param package_type_code: Str of the Code
        :param weight: Str eg '14.1' 
        :param dimensions: A dict with length, width and height
            eg {'length': 10, 'width': 10, 'height': 10}
        """
        if dimensions is None:
            dimensions = {
                'length': '10',
                'width': '10',
                'height': '10',
                }
        if country == "GB":
            package_weight = ShipmentConfirm.package_weight_type(
                Weight=weight, Code="KGS", Description="Kilograms")
            dimensions = ShipmentConfirm.dimensions_type(
                Code="CM", 
                Length=dimensions['length'], 
                Width=dimensions['width'], 
                Height=dimensions['height'],
                )
        elif country == "US":
            package_weight = ShipmentConfirm.package_weight_type(
                Weight=weight, Code="LBS", Description="Pounds")
            dimensions = ShipmentConfirm.dimensions_type(
                Code="IN", 
                Length=dimensions['length'], 
                Width=dimensions['width'], 
                Height=dimensions['height'],
                )
        else:
            raise Exception("This country is not supported")

        package_type = ShipmentConfirm.packaging_type(Code=package_type_code)

        return ShipmentConfirm.package_type(
            package_type,
            package_weight,
            dimensions,
            )
    def _add_packages(self, cursor, user, register_id, context=None):
        """
        Adds the UPS style packages and return the XML element

        :param cursor: Database Cursor
        :param user: ID of User
        :param register_id: Shipment Register ID
        :param context: Context directly uses active id.
        """
        company_obj = self.pool.get('res.company')

        packages = []
        ups_uoms = company_obj.get_ups_uoms(cursor, user, context)
        register_record = self.browse(cursor, user, register_id, context)

        for package in register_record.package_det:
            package_type = ShipmentConfirm.packaging_type(
                Code=package.package_type.code)
            package_weight = ShipmentConfirm.package_weight_type(
                Weight=str(package.weight), Code=ups_uoms[0],
                Description=package.description or 'None')
            package_service_options = \
                ShipmentConfirm.package_service_options_type(
                    ShipmentConfirm.insured_value_type(
                        MonetaryValue=str(package.insured_value) or ''))
            if package.length and package.height and package.width:
                package_dimension = ShipmentConfirm.dimensions_type(
                    Code=ups_uoms[1], Length=str(package.length),
                    Height=str(package.height), Width=str(package.width),
                    Description=package.description or 'None')
            else:
                raise osv.except_osv(('Error : '),
                    ("Package Dimensions are required"))
            package_container = ShipmentConfirm.package_type(
                package_type,
                package_weight,
                package_dimension,
                package_service_options)
            packages.append(package_container)
        shipment_service = ShipmentConfirm.shipment_service_option_type(
            SaturdayDelivery=1 if register_record.saturday_delivery \
            else 'None')
        return (packages, shipment_service)
Example #5
0
    def _add_packages(self, cr, uid, omni, package, weight, context=None):
        """
        Adds the UPS style packages and return the XML element

        """
        picking_obj = self.pool.get('stock.picking')
        package_obj = self.pool.get('stock.out.package')

        ups_package = None
        omni_obj = self.pool.get('omniship')
        ups_uoms = omni_obj.get_ups_uoms(cr, uid, omni, context)

        #Solves a bug where weight is rejected by UPS api for being too low
        if weight < 0.5:
            weight = 0.5

        package_type = ShipmentConfirm.packaging_type(Code='02')

        package_weight = ShipmentConfirm.package_weight_type(
            Weight=str(weight), Code=ups_uoms[0], Description='None')

        #Shipment References
        ref1 = str(12345)
        package_referencenumber1 = \
            ShipmentConfirm.reference_type(Code='02', Value=ref1)

        #Ignore ref2 for now
        #       ref2 = str(package.move_id.product_id.sku)
        #      package_referencenumber2 = \
        #         ShipmentConfirm.reference_type(Code='02', Value=ref2)

        #REVIEW: Value set to 0
        package_service_options = \
            ShipmentConfirm.package_service_options_type(
                ShipmentConfirm.insured_value_type(
                    MonetaryValue='0'))

        if package.length > 0.1 and package.width > 0.1 and package.height > 0.1:
            length = package.length
            width = package.width
            height = package.height

        elif package.shape_dimension:
            dims = package.shape_dimension
            length = dims.length
            width = dims.width
            height = dims.height

        else:
            length = 1.0
            width = 1.0
            height = 1.0

        package_dimension = ShipmentConfirm.dimensions_type(Code=ups_uoms[1],
                                                            Length=str(length),
                                                            Height=str(height),
                                                            Width=str(width),
                                                            Description='None')

        xml_package = ShipmentConfirm.package_type(package_type,
                                                   package_weight,
                                                   package_dimension,
                                                   package_service_options,
                                                   package_referencenumber1)
        #    package_referencenumber2)

        shipment_service = ShipmentConfirm.shipment_service_option_type(
            SaturdayDelivery='None')

        return ([xml_package], shipment_service)
Example #6
0
    def _add_packages(self, cr, uid, omni, package, weight, context=None):
        """
        Adds the UPS style packages and return the XML element

        """
	picking_obj = self.pool.get('stock.picking')
	package_obj = self.pool.get('stock.out.package')

	ups_package = None
	omni_obj = self.pool.get('omniship')
        ups_uoms = omni_obj.get_ups_uoms(cr, uid, omni, context)

	#Solves a bug where weight is rejected by UPS api for being too low
	if weight < 0.5:
	    weight = 0.5

        package_type = ShipmentConfirm.packaging_type(
            Code='02')

        package_weight = ShipmentConfirm.package_weight_type(
            Weight=str(weight), Code=ups_uoms[0],
            Description='None')

	#Shipment References
	ref1 = str(12345)
	package_referencenumber1 = \
	    ShipmentConfirm.reference_type(Code='02', Value=ref1)

	#Ignore ref2 for now
#       ref2 = str(package.move_id.product_id.sku)
 #      package_referencenumber2 = \
  #         ShipmentConfirm.reference_type(Code='02', Value=ref2)


	#REVIEW: Value set to 0
        package_service_options = \
            ShipmentConfirm.package_service_options_type(
                ShipmentConfirm.insured_value_type(
                    MonetaryValue='0'))

        if ups_package and ups_package.length and ups_package.height and ups_package.width:

            package_dimension = ShipmentConfirm.dimensions_type(
                Code=ups_uoms[1], Length=str(ups_package.length),
                Height=str(ups_package.height), Width=str(ups_package.width),
                Description='None')
        else:
	    #Hardcode a failsafe here so there are no complaints!
            package_dimension = ShipmentConfirm.dimensions_type(
                Code=ups_uoms[1], Length=str(6.0),
                Height=str(6.0), Width=str(6.0),
                Description='None')

        xml_package = ShipmentConfirm.package_type(
            package_type,
            package_weight,
            package_dimension,
            package_service_options,
	    package_referencenumber1)
	#    package_referencenumber2)

        shipment_service = ShipmentConfirm.shipment_service_option_type(
            SaturdayDelivery='None')
        return ([xml_package], shipment_service)