2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-05-01 04:56:45 +00:00

Add stock tracking code to indicate stock has been consumed by a build order

This commit is contained in:
Oliver 2022-02-25 15:56:09 +11:00
parent bb164ed72a
commit 9e3406efc9
3 changed files with 15 additions and 4 deletions

View File

@ -258,6 +258,7 @@ class StockHistoryCode(StatusCode):
# Build order codes # Build order codes
BUILD_OUTPUT_CREATED = 50 BUILD_OUTPUT_CREATED = 50
BUILD_OUTPUT_COMPLETED = 55 BUILD_OUTPUT_COMPLETED = 55
BUILD_CONSUMED = 57
# Sales order codes # Sales order codes
@ -298,6 +299,7 @@ class StockHistoryCode(StatusCode):
BUILD_OUTPUT_CREATED: _('Build order output created'), BUILD_OUTPUT_CREATED: _('Build order output created'),
BUILD_OUTPUT_COMPLETED: _('Build order output completed'), BUILD_OUTPUT_COMPLETED: _('Build order output completed'),
BUILD_CONSUMED: _('Consumed by build order'),
RECEIVED_AGAINST_PURCHASE_ORDER: _('Received against purchase order') RECEIVED_AGAINST_PURCHASE_ORDER: _('Received against purchase order')

View File

@ -1167,7 +1167,12 @@ class BuildItem(models.Model):
if item.part.trackable: if item.part.trackable:
# Split the allocated stock if there are more available than allocated # Split the allocated stock if there are more available than allocated
if item.quantity > self.quantity: 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 # Make sure we are pointing to the new item
self.stock_item = item self.stock_item = item
@ -1178,7 +1183,11 @@ class BuildItem(models.Model):
item.save() item.save()
else: else:
# Simply remove the items from stock # 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): def getStockItemThumbnail(self):
""" """

View File

@ -1530,7 +1530,7 @@ class StockItem(MPTTModel):
return True return True
@transaction.atomic @transaction.atomic
def take_stock(self, quantity, user, notes=''): def take_stock(self, quantity, user, notes='', code=StockHistoryCode.STOCK_REMOVE):
""" """
Remove items from stock Remove items from stock
""" """
@ -1550,7 +1550,7 @@ class StockItem(MPTTModel):
if self.updateQuantity(self.quantity - quantity): if self.updateQuantity(self.quantity - quantity):
self.add_tracking_entry( self.add_tracking_entry(
StockHistoryCode.STOCK_REMOVE, code,
user, user,
notes=notes, notes=notes,
deltas={ deltas={