def test0005_label_request(self): label_request = LabelRequest() shipping_label_api = ShippingLabelAPI( label_request=label_request, weight_oz=10, partner_customer_id=1, partner_transaction_id=1020, requesterid=REQUESTER_ID, accountid=ACCOUNT_ID, passphrase=PASSPHRASE, test=True, ) shipping_label_api.to_xml() # # Now try to fetch label # self.assertRaises(RequestError, shipping_label_api.send_request) print "Excpected Error: %s" % shipping_label_api.error from_address = FromAddress( FromName="John Doe", ReturnAddress1="123 Main Street", FromCity="Boise", FromState="ID", FromPostalCode="83702", FromZIP4="7261", FromPhone="8005551212" ) to_address = ToAddress( ToName="Amine Khechfe", ToCompany="Endicia", ToAddress1="247 High Street", ToCity="Palo Alto", ToState="CA", ToPostalCode="84301", ToZIP4="0000", ToDeliveryPoint="00", ToPhone="8005763279" ) shipping_label_api.add_data(from_address.data) shipping_label_api.add_data(to_address.data) response = shipping_label_api.send_request() print shipping_label_api.to_xml() assert shipping_label_api.success == True res = objectify_response(response) pic_number = res.TrackingNumber filename = '/tmp/' + str(res.TrackingNumber) + '.gif' f = open(filename, 'wb') f.write(base64.decodestring(str(res.Base64LabelImage))) f.close() print "New Label at: %s" % filename
def test0005_label_request(self): label_request = LabelRequest() shipping_label_api = ShippingLabelAPI( label_request=label_request, weight_oz=10, partner_customer_id=1, partner_transaction_id=1020, requesterid=REQUESTER_ID, accountid=ACCOUNT_ID, passphrase=PASSPHRASE, test=True, ) shipping_label_api.to_xml() # # Now try to fetch label # self.assertRaises(RequestError, shipping_label_api.send_request) print "Excpected Error: %s" % shipping_label_api.error from_address = FromAddress(FromName="John Doe", ReturnAddress1="123 Main Street", FromCity="Boise", FromState="ID", FromPostalCode="83702", FromZIP4="7261", FromPhone="8005551212") to_address = ToAddress(ToName="Amine Khechfe", ToCompany="Endicia", ToAddress1="247 High Street", ToCity="Palo Alto", ToState="CA", ToPostalCode="84301", ToZIP4="0000", ToDeliveryPoint="00", ToPhone="8005763279") shipping_label_api.add_data(from_address.data) shipping_label_api.add_data(to_address.data) response = shipping_label_api.send_request() print shipping_label_api.to_xml() assert shipping_label_api.success == True res = objectify_response(response) pic_number = res.TrackingNumber filename = '/tmp/' + str(res.TrackingNumber) + '.gif' f = open(filename, 'wb') f.write(base64.decodestring(str(res.Base64LabelImage))) f.close() print "New Label at: %s" % filename
def test_pmi(self): """ Test creating a PMI shipment """ label_request = LabelRequest() shipping_label_api = ShippingLabelAPI( label_request=label_request, weight_oz=10, partner_customer_id=1, partner_transaction_id=1020, requesterid=REQUESTER_ID, accountid=ACCOUNT_ID, passphrase=PASSPHRASE, test=True, mail_class='PriorityMailInternational', EelPfc='Testing', CustomsCertify='TRUE', CustomsSigner='John', ) # A US address to an IN address from_address = self.make_from_address() to_address = self.make_to_address('IN') shipping_label_api.add_data(from_address.data) shipping_label_api.add_data(to_address.data) customs_item1 = [ Element('Description', 'My Beautiful Shoes'), Element('Quantity', 1), Element('Weight', 10), Element('Value', 50), ] customs_item2 = [ Element('Description', 'My Beautiful Dress'), Element('Quantity', 1), Element('Weight', 10), Element('Value', 50), ] shipping_label_api.add_data({ 'customsinfo': [ Element('CustomsItems', [ Element('CustomsItem', customs_item1), Element('CustomsItem', customs_item2) ]), Element('EelPfc', 'Testing'), Element('ContentsType', 'Merchandise') ], 'EelPfc': 'Testing', 'ValidateAddress': 'FALSE', 'Value': '100.00', 'Description': 'Some Fancy Stuffs', 'LabelSubtype': 'Integrated', 'IntegratedFormType': 'Form2976', 'CustomsCertify': 'TRUE', 'CustomsSigner': 'John', }) print shipping_label_api.to_xml() response = shipping_label_api.send_request() assert shipping_label_api.success == True parsed_response = parse_response(response, shipping_label_api.namespace) print parsed_response.keys() filename = '/tmp/' + parsed_response['TrackingNumber'] + '.gif' f = open(filename, 'wb') f.write(base64.decodestring(parsed_response['Base64LabelImage'])) f.close() print "New Label at: %s" % filename
def make_endicia_labels(self): """ Make labels for the given shipment :return: Tracking number as string """ Attachment = Pool().get('ir.attachment') EndiciaConfiguration = Pool().get('endicia.configuration') if self.state not in ('packed', 'done'): self.raise_user_error('invalid_state') if not ( self.carrier and self.carrier.carrier_cost_method == 'endicia' ): self.raise_user_error('wrong_carrier') if self.tracking_number: self.raise_user_error('tracking_number_already_present') endicia_credentials = EndiciaConfiguration(1).get_endicia_credentials() if not self.endicia_mailclass: self.raise_user_error('mailclass_missing') mailclass = self.endicia_mailclass.value label_request = LabelRequest( Test=endicia_credentials.is_test and 'YES' or 'NO', LabelType=( 'International' in mailclass ) and 'International' or 'Default', # TODO: Probably the following have to be configurable ImageFormat="PNG", LabelSize="6x4", ImageResolution="203", ImageRotation="Rotate270", ) # Endicia only support 1 decimal place in weight weight_oz = "%.1f" % self.weight 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=mailclass, MailpieceShape=self.endicia_mailpiece_shape, accountid=endicia_credentials.account_id, requesterid=endicia_credentials.requester_id, passphrase=endicia_credentials.passphrase, test=endicia_credentials.is_test, ) 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, }) 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,))
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,))
def make_endicia_labels(self): """ Make labels for the given shipment :return: Tracking number as string """ Attachment = Pool().get('ir.attachment') if self.state not in ('packed', 'done'): self.raise_user_error('invalid_state') if not (self.carrier and self.carrier.carrier_cost_method == 'endicia'): self.raise_user_error('wrong_carrier') if self.tracking_number: self.raise_user_error('tracking_number_already_present') if not self.endicia_mailclass: self.raise_user_error('mailclass_missing') mailclass = self.endicia_mailclass.value label_request = LabelRequest( Test=self.carrier.endicia_is_test and 'YES' or 'NO', LabelType=('International' in mailclass) and 'International' or 'Default', # TODO: Probably the following have to be configurable ImageFormat="PNG", LabelSize="6x4", ImageResolution="203", ImageRotation="Rotate270", ) # Endicia only support 1 decimal place in weight weight_oz = "%.1f" % self.weight 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=mailclass, 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 = self.endicia_mailpiece_shape 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, ))
ACCOUNT_ID = 123456 PASSPHRASE = "PassPhrase" label_request = LabelRequest() shipping_label_api = ShippingLabelAPI( label_request=label_request, weight_oz=10, partner_customer_id=1, partner_transaction_id=1020, requesterid=REQUESTER_ID, accountid=ACCOUNT_ID, passphrase=PASSPHRASE, test=True, ) print shipping_label_api.to_xml() from_address = FromAddress( FromName="John Doe", ReturnAddress1="123 Main Street", FromCity="Boise", FromState="ID", FromPostalCode="83702", FromZIP4="7261", FromPhone="8005551212" ) to_address = ToAddress( ToName="Amine Khechfe", ToCompany="Endicia", ToAddress1="247 High Street", ToCity="Palo Alto",