Skip to content
Open
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
39 changes: 39 additions & 0 deletions inventree/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import inventree.base
import inventree.report
import inventree.stock


class Build(
Expand Down Expand Up @@ -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)
23 changes: 18 additions & 5 deletions test/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from test_api import InvenTreeTestCase # noqa: E402

from inventree.base import Attachment # noqa: E402
from inventree.build import Build # noqa: E402
from inventree.build import Build, BuildLine # noqa: E402


class BuildOrderTest(InvenTreeTestCase):
Expand All @@ -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:
Expand Down Expand Up @@ -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}"
}
)

Expand All @@ -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}"
}
)

Expand All @@ -144,3 +144,16 @@ def test_build_complete(self):
# Check status
self.assertEqual(build.status, 40)
self.assertEqual(build.status_text, 'Complete')

def test_build_lines(self):
""" Test retrieval of build line items. """

build = self.get_build()

lines = build.getLines()

self.assertGreater(len(lines), 0)

for line in lines:
self.assertEqual(line.build, build.pk)
self.assertIsInstance(line, BuildLine)
Loading