Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions inventree/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import json
import logging
import requests
import os

from . import api as inventree_api

INVENTREE_PYTHON_VERSION = "0.17.1"
INVENTREE_PYTHON_VERSION = "0.17.2"


logger = logging.getLogger('inventree')
Expand Down Expand Up @@ -231,10 +232,21 @@ def list(cls, api, **kwargs):
else:
url = cls.URL

response = api.get(url=url, params=kwargs)
try:
response = api.get(url=url, params=kwargs)
except requests.exceptions.HTTPError as e:
logger.error(f"Error during list request: {e}")
# Return an empty list

raise_error = kwargs.get('raise_error', False)

if raise_error:
raise e
else:
return []

if response is None:
return None
return []

items = []

Expand Down
37 changes: 37 additions & 0 deletions test/test_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,43 @@ def test_po_attachment(self):
attachments = po.getAttachments()
self.assertEqual(len(attachments), 3)

def test_invalid_list(self):
"""Test list with an invalid parameter.

Ref: https://github.com/inventree/inventree-python/issues/246
"""

from inventree.project_code import ProjectCode

results = order.PurchaseOrder.list(self.api, project_code=999999999)
self.assertEqual(len(results), 0)

# Try the same again, but raise the eror
with self.assertRaises(HTTPError):
results = order.PurchaseOrder.list(
self.api,
project_code=999999999,
raise_error=True
)

# Find a valid project code
n = ProjectCode.count(self.api)

# Create a new project code
pc = ProjectCode.create(self.api, {
'code': f"TEST-{n+1}",
'description': 'Test project code',
})

# Attach project code to an order
po = order.PurchaseOrder.list(self.api, limit=1)[0]
po.save({'project_code': pc.pk})

# Now, list orders with the project code
results = order.PurchaseOrder.list(self.api, project_code=pc.pk)
self.assertEqual(len(results), 1)
self.assertEqual(results[0].pk, po.pk)


class SOTest(InvenTreeTestCase):
"""
Expand Down
Loading