def generate_shipping_labels(self, **kwargs): """ Make labels for the given shipment :return: Tracking number as string """ Attachment = Pool().get('ir.attachment') Tracking = Pool().get('shipment.tracking') Uom = Pool().get('product.uom') if self.carrier_cost_method != 'endicia': return super(ShipmentOut, self).generate_shipping_labels(**kwargs) label_request = LabelRequest( Test=self.carrier.endicia_is_test and 'YES' or 'NO', LabelType=( 'International' in self.carrier_service.code ) and 'International' or 'Default', # TODO: Probably the following have to be configurable ImageFormat="PNG", LabelSize="6x4", ImageResolution="203", ImageRotation="Rotate270", ) try: package, = self.packages except ValueError: self.raise_user_error( "There should be exactly one package to generate USPS label" "\n Multi Piece shipment is not supported yet" ) oz, = Uom.search([('symbol', '=', 'oz')]) # Endicia only support 1 decimal place in weight weight_oz = "%.1f" % Uom.compute_qty( package.weight_uom, package.weight, oz ) shipping_label_request = ShippingLabelAPI( label_request=label_request, weight_oz=weight_oz, partner_customer_id=self.delivery_address.id, partner_transaction_id=self.id, mail_class=self.carrier_service.code, accountid=self.carrier.endicia_account_id, requesterid=self.carrier.endicia_requester_id, passphrase=self.carrier.endicia_passphrase, test=self.carrier.endicia_is_test, ) shipping_label_request.mailpieceshape = package.box_type and \ package.box_type.code # Dimensions required for priority mail class and # all values must be in inches to_uom, = Uom.search([('symbol', '=', 'in')]) from_uom, = Uom.search([('symbol', '=', package.distance_unit.symbol)]) if (package.length and package.width and package.height): length, width, height = package.length, package.width, package.height if from_uom != to_uom: length = "%.1f" % Uom.compute_qty( from_uom, package.length, to_uom ) width = "%.1f" % Uom.compute_qty( from_uom, package.width, to_uom ) height = "%.1f" % Uom.compute_qty( from_uom, package.height, to_uom ) shipping_label_request.mailpiecedimensions = { 'Length': length, 'Width': width, 'Height': height } from_address = self._get_ship_from_address() shipping_label_request.add_data( from_address.address_to_endicia_from_address().data ) shipping_label_request.add_data( self.delivery_address.address_to_endicia_to_address().data ) shipping_label_request.add_data({ 'LabelSubtype': self.endicia_label_subtype, 'IncludePostage': self.endicia_include_postage and 'TRUE' or 'FALSE', }) if self.endicia_label_subtype != 'None': # Integrated form type needs to be sent for international shipments shipping_label_request.add_data({ 'IntegratedFormType': self.endicia_integrated_form_type, }) if self.delivery_address.country.code != 'US': self._update_endicia_item_details(shipping_label_request) # Logging. logger.debug( 'Making Shipping Label Request for' 'Shipment ID: {0} and Carrier ID: {1}' .format(self.id, self.carrier.id) ) logger.debug('--------SHIPPING LABEL REQUEST--------') logger.debug(str(shipping_label_request.to_xml())) logger.debug('--------END REQUEST--------') try: response = shipping_label_request.send_request() except RequestError, error: self.raise_user_error('error_label', error_args=(error.message,))