|
| 1 | +""" |
| 2 | +Document Service Module |
| 3 | +
|
| 4 | +This package contains the shipping methods defined by Fedex's |
| 5 | +DocumentService WSDL file. Each is encapsulated in a class for |
| 6 | +easy access. For more details on each, refer to the respective class's |
| 7 | +documentation. |
| 8 | +""" |
| 9 | + |
| 10 | +import datetime |
| 11 | +from ..base_service import FedexBaseService |
| 12 | + |
| 13 | + |
| 14 | +class FedexDocumentServiceRequest(FedexBaseService): |
| 15 | + """ |
| 16 | + This class allows you to submit the document. |
| 17 | + You will need to populate the data structures in self.UploadDocumentsRequest, |
| 18 | + then send the request. |
| 19 | + """ |
| 20 | + |
| 21 | + def __init__(self, config_obj, *args, **kwargs): |
| 22 | + """ |
| 23 | + The optional keyword args detailed on L{FedexBaseService} |
| 24 | + apply here as well. |
| 25 | + @type config_obj: L{FedexConfig} |
| 26 | + @param config_obj: A valid FedexConfig object. |
| 27 | + """ |
| 28 | + |
| 29 | + self._config_obj = config_obj |
| 30 | + |
| 31 | + # Holds version info for the VersionId SOAP object. |
| 32 | + self._version_info = {'service_id': 'cdus', 'major': '11', |
| 33 | + 'intermediate': '0', 'minor': '0'} |
| 34 | + |
| 35 | + self.UploadDocumentsRequest = None |
| 36 | + """@ivar: Holds the UploadDocumentsRequest WSDL object including the shipper, recipient and shipt time.""" |
| 37 | + super(FedexDocumentServiceRequest, self).__init__( |
| 38 | + self._config_obj, 'UploadDocumentService_v11.wsdl', *args, **kwargs) |
| 39 | + """@ivar: Holds the express region code from the config object.""" |
| 40 | + |
| 41 | + def _prepare_wsdl_objects(self): |
| 42 | + """ |
| 43 | + This is the data that will be used to create your shipment. Create |
| 44 | + the data structure and get it ready for the WSDL request. |
| 45 | + """ |
| 46 | + self.UploadDocumentsRequest = self.client.factory.create('UploadDocumentsRequest') |
| 47 | + self.OriginCountryCode =None |
| 48 | + self.DestinationCountryCode =None |
| 49 | + self.Usage ='ELECTRONIC_TRADE_DOCUMENTS'#Default Usage |
| 50 | + self.Documents = [] |
| 51 | + self.UploadDocumentsRequest.Documents = [] |
| 52 | + self.logger.debug(self.UploadDocumentsRequest) |
| 53 | + |
| 54 | + def _assemble_and_send_request(self): |
| 55 | + """ |
| 56 | + Fires off the Fedex request. |
| 57 | +
|
| 58 | + @warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(), |
| 59 | + WHICH RESIDES ON FedexBaseService AND IS INHERITED. |
| 60 | + """ |
| 61 | + |
| 62 | + # Fire off the query. |
| 63 | + return self.client.service.uploadDocuments( |
| 64 | + WebAuthenticationDetail=self.WebAuthenticationDetail, |
| 65 | + ClientDetail=self.ClientDetail, |
| 66 | + TransactionDetail=self.TransactionDetail, |
| 67 | + Version=self.VersionId, |
| 68 | + Documents=self.Documents, |
| 69 | + Usage = self.Usage, |
| 70 | + OriginCountryCode = self.OriginCountryCode, |
| 71 | + DestinationCountryCode = self.DestinationCountryCode, |
| 72 | + ) |
| 73 | + def get_document(self, line_number,customer_reference, |
| 74 | + document_type , file_name, document_content, expiration_date =None |
| 75 | + ): |
| 76 | + document_item = self.client.factory.create('UploadDocumentDetail') |
| 77 | + document_item.LineNumber = line_number |
| 78 | + document_item.CustomerReference = customer_reference |
| 79 | + document_item.DocumentType = document_type |
| 80 | + document_item.FileName = file_name |
| 81 | + document_item.DocumentContent = document_content |
| 82 | + document_item.ExpirationDate = expiration_date |
| 83 | + return document_item |
| 84 | + def add_documents(self, document_item): |
| 85 | + self.Documents.append(document_item) |
0 commit comments