diff --git a/InvenTree/InvenTree/status_codes.py b/InvenTree/InvenTree/status_codes.py index c8917d679b..ffe22039c9 100644 --- a/InvenTree/InvenTree/status_codes.py +++ b/InvenTree/InvenTree/status_codes.py @@ -258,6 +258,7 @@ class StockHistoryCode(StatusCode): # Build order codes BUILD_OUTPUT_CREATED = 50 BUILD_OUTPUT_COMPLETED = 55 + BUILD_CONSUMED = 57 # Sales order codes @@ -298,6 +299,7 @@ class StockHistoryCode(StatusCode): BUILD_OUTPUT_CREATED: _('Build order output created'), BUILD_OUTPUT_COMPLETED: _('Build order output completed'), + BUILD_CONSUMED: _('Consumed by build order'), RECEIVED_AGAINST_PURCHASE_ORDER: _('Received against purchase order') diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index cbf55dc265..443998ca11 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -1167,7 +1167,12 @@ class BuildItem(models.Model): if item.part.trackable: # Split the allocated stock if there are more available than allocated if item.quantity > self.quantity: - item = item.splitStock(self.quantity, None, user) + item = item.splitStock( + self.quantity, + None, + user, + code=StockHistoryCode.BUILD_CONSUMED, + ) # Make sure we are pointing to the new item self.stock_item = item @@ -1178,7 +1183,11 @@ class BuildItem(models.Model): item.save() else: # Simply remove the items from stock - item.take_stock(self.quantity, user) + item.take_stock( + self.quantity, + user, + code=StockHistoryCode.BUILD_CONSUMED + ) def getStockItemThumbnail(self): """ diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index 158d0a2640..45f3a40a4d 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -1530,7 +1530,7 @@ class StockItem(MPTTModel): return True @transaction.atomic - def take_stock(self, quantity, user, notes=''): + def take_stock(self, quantity, user, notes='', code=StockHistoryCode.STOCK_REMOVE): """ Remove items from stock """ @@ -1550,7 +1550,7 @@ class StockItem(MPTTModel): if self.updateQuantity(self.quantity - quantity): self.add_tracking_entry( - StockHistoryCode.STOCK_REMOVE, + code, user, notes=notes, deltas={