def cancel(self, tracking_no, **kwargs): delete = FedexDeleteShipmentRequest(self.config) delete.DeletionControlType = "DELETE_ALL_PACKAGES" delete.TrackingId.TrackingNumber = tracking_no try: delete.send_request() return delete.response except Exception as e: raise FedExError(e)
def delete_shipment(self, tracking_id): del_request = FedexDeleteShipmentRequest(self.config_obj) del_request.DeletionControlType = "DELETE_ALL_PACKAGES" del_request.TrackingId.TrackingNumber = tracking_id del_request.TrackingId.TrackingIdType = 'EXPRESS' try: del_request.send_request() except Exception as ex: frappe.throw('Fedex API: ' + cstr(ex)) if del_request.response.HighestSeverity == "SUCCESS": frappe.msgprint( 'Shipment with tracking number %s is deleted successfully.' % tracking_id) else: self.show_notification(del_request) frappe.throw('Canceling of Shipment in Fedex service failed.')
def delete_shipment_service(self, credentials, transporter_doc): from fedex.services.ship_service import FedexDeleteShipmentRequest tracking_id = self.awb_number del_request = FedexDeleteShipmentRequest(credentials) del_request.DeletionControlType = "DELETE_ALL_PACKAGES" del_request.TrackingId.TrackingNumber = tracking_id del_request.TrackingId.TrackingIdType = transporter_doc.type_of_service try: del_request.send_request() except Exception as ex: frappe.throw('Fedex API: ' + cstr(ex)) if del_request.response.HighestSeverity == "SUCCESS": frappe.msgprint('Shipment with tracking number %s is deleted successfully.' % tracking_id) self.remove_tracking_details(del_request) else: self.remove_tracking_details(del_request) self.show_notification(del_request) frappe.msgprint('Canceling of Shipment in Fedex service failed.')
def fedex_cancel_shipment(self, pickings): try: for tracking_ref in pickings.carrier_tracking_ref.split(','): del_request = FedexDeleteShipmentRequest(self.config_fedex()) del_request.DeletionControlType = "DELETE_ALL_PACKAGES" del_request.TrackingId.TrackingNumber = tracking_ref del_request.TrackingId.TrackingIdType = self.fedex_trackingid_type del_request.send_request() assert (del_request.response.HighestSeverity == 'SUCCESS' ), 'ID:{},{}'.format( tracking_ref, del_request.response.Notifications[0].Message) return True except (FedexError, FedexFailure, SchemaValidationError) as f_err: pickings.message_post(body=f_err.value, subject="FedEx Error:") _logger.warning( "---#1 FEDEX Cancel SHIPMENT ERROR-------%r---------------", f_err.value) raise ValidationError(f_err.value) except Exception as e: pickings.message_post(body=e, subject="FedEx Error:") _logger.warning('-#2 FEDEX Cancel SHIPMENT ERROR--%r', e) raise ValidationError(e)
def process_void(self,cr, uid, ids, context=None): do = self.browse(cr, uid, type(ids)==type([]) and ids[0] or ids, context=context) print do.ship_company_code if do.ship_company_code != 'fedex': return super(stock_picking, self).process_void(cr, uid, ids, context=context) if not (do.logis_company and do.logis_company.ship_company_code=='fedex'): return super(stock_picking, self).process_void(cr, uid, ids, context=context) from fedex.config import FedexConfig config_obj = FedexConfig(key=do.logis_company.fedex_key, password=do.logis_company.fedex_password, account_number=do.logis_company.fedex_account_number, meter_number=do.logis_company.fedex_meter_number, use_test_server=do.logis_company.test_mode) from fedex.services.ship_service import FedexDeleteShipmentRequest error = 0 for pack in do.packages_ids: #@todo: Must check the company_code saved in stock.packages it should be 'fedex' if pack.tracking_no: # This is the object that will be handling our tracking request. del_request = FedexDeleteShipmentRequest(config_obj) # Either delete all packages in a shipment, or delete an individual package. # Docs say this isn't required, but the WSDL won't validate without it. # DELETE_ALL_PACKAGES, DELETE_ONE_PACKAGE del_request.DeletionControlType = "DELETE_ALL_PACKAGES" # The tracking number of the shipment to delete. del_request.TrackingId.TrackingNumber = pack.tracking_no # What kind of shipment the tracking number used. # Docs say this isn't required, but the WSDL won't validate without it. # EXPRESS, GROUND, or USPS del_request.TrackingId.TrackingIdType = 'EXPRESS' # Fires off the request, sets the 'response' attribute on the object. del_request.send_request() #@todo: check if some packages is possible to delete and others fails. print "Response...\n", del_request.response if del_request.response.HighestSeverity=="SUCCESS" or (del_request.response.HighestSeverity=="NOTE" and del_request.response.Notifications[0].Code) : self.pool.get('stock.packages').write(cr, uid, pack.id, { 'negotiated_rates' : 0.00, 'shipment_identific_no' :'', 'tracking_no': '', 'tracking_url': '', 'logo' : '', 'ship_message' : 'Shipment Cancelled',}, context=context) else: error=1 # See the response printed out. #print del_request.response if not error: #@todo: check if some packages is possible to delete and others fails. self.write(cr, uid, do.id, {'ship_state' :'draft', 'ship_message' : 'Shipment has been cancelled.'}, context=context) else : self.write(cr, uid, do.id, { 'ship_message' : 'Shipment cancellation failed.'}, context=context) return True
def test_create_delete_shipment(self): shipment = FedexProcessShipmentRequest(CONFIG_OBJ) shipment.RequestedShipment.DropoffType = 'REGULAR_PICKUP' shipment.RequestedShipment.ServiceType = 'FEDEX_GROUND' shipment.RequestedShipment.PackagingType = 'YOUR_PACKAGING' shipment.RequestedShipment.Shipper.Contact.PersonName = 'Sender Name' shipment.RequestedShipment.Shipper.Contact.PhoneNumber = '9012638716' shipment.RequestedShipment.Shipper.Address.StreetLines = [ 'Address Line 1' ] shipment.RequestedShipment.Shipper.Address.City = 'Herndon' shipment.RequestedShipment.Shipper.Address.StateOrProvinceCode = 'VA' shipment.RequestedShipment.Shipper.Address.PostalCode = '20171' shipment.RequestedShipment.Shipper.Address.CountryCode = 'US' shipment.RequestedShipment.Recipient.Contact.PersonName = 'Recipient Name' shipment.RequestedShipment.Recipient.Contact.PhoneNumber = '9012637906' shipment.RequestedShipment.Recipient.Address.StreetLines = [ 'Address Line 1' ] shipment.RequestedShipment.Recipient.Address.City = 'Herndon' shipment.RequestedShipment.Recipient.Address.StateOrProvinceCode = 'VA' shipment.RequestedShipment.Recipient.Address.PostalCode = '20171' shipment.RequestedShipment.Recipient.Address.CountryCode = 'US' shipment.RequestedShipment.EdtRequestType = 'NONE' shipment.RequestedShipment.ShippingChargesPayment.Payor.ResponsibleParty.AccountNumber \ = CONFIG_OBJ.account_number shipment.RequestedShipment.ShippingChargesPayment.PaymentType = 'SENDER' shipment.RequestedShipment.LabelSpecification.LabelFormatType = 'COMMON2D' shipment.RequestedShipment.LabelSpecification.ImageType = 'PNG' shipment.RequestedShipment.LabelSpecification.LabelStockType = 'PAPER_7X4.75' shipment.RequestedShipment.LabelSpecification.LabelPrintingOrientation = 'BOTTOM_EDGE_OF_TEXT_FIRST' # Use order if setting multiple labels or delete del shipment.RequestedShipment.LabelSpecification.LabelOrder package1_weight = shipment.create_wsdl_object_of_type('Weight') package1_weight.Value = 2.0 package1_weight.Units = "LB" package1 = shipment.create_wsdl_object_of_type( 'RequestedPackageLineItem') package1.PhysicalPackaging = 'ENVELOPE' package1.Weight = package1_weight shipment.add_package(package1) shipment.send_validation_request() shipment.send_request() assert shipment.response assert shipment.response.HighestSeverity in ['SUCCESS', 'WARNING'] track_id = shipment.response.CompletedShipmentDetail.CompletedPackageDetails[ 0].TrackingIds[0].TrackingNumber assert track_id del_shipment = FedexDeleteShipmentRequest(CONFIG_OBJ) del_shipment.DeletionControlType = "DELETE_ALL_PACKAGES" del_shipment.TrackingId.TrackingNumber = track_id del_shipment.TrackingId.TrackingIdType = 'EXPRESS' del_shipment.send_request() assert del_shipment.response
from example_config import CONFIG_OBJ from fedex.services.ship_service import FedexDeleteShipmentRequest from fedex.base_service import FedexError # Un-comment to see the response from Fedex printed in stdout. logging.basicConfig(stream=sys.stdout, level=logging.INFO) # This is the object that will be handling our request. # We're using the FedexConfig object from example_config.py in this dir. del_request = FedexDeleteShipmentRequest(CONFIG_OBJ) # Either delete all packages in a shipment, or delete an individual package. # Docs say this isn't required, but the WSDL won't validate without it. # DELETE_ALL_PACKAGES, DELETE_ONE_PACKAGE del_request.DeletionControlType = "DELETE_ALL_PACKAGES" # The tracking number of the shipment to delete. del_request.TrackingId.TrackingNumber = "794798682968" # '111111111111' will also not delete # What kind of shipment the tracking number used. # Docs say this isn't required, but the WSDL won't validate without it. # EXPRESS, GROUND, or USPS del_request.TrackingId.TrackingIdType = "EXPRESS" # Fires off the request, sets the 'response' attribute on the object. try: del_request.send_request() except FedexError as e: if "Unable to retrieve record" in str(e): print "WARNING: Unable to delete the shipment with the provided tracking number."
""" import logging from example_config import CONFIG_OBJ from fedex.services.ship_service import FedexDeleteShipmentRequest # Set this to the INFO level to see the response from Fedex printed in stdout. logging.basicConfig(level=logging.INFO) # This is the object that will be handling our tracking request. # We're using the FedexConfig object from example_config.py in this dir. del_request = FedexDeleteShipmentRequest(CONFIG_OBJ) # Either delete all packages in a shipment, or delete an individual package. # Docs say this isn't required, but the WSDL won't validate without it. # DELETE_ALL_PACKAGES, DELETE_ONE_PACKAGE del_request.DeletionControlType = "DELETE_ALL_PACKAGES" # The tracking number of the shipment to delete. del_request.TrackingId.TrackingNumber = '794798682968' # What kind of shipment the tracking number used. # Docs say this isn't required, but the WSDL won't validate without it. # EXPRESS, GROUND, or USPS del_request.TrackingId.TrackingIdType = 'EXPRESS' # Fires off the request, sets the 'response' attribute on the object. del_request.send_request() # See the response printed out. print del_request.response
def test_create_delete_shipment(self): shipment = FedexProcessShipmentRequest(CONFIG_OBJ) shipment.RequestedShipment.DropoffType = 'REGULAR_PICKUP' shipment.RequestedShipment.ServiceType = 'FEDEX_GROUND' shipment.RequestedShipment.PackagingType = 'YOUR_PACKAGING' shipment.RequestedShipment.Shipper.Contact.PersonName = 'Sender Name' shipment.RequestedShipment.Shipper.Contact.PhoneNumber = '9012638716' shipment.RequestedShipment.Shipper.Address.StreetLines = ['Address Line 1'] shipment.RequestedShipment.Shipper.Address.City = 'Herndon' shipment.RequestedShipment.Shipper.Address.StateOrProvinceCode = 'VA' shipment.RequestedShipment.Shipper.Address.PostalCode = '20171' shipment.RequestedShipment.Shipper.Address.CountryCode = 'US' shipment.RequestedShipment.Recipient.Contact.PersonName = 'Recipient Name' shipment.RequestedShipment.Recipient.Contact.PhoneNumber = '9012637906' shipment.RequestedShipment.Recipient.Address.StreetLines = ['Address Line 1'] shipment.RequestedShipment.Recipient.Address.City = 'Herndon' shipment.RequestedShipment.Recipient.Address.StateOrProvinceCode = 'VA' shipment.RequestedShipment.Recipient.Address.PostalCode = '20171' shipment.RequestedShipment.Recipient.Address.CountryCode = 'US' shipment.RequestedShipment.EdtRequestType = 'NONE' shipment.RequestedShipment.ShippingChargesPayment.Payor.ResponsibleParty.AccountNumber \ = CONFIG_OBJ.account_number shipment.RequestedShipment.ShippingChargesPayment.PaymentType = 'SENDER' shipment.RequestedShipment.LabelSpecification.LabelFormatType = 'COMMON2D' shipment.RequestedShipment.LabelSpecification.ImageType = 'PNG' shipment.RequestedShipment.LabelSpecification.LabelStockType = 'PAPER_7X4.75' shipment.RequestedShipment.LabelSpecification.LabelPrintingOrientation = 'BOTTOM_EDGE_OF_TEXT_FIRST' del shipment.RequestedShipment.LabelSpecification.LabelOrder package1_weight = shipment.create_wsdl_object_of_type('Weight') package1_weight.Value = 2.0 package1_weight.Units = "LB" package1 = shipment.create_wsdl_object_of_type('RequestedPackageLineItem') package1.PhysicalPackaging = 'ENVELOPE' package1.Weight = package1_weight shipment.add_package(package1) shipment.send_request() assert shipment.response assert shipment.response.HighestSeverity == 'SUCCESS' track_id = shipment.response.CompletedShipmentDetail.CompletedPackageDetails[0].TrackingIds[0].TrackingNumber assert track_id del_shipment = FedexDeleteShipmentRequest(CONFIG_OBJ) del_shipment.DeletionControlType = "DELETE_ALL_PACKAGES" del_shipment.TrackingId.TrackingNumber = track_id del_shipment.TrackingId.TrackingIdType = 'EXPRESS' del_shipment.send_request() assert del_shipment.response