mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add stock tracking code to indicate stock has been consumed by a build order
This commit is contained in:
parent
bb164ed72a
commit
9e3406efc9
@ -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')
|
||||
|
||||
|
@ -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):
|
||||
"""
|
||||
|
@ -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={
|
||||
|
Loading…
Reference in New Issue
Block a user