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.')
예제 #2
0
	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.')
예제 #3
0
 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)
예제 #4
0
    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
예제 #5
0
#!/usr/bin/env python
"""
This example shows how to delete existing shipments.
"""
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()