def track_fedex_shipment(tracking_id, fedex_account): fedex = FedexController(fedex_account) try: response = fedex.track_shipment(tracking_id) return response except Exception, e: frappe.throw(cstr(e))
def validate_postal_code(doc, method): if doc.is_fedex_account: fedex = FedexController(doc.shipment_forwarder) try: fedex.validate_postal_address(doc.shipping_address_name) except Exception, e: frappe.throw(cstr(e))
def schedule_pickup(request_data): request_data = json.loads(request_data) fedex = FedexController(request_data.get("fedex_account")) try: response = fedex.schedule_pickup(request_data) return response except Exception, e: frappe.throw(cstr(e))
def get_fedex_shipment_rate(doc, method): if doc.is_fedex_account: fedex = FedexController(doc.shipment_forwarder) try: rate_request = fedex.get_shipment_rate(doc) set_shipment_rate(doc, rate_request) except Exception, e: print "traceback__________", frappe.get_traceback() frappe.throw(cstr(e))
def get_fedex_shipment_rate(doc, method): if doc.is_fedex_account: so_no = frappe.db.get_value("Delivery Note Item", {"parent": doc.delivery_note}, "against_sales_order") or "" fedex = FedexController(doc.shipment_forwarder) try: rate_request = fedex.get_shipment_rate(doc, so_no) set_shipment_rate(doc, rate_request) except Exception, e: frappe.throw(cstr(e))
def init_fedex_shipment(doc, method): if doc.is_fedex_account and doc.no_of_packages: try: so_no = frappe.db.get_value("Delivery Note Item", {"parent": doc.delivery_note}, "against_sales_order") or "" fedex = FedexController(doc.shipment_forwarder) shipment = fedex.init_shipment(doc) for index, pkg in enumerate(doc.fedex_package_details): if index: shipment.RequestedShipment.MasterTrackingId.TrackingNumber = doc.fedex_tracking_id shipment.RequestedShipment.MasterTrackingId.TrackingIdType.value = 'EXPRESS' fedex.set_package_data(pkg, shipment, index + 1, doc, so_no) else: shipment.RequestedShipment.TotalWeight.Units = uom_mapper.get( doc.gross_weight_uom) shipment.RequestedShipment.TotalWeight.Value = doc.gross_weight_pkg fedex.set_package_data(pkg, shipment, index + 1, doc, so_no) shipment.send_validation_request() shipment.send_request() fedex.validate_fedex_shipping_response(shipment, pkg.fedex_package) tracking_id = shipment.response.CompletedShipmentDetail.CompletedPackageDetails[ 0].TrackingIds[0].TrackingNumber if not index: doc.fedex_tracking_id = tracking_id set_package_details(pkg, cstr(shipment.response), tracking_id) fedex.store_label(shipment, tracking_id, doc.name) except Exception as e: fedex.delete_shipment( doc.fedex_tracking_id) if doc.fedex_tracking_id else "" frappe.throw(cstr(e)) update_shipment_rate(shipment, doc)