mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Do not let a StockItem be deleted if child items exist
This commit is contained in:
parent
49d5573f8b
commit
49118d8083
@ -376,10 +376,14 @@ class StockItem(MPTTModel):
|
|||||||
def can_delete(self):
|
def can_delete(self):
|
||||||
""" Can this stock item be deleted? It can NOT be deleted under the following circumstances:
|
""" 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
|
- Has a serial number and is tracked
|
||||||
- Is installed inside another StockItem
|
- Is installed inside another StockItem
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if self.child_count > 0:
|
||||||
|
return False
|
||||||
|
|
||||||
if self.part.trackable and self.serial is not None:
|
if self.part.trackable and self.serial is not None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -43,15 +43,21 @@
|
|||||||
<button type='button' class='btn btn-default btn-glyph' id='stock-edit' title='Edit stock item'>
|
<button type='button' class='btn btn-default btn-glyph' id='stock-edit' title='Edit stock item'>
|
||||||
<span class='glyphicon glyphicon-edit'/>
|
<span class='glyphicon glyphicon-edit'/>
|
||||||
</button>
|
</button>
|
||||||
|
{% if item.can_delete %}
|
||||||
<button type='button' class='btn btn-default btn-glyph' id='stock-delete' title='Edit stock item'>
|
<button type='button' class='btn btn-default btn-glyph' id='stock-delete' title='Edit stock item'>
|
||||||
<span class='glyphicon glyphicon-trash'/>
|
<span class='glyphicon glyphicon-trash'/>
|
||||||
</button>
|
</button>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</p>
|
</p>
|
||||||
{% if item.serialized %}
|
{% if item.serialized %}
|
||||||
<div class='alert alert-block alert-info'>
|
<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." %}
|
{% trans "This stock item is serialized - it has a unique serial number and the quantity cannot be adjusted." %}
|
||||||
</div>
|
</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 %}
|
{% elif item.delete_on_deplete %}
|
||||||
<div class='alert alert-block alert-warning'>
|
<div class='alert alert-block alert-warning'>
|
||||||
{% trans "This stock item will be automatically deleted when all stock is depleted." %}
|
{% trans "This stock item will be automatically deleted when all stock is depleted." %}
|
||||||
|
Loading…
Reference in New Issue
Block a user