Do not let a StockItem be deleted if child items exist

This commit is contained in:
Oliver Walters 2020-02-18 10:41:06 +11:00
parent 49d5573f8b
commit 49118d8083
2 changed files with 10 additions and 0 deletions

View File

@ -376,10 +376,14 @@ class StockItem(MPTTModel):
def can_delete(self):
""" Can this stock item be deleted? It can NOT be deleted under the following circumstances:
- Has child StockItems
- Has a serial number and is tracked
- Is installed inside another StockItem
"""
if self.child_count > 0:
return False
if self.part.trackable and self.serial is not None:
return False

View File

@ -43,15 +43,21 @@
<button type='button' class='btn btn-default btn-glyph' id='stock-edit' title='Edit stock item'>
<span class='glyphicon glyphicon-edit'/>
</button>
{% if item.can_delete %}
<button type='button' class='btn btn-default btn-glyph' id='stock-delete' title='Edit stock item'>
<span class='glyphicon glyphicon-trash'/>
</button>
{% endif %}
</div>
</p>
{% if item.serialized %}
<div class='alert alert-block alert-info'>
{% trans "This stock item is serialized - it has a unique serial number and the quantity cannot be adjusted." %}
</div>
{% elif item.child_count > 0 %}
<div class='alert alert-block alert-warning'>
{% trans "This stock item cannot be deleted as it has child items" %}
</div>
{% elif item.delete_on_deplete %}
<div class='alert alert-block alert-warning'>
{% trans "This stock item will be automatically deleted when all stock is depleted." %}