2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-09 07:00:56 +00:00

Prevent stock adjustments for serialized stock items

This commit is contained in:
Oliver Walters
2019-07-25 11:05:09 +10:00
parent 94c0102742
commit fe7392f152
3 changed files with 45 additions and 2 deletions

View File

@ -122,6 +122,11 @@ class StockItem(models.Model):
system=True
)
@property
def serialized(self):
""" Return True if this StockItem is serialized """
return self.serial is not None and self.quantity == 1
@classmethod
def check_serial_number(cls, part, serial_number):
""" Check if a new stock item can be created with the provided part_id
@ -358,6 +363,14 @@ class StockItem(models.Model):
track.save()
@transaction.atomic
def serializeStock(self, serials, user):
""" Split this stock item into unique serial numbers.
"""
# TODO
pass
@transaction.atomic
def splitStock(self, quantity, user):
""" Split this stock item into two items, in the same location.
@ -372,6 +385,10 @@ class StockItem(models.Model):
The new item will have a different StockItem ID, while this will remain the same.
"""
# Do not split a serialized part
if self.serialized:
return
# Doesn't make sense for a zero quantity
if quantity <= 0:
return
@ -461,6 +478,10 @@ class StockItem(models.Model):
- False if the StockItem was deleted
"""
# Do not adjust quantity of a serialized part
if self.serialized:
return
if quantity < 0:
quantity = 0
@ -504,6 +525,10 @@ class StockItem(models.Model):
or by manually adding the items to the stock location
"""
# Cannot add items to a serialized part
if self.serialized:
return False
quantity = int(quantity)
# Ignore amounts that do not make sense
@ -524,6 +549,10 @@ class StockItem(models.Model):
""" Remove items from stock
"""
# Cannot remove items from a serialized part
if self.serialized:
return False
quantity = int(quantity)
if quantity <= 0 or self.infinite: