diff options
author | Filipp Lepalaan <f@230.to> | 2013-05-15 11:47:46 +0300 |
---|---|---|
committer | Filipp Lepalaan <f@230.to> | 2013-05-15 11:47:46 +0300 |
commit | 47db98b2449009f8bf80fe9d30fb6bfe4a331341 (patch) | |
tree | ac6a23f620cec675c87a8421b40a4a21b2b2c1cc | |
parent | 28b982e69b87c57d5d520b59c68f7bc32bbf9ea4 (diff) | |
download | py-gsxws-47db98b2449009f8bf80fe9d30fb6bfe4a331341.tar.gz py-gsxws-47db98b2449009f8bf80fe9d30fb6bfe4a331341.tar.bz2 py-gsxws-47db98b2449009f8bf80fe9d30fb6bfe4a331341.zip |
Fixed stocking orders
-rw-r--r-- | gsxws/orders.py | 57 | ||||
-rw-r--r-- | gsxws/parts.py | 20 |
2 files changed, 58 insertions, 19 deletions
diff --git a/gsxws/orders.py b/gsxws/orders.py index e097cf6..791fe58 100644 --- a/gsxws/orders.py +++ b/gsxws/orders.py @@ -1,23 +1,52 @@ from core import GsxObject +class OrderLine(GsxObject): + partNumber = None + quantity = None + + +class APPOrder(GsxObject): + pass + + class StockingOrder(GsxObject): - def __init__(self, type='stocking', *args, **kwargs): + """ + Description: + The Create Stocking Order API is used to create a stocking order. + The purchase order number, ship-to number of the service provider + and a list of parts are required. + The service account number is obtained from the session. + Quote is obtained for the parts and if it is processed successfully, + a confirmation number, array of parts, sub-total, tax and total price are returned. + The part details also contain the net price and availability. + + Context: + The API can be invoked only after valid authentication. + Authentication generates a session ID that needs to be passed while using this API. + + >>> StockingOrder(purchaseOrderNumber=111, shipToCode=677592).add_part('661-5097', 1).submit() + """ + _namespace = "asp:" + + def __init__(self, *args, **kwargs): super(StockingOrder, self).__init__(*args, **kwargs) - self.data['orderLines'] = list() + self.orderLines = list() def add_part(self, part_number, quantity): - self.data['orderLines'].append({ - 'partNumber': part_number, 'quantity': quantity - }) + self.orderLines.append(OrderLine(partNumber=part_number, quantity=quantity)) + return self def submit(self): - dt = CLIENT.factory.create('ns1:createStockingOrderRequestType') - dt.userSession = SESSION - dt.orderData = self.data - - try: - result = CLIENT.service.CreateStockingOrder(dt) - return result.orderConfirmation - except suds.WebFault, e: - raise GsxError(fault=e) + self._submit("orderData", "CreateStockingOrder", "orderConfirmation") + return self._req.objects[0] + + +if __name__ == '__main__': + import sys + import doctest + import logging + from core import connect + logging.basicConfig(level=logging.DEBUG) + connect(*sys.argv[1:5]) + doctest.testmod() diff --git a/gsxws/parts.py b/gsxws/parts.py index a371ea3..536c6aa 100644 --- a/gsxws/parts.py +++ b/gsxws/parts.py @@ -1,11 +1,19 @@ import urllib import tempfile + +from lookups import Lookup from core import GsxObject, GsxError class Part(GsxObject): + """ + A service part + + >>> Part('922-7913').lookup().stockPrice + 6.16 + """ def lookup(self): - lookup = Lookup(**self.data) + lookup = Lookup(**self._data) return lookup.parts() def fetch_image(self): @@ -15,19 +23,21 @@ class Part(GsxObject): if self.partNumber is None: raise GsxError("Cannot fetch part image without part number") - image = '%s_350_350.gif' % self.partNumber - url = 'https://km.support.apple.com.edgekey.net/kb/imageService.jsp?image=%s' % image + image = "%s_350_350.gif" % self.partNumber + url = "https://km.support.apple.com.edgekey.net/kb/imageService.jsp?image=%s" % image tmpfile = tempfile.mkstemp(suffix=image) try: return urllib.urlretrieve(url, tmpfile[1])[0] except Exception, e: - raise GsxError('Failed to fetch part image: %s' % e) + raise GsxError("Failed to fetch part image: %s" % e) if __name__ == '__main__': + import sys import doctest + import logging from core import connect logging.basicConfig(level=logging.DEBUG) - connect(*sys.argv[1:4]) + connect(*sys.argv[1:5]) doctest.testmod() |