From 8ae16a125e343730139187902708f14788ec507e Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 21 Oct 2020 00:24:55 +1100 Subject: [PATCH] Build - Add functions to access build outputs --- InvenTree/build/models.py | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index a22aae196f..166d70afac 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -184,6 +184,57 @@ class Build(MPTTModel): def output_count(self): return self.build_outputs.count() + def getBuildOutputs(self, **kwargs): + """ + Return a list of build outputs + """ + + outputs = self.build_outputs + + # Filter by 'in stock' status + in_stock = kwargs.get('in_stock', None) + + if in_stock is not None: + if in_stock: + outputs = outputs.filter(StockModels.StockItem.IN_STOCK_FILTER) + else: + outputs = outputs.exclude(StockModels.StockItem.IN_STOCK_FILTER) + + # Filter by 'complete' status + complete = kwargs.get('complete', None) + + if complete is not None: + if complete: + outputs = outputs.filter(is_building=False) + else: + outputs = outputs.filter(is_building=True) + + return outputs + + @property + def complete_outputs(self): + """ + Return all the "completed" build outputs + """ + + outputs = self.getBuildOutputs(complete=True) + + # TODO - Ordering? + + return outputs + + @property + def incomplete_outputs(self): + """ + Return all the "incomplete" build outputs" + """ + + outputs = self.getBuildOutputs(complete=False) + + # TODO - Order by how "complete" they are? + + return outputs + @classmethod def getNextBuildNumber(cls): """ @@ -494,6 +545,7 @@ class Build(MPTTModel): @property def is_complete(self): """ Returns True if the build status is COMPLETE """ + return self.status == BuildStatus.COMPLETE