Add get_vendor_items() and get_vendor_item() methods for web API

This commit is contained in:
Lance Edgar 2020-09-04 19:07:41 -05:00
parent 963f544b02
commit 286df47c22

View file

@ -421,3 +421,46 @@ class CoreWebAPI(object):
response = self.post(params)
result = self.parse_response(response)
return json.loads(result)
def get_vendor_items(self, **columns):
"""
Fetch some or all of VendorItem records from CORE.
:returns: A (potentially empty) list of vendor item dict records.
To fetch all vendor items::
api.get_vendor_items()
To fetch only products with brand name "Braggs"::
api.get_vendor_items(brand='Braggs')
"""
params = {
'entity': 'VendorItems',
'submethod': 'get',
'columns': columns,
}
response = self.post(params)
result = self.parse_response(response)
return [json.loads(rec) for rec in result]
def get_vendor_item(self, upc, vendorID, **columns):
"""
Fetch an existing VendorItem record from CORE.
:returns: Either a vendor item dict record, or ``None``.
"""
columns['upc'] = upc
columns['vendorID'] = vendorID
params = {
'entity': 'VendorItems',
'submethod': 'get',
'columns': columns,
}
response = self.post(params)
result = self.parse_response(response)
if result:
if len(result) > 1:
log.warning("CORE API returned %s VendorItem results", len(result))
return json.loads(result[0])