Exemplo n.º 1
0
    def create_shipment_service(self, credentials, from_address_doc, to_address_doc, \
     from_country_doc, to_country_doc, transporter_doc, contact_doc):
        from fedex.services.ship_service import FedexProcessShipmentRequest
        customer_transaction_id = self.name  # Optional transaction_id
        shipment = FedexProcessShipmentRequest(credentials, \
         customer_transaction_id=customer_transaction_id)
        self.set_shipment_details(shipment, credentials, transporter_doc)
        shipper_details = self.set_shipper_info(shipment, from_address_doc,
                                                credentials)
        recipient_details = self.set_recipient_info(shipment, to_address_doc,
                                                    credentials)
        self.set_fedex_label_info(shipment)
        self.set_commodities_info(self, shipment)
        self.set_commercial_invoice_info(shipment)
        #self.set_email_notification(shipment, from_address_doc, to_address_doc, contact_doc)

        pkg_count = self.total_handling_units
        for index, pkg in enumerate(self.shipment_package_details):
            pkg_doc = frappe.get_doc("Shipment Package", pkg.shipment_package)
            if index:
                shipment.RequestedShipment.MasterTrackingId.TrackingNumber = self.awb_number
                shipment.RequestedShipment.MasterTrackingId.TrackingIdType.value = \
                 transporter_doc.type_of_service
                self.set_package_data(pkg, pkg_doc, shipment, index + 1)
            else:
                shipment.RequestedShipment.TotalWeight.Units = self.uom_mapper.get(
                    self.weight_uom)
                shipment.RequestedShipment.TotalWeight.Value = self.total_weight
                self.set_package_data(pkg, pkg_doc, shipment, index + 1)
                shipment.send_validation_request()
            shipment.send_request()

            self.validate_fedex_shipping_response(shipment, pkg.idx)
            tracking_id = shipment.response.CompletedShipmentDetail.CompletedPackageDetails[
                0].TrackingIds[0].TrackingNumber
            if index == 0:
                self.awb_number = tracking_id
            self.status = "Booked"
            self.set_package_details(pkg, cstr(shipment.response), tracking_id)
            self.store_label(self, shipment, tracking_id, self.doctype,
                             self.name)
            self.save()
        return shipment
	def create_shipment_service(self, credentials, from_address_doc, to_address_doc, \
		from_country_doc, to_country_doc, transporter_doc, contact_doc):
		from fedex.services.ship_service import FedexProcessShipmentRequest
		customer_transaction_id = self.name  # Optional transaction_id
		shipment = FedexProcessShipmentRequest(credentials, \
			customer_transaction_id=customer_transaction_id)
		self.set_shipment_details(shipment, credentials, transporter_doc)
		shipper_details =  self.set_shipper_info(shipment, from_address_doc, credentials)
		recipient_details = self.set_recipient_info(shipment, to_address_doc, credentials)
		self.set_fedex_label_info(shipment)
		self.set_commodities_info(self, shipment)
		self.set_commercial_invoice_info(shipment)
		#self.set_email_notification(shipment, from_address_doc, to_address_doc, contact_doc)
		
		pkg_count = self.total_handling_units
		for index, pkg in enumerate(self.shipment_package_details):
			pkg_doc = frappe.get_doc("Shipment Package", pkg.shipment_package)
			if index:
					shipment.RequestedShipment.MasterTrackingId.TrackingNumber = self.awb_number
					shipment.RequestedShipment.MasterTrackingId.TrackingIdType.value = \
						transporter_doc.type_of_service
					self.set_package_data(pkg, pkg_doc, shipment, index + 1)
			else:
				shipment.RequestedShipment.TotalWeight.Units = self.uom_mapper.get(self.weight_uom)
				shipment.RequestedShipment.TotalWeight.Value = self.total_weight
				self.set_package_data(pkg, pkg_doc, shipment, index + 1)
				shipment.send_validation_request()
			shipment.send_request()

			self.validate_fedex_shipping_response(shipment, pkg.idx)
			tracking_id = shipment.response.CompletedShipmentDetail.CompletedPackageDetails[0].TrackingIds[0].TrackingNumber
			if index == 0:
				self.awb_number = tracking_id
			self.status = "Booked"
			self.set_package_details(pkg, cstr(shipment.response), tracking_id)
			self.store_label(self, shipment, tracking_id, self.doctype, self.name)
			self.save()
		return shipment
Exemplo n.º 3
0
# increments the package count and total weight of the shipment for you.
shipment.add_package(package1)

# If you'd like to see some documentation on the ship service WSDL, un-comment
# this line. (Spammy).
# print shipment.client

# Un-comment this to see your complete, ready-to-send request as it stands
# before it is actually sent. This is useful for seeing what values you can
# change.
print shipment.RequestedShipment

# If you want to make sure that all of your entered details are valid, you
# can call this and parse it just like you would via send_request(). If
# shipment.response.HighestSeverity == "SUCCESS", your shipment is valid.
shipment.send_validation_request()

# Fires off the request, sets the 'response' attribute on the object.
# shipment.send_request()

# This will show the reply to your shipment being sent. You can access the
# attributes through the response attribute on the request object. This is
# good to un-comment to see the variables returned by the Fedex reply.
# print shipment.response

# Here is the overall end result of the query.
print "HighestSeverity:", shipment.response.HighestSeverity
# Getting the tracking number from the new shipment.
print "Tracking #:", shipment.response.CompletedShipmentDetail.CompletedPackageDetails[0].TrackingIds[0].TrackingNumber
# Net shipping costs.
print "Net Shipping Cost (US$):", shipment.response.CompletedShipmentDetail.CompletedPackageDetails[0].PackageRating.PackageRateDetails[0].NetCharge.Amount
Exemplo n.º 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
Exemplo n.º 5
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