mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Prevent auto-delete of stock items which have a serial number
This commit is contained in:
parent
33fe4d186d
commit
3058b895dd
@ -316,7 +316,15 @@ class StockItem(models.Model):
|
||||
infinite = models.BooleanField(default=False)
|
||||
|
||||
def can_delete(self):
|
||||
# TODO - Return FALSE if this item cannot be deleted!
|
||||
""" Can this stock item be deleted? It can NOT be deleted under the following circumstances:
|
||||
|
||||
- Has a serial number and is tracked
|
||||
- Is installed inside another StockItem
|
||||
"""
|
||||
|
||||
if part.trackable and self.serial is not None:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
@property
|
||||
@ -457,7 +465,7 @@ class StockItem(models.Model):
|
||||
|
||||
self.quantity = quantity
|
||||
|
||||
if quantity <= 0 and self.delete_on_deplete:
|
||||
if quantity <= 0 and self.delete_on_deplete and self.can_delete():
|
||||
self.delete()
|
||||
return False
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user