Skip to content

Commit dcada33

Browse files
Merge pull request #290 from inventree/build-models
Enhanced build models support
2 parents 4712249 + 1758bbe commit dcada33

2 files changed

Lines changed: 43 additions & 4 deletions

File tree

inventree/build.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import inventree.base
44
import inventree.report
5+
import inventree.stock
56

67

78
class Build(
@@ -48,3 +49,41 @@ def complete(
4849
def finish(self, *args, **kwargs):
4950
"""Alias for complete"""
5051
return self.complete(*args, **kwargs)
52+
53+
def getLines(self, **kwargs):
54+
""" Return the build line items associated with this build order """
55+
return BuildLine.list(self._api, build=self.pk, **kwargs)
56+
57+
58+
class BuildLine(
59+
inventree.base.InventreeObject,
60+
):
61+
""" Class representing the BuildLine database model """
62+
63+
URL = 'build/line/'
64+
MODEL_TYPE = 'buildline'
65+
66+
def getBuild(self):
67+
"""Return the Build object associated with this line item"""
68+
return Build(self._api, self.build)
69+
70+
71+
class BuildItem(
72+
inventree.base.InventreeObject,
73+
):
74+
""" Class representing the BuildItem database model """
75+
76+
URL = 'build/item/'
77+
MODEL_TYPE = 'builditem'
78+
79+
def getBuild(self):
80+
"""Return the Build object associated with this build item"""
81+
return Build(self._api, self.build)
82+
83+
def getBuildLine(self):
84+
"""Return the BuildLine object associated with this build item"""
85+
return BuildLine(self._api, self.build_line)
86+
87+
def getStockItem(self):
88+
"""Return the StockItem object associated with this build item"""
89+
return inventree.stock.StockItem(self._api, self.stock_item)

test/test_build.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ def get_build(self):
3636
self.api,
3737
{
3838
"title": "Automated test build",
39-
"part": 25,
39+
"part": 100,
4040
"quantity": 100,
41-
"reference": f"BO-{n+1:04d}",
41+
"reference": f"BO-{n + 1:04d}",
4242
}
4343
)
4444
else:
@@ -93,7 +93,7 @@ def test_build_cancel(self):
9393
"title": "Automated test build",
9494
"part": 25,
9595
"quantity": 100,
96-
"reference": f"BO-{n+1:04d}"
96+
"reference": f"BO-{n + 1:04d}"
9797
}
9898
)
9999

@@ -118,7 +118,7 @@ def test_build_complete(self):
118118
"title": "Automated test build",
119119
"part": 25,
120120
"quantity": 100,
121-
"reference": f"BO-{n+1:04d}"
121+
"reference": f"BO-{n + 1:04d}"
122122
}
123123
)
124124

0 commit comments

Comments
 (0)