Skip to content

Commit

Permalink
Add function for Part requirements (#173)
Browse files Browse the repository at this point in the history
* Add getRequirements method

* Add tests
  • Loading branch information
miggland committed Mar 2, 2023
1 parent d1f2163 commit 08e143c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions inventree/part.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ def uploadAttachment(self, attachment, comment=''):
part=self.pk
)

def getRequirements(self):
"""
Get required amounts from requirements API endpoint for this part
"""

# Set the url
URL = f"{self.URL}/{self.pk}/requirements/"

# Get data
return self._api.get(URL)


class PartAttachment(inventree.base.Attachment):
""" Class representing a file attachment for a Part """
Expand Down
20 changes: 20 additions & 0 deletions test/test_part.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,26 @@ def test_part_related(self):
with self.assertRaises(HTTPError):
ret = PartRelated.add_related(self.api, parts[3], parts[3])

def test_get_requirements(self):
"""Test getRequirements function for parts"""

# Get first part
prt = Part.list(self.api, limit=1)[0]

# Get requirements list
req = prt.getRequirements()

# Check for expected content
self.assertIsInstance(req, dict)
self.assertIn('available_stock', req)
self.assertIn('on_order', req)
self.assertIn('required_build_order_quantity', req)
self.assertIn('allocated_build_order_quantity', req)
self.assertIn('required_sales_order_quantity', req)
self.assertIn('allocated_sales_order_quantity', req)
self.assertIn('allocated', req)
self.assertIn('required', req)


class PartBarcodeTest(InvenTreeTestCase):
"""Tests for Part barcode functionality"""
Expand Down

0 comments on commit 08e143c

Please sign in to comment.