@@ -21,7 +21,7 @@ class Build(
2121 def issue (self ):
2222 """Mark this build as 'issued'."""
2323 return self ._statusupdate (status = 'issue' )
24-
24+
2525 def hold (self ):
2626 """Mark this build as 'on hold'."""
2727 return self ._statusupdate (status = 'hold' )
@@ -54,6 +54,94 @@ def getLines(self, **kwargs):
5454 """ Return the build line items associated with this build order """
5555 return BuildLine .list (self ._api , build = self .pk , ** kwargs )
5656
57+ def getBuildOutputs (self , complete : bool = None , ** kwargs ):
58+ """ Return the build output items associated with this build order
59+
60+ Arguments:
61+ - complete: If not None, filter the build outputs by their 'complete' status
62+ """
63+ if complete is not None :
64+ kwargs ['complete' ] = complete
65+
66+ # Find stock items which are marked as 'outputs' of this build order
67+ return inventree .stock .StockItem .list (
68+ self ._api ,
69+ build = self .pk ,
70+ ** kwargs
71+ )
72+
73+ def createBuildOutput (self , ** kwargs ):
74+ """ Create a new build output (stock item) associated with this build order """
75+ return self ._api .post (
76+ f'{ self .URL } create_output/' ,
77+ data = {
78+ ** kwargs
79+ }
80+ )
81+
82+ def cancelBuildOutputs (self , outputs ):
83+ """ Cancel a build output item associated with this build order
84+
85+ Arguments:
86+ - outputs: The StockItem object (or list of StockItem objects, or PK(s)) to cancel
87+ """
88+
89+ if not isinstance (outputs , list ):
90+ outputs = [outputs ]
91+
92+ for idx , output in outputs :
93+ if isinstance (output , inventree .stock .StockItem ):
94+ outputs [idx ] = output .pk
95+
96+ return self ._api .post (
97+ f'{ self .URL } delete-outputs/' ,
98+ data = {
99+ 'outputs' : outputs ,
100+ }
101+ )
102+
103+ def scrapBuildOutput (self , outputs , ** kwargs ):
104+ """ Scrap a build output item associated with this build order
105+
106+ Arguments:
107+ - outputs: The StockItem object (or list of StockItem objects, or PK(s)) to scrap
108+ """
109+ if not isinstance (outputs , list ):
110+ outputs = [outputs ]
111+
112+ for idx , output in outputs :
113+ if isinstance (output , inventree .stock .StockItem ):
114+ outputs [idx ] = output .pk
115+
116+ return self ._api .post (
117+ f'{ self .URL } scrap-outputs/' ,
118+ data = {
119+ 'build' : self .pk ,
120+ 'outputs' : {
121+ # TODO
122+ },
123+ ** kwargs
124+ }
125+ )
126+
127+ def completeBuildOutput (self , stock_item , ** kwargs ):
128+ """ Mark a build output item as complete
129+
130+ Arguments:
131+ - stock_item: The StockItem object (or PK) to mark as complete
132+ """
133+ if isinstance (stock_item , inventree .stock .StockItem ):
134+ stock_item = stock_item .pk
135+
136+ return self ._api .post (
137+ f'{ self .URL } complete_output/' ,
138+ data = {
139+ 'build' : self .pk ,
140+ 'stock_item' : stock_item ,
141+ ** kwargs
142+ }
143+ )
144+
57145
58146class BuildLine (
59147 inventree .base .InventreeObject ,
@@ -83,7 +171,7 @@ def getBuild(self):
83171 def getBuildLine (self ):
84172 """Return the BuildLine object associated with this build item"""
85173 return BuildLine (self ._api , self .build_line )
86-
174+
87175 def getStockItem (self ):
88176 """Return the StockItem object associated with this build item"""
89177 return inventree .stock .StockItem (self ._api , self .stock_item )
0 commit comments