diff --git a/inventree/build.py b/inventree/build.py index 8bc0c5e..d20fb3d 100644 --- a/inventree/build.py +++ b/inventree/build.py @@ -2,6 +2,7 @@ import inventree.base import inventree.report +import inventree.stock class Build( @@ -48,3 +49,41 @@ def complete( def finish(self, *args, **kwargs): """Alias for complete""" return self.complete(*args, **kwargs) + + def getLines(self, **kwargs): + """ Return the build line items associated with this build order """ + return BuildLine.list(self._api, build=self.pk, **kwargs) + + +class BuildLine( + inventree.base.InventreeObject, +): + """ Class representing the BuildLine database model """ + + URL = 'build/line/' + MODEL_TYPE = 'buildline' + + def getBuild(self): + """Return the Build object associated with this line item""" + return Build(self._api, self.build) + + +class BuildItem( + inventree.base.InventreeObject, +): + """ Class representing the BuildItem database model """ + + URL = 'build/item/' + MODEL_TYPE = 'builditem' + + def getBuild(self): + """Return the Build object associated with this build item""" + return Build(self._api, self.build) + + def getBuildLine(self): + """Return the BuildLine object associated with this build item""" + return BuildLine(self._api, self.build_line) + + def getStockItem(self): + """Return the StockItem object associated with this build item""" + return inventree.stock.StockItem(self._api, self.stock_item) diff --git a/test/test_build.py b/test/test_build.py index 45929bb..f7db883 100644 --- a/test/test_build.py +++ b/test/test_build.py @@ -36,9 +36,9 @@ def get_build(self): self.api, { "title": "Automated test build", - "part": 25, + "part": 100, "quantity": 100, - "reference": f"BO-{n+1:04d}", + "reference": f"BO-{n + 1:04d}", } ) else: @@ -93,7 +93,7 @@ def test_build_cancel(self): "title": "Automated test build", "part": 25, "quantity": 100, - "reference": f"BO-{n+1:04d}" + "reference": f"BO-{n + 1:04d}" } ) @@ -118,7 +118,7 @@ def test_build_complete(self): "title": "Automated test build", "part": 25, "quantity": 100, - "reference": f"BO-{n+1:04d}" + "reference": f"BO-{n + 1:04d}" } )