From 49118d8083f6bd42e38a0e2b8b4ee3206125de4b Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 18 Feb 2020 10:41:06 +1100 Subject: [PATCH] Do not let a StockItem be deleted if child items exist --- InvenTree/stock/models.py | 4 ++++ InvenTree/stock/templates/stock/item_base.html | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index 1a4a48ad62..43d3eef145 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -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 diff --git a/InvenTree/stock/templates/stock/item_base.html b/InvenTree/stock/templates/stock/item_base.html index 4e32356101..3e398ba16a 100644 --- a/InvenTree/stock/templates/stock/item_base.html +++ b/InvenTree/stock/templates/stock/item_base.html @@ -43,15 +43,21 @@ + {% if item.can_delete %} + {% endif %}

{% if item.serialized %}
{% trans "This stock item is serialized - it has a unique serial number and the quantity cannot be adjusted." %}
+ {% elif item.child_count > 0 %} +
+ {% trans "This stock item cannot be deleted as it has child items" %} +
{% elif item.delete_on_deplete %}
{% trans "This stock item will be automatically deleted when all stock is depleted." %}