From 009adaf528b2e1377b3f0b815a34a834059f6276 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 25 May 2020 13:13:28 +1000 Subject: [PATCH 1/4] Code to get and test for variants of a part --- InvenTree/part/models.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 4acd4a594e..1a8048a985 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -1109,6 +1109,17 @@ class Part(MPTTModel): return self.parameters.order_by('template__name') + @property + def has_variants(self): + """ Check if this Part object has variants underneath it. """ + + return self.get_all_variants().count() > 0 + + def get_all_variants(self): + """ Return all Part object which exist as a variant under this part. """ + + return self.get_descendants(include_self=False) + def attach_file(instance, filename): """ Function for storing a file for a PartAttachment From fdf57891fc224e4a124e53ff2219e63d89bcf6c3 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 25 May 2020 14:16:38 +1000 Subject: [PATCH 2/4] Form / view / etc for performing StockItem conversion --- InvenTree/stock/forms.py | 12 ++++++++++ .../stock/templates/stock/item_base.html | 15 ++++++++++++ .../templates/stock/stockitem_convert.html | 17 +++++++++++++ InvenTree/stock/urls.py | 1 + InvenTree/stock/views.py | 24 +++++++++++++++++++ 5 files changed, 69 insertions(+) create mode 100644 InvenTree/stock/templates/stock/stockitem_convert.html diff --git a/InvenTree/stock/forms.py b/InvenTree/stock/forms.py index edf3d28df8..ddd7390246 100644 --- a/InvenTree/stock/forms.py +++ b/InvenTree/stock/forms.py @@ -63,6 +63,18 @@ class EditStockLocationForm(HelperForm): ] +class ConvertStockItemForm(HelperForm): + """ + Form for converting a StockItem to a variant of its current part. + """ + + class Meta: + model = StockItem + fields = [ + 'part' + ] + + class CreateStockItemForm(HelperForm): """ Form for creating a new StockItem """ diff --git a/InvenTree/stock/templates/stock/item_base.html b/InvenTree/stock/templates/stock/item_base.html index 819c138988..bc187588d0 100644 --- a/InvenTree/stock/templates/stock/item_base.html +++ b/InvenTree/stock/templates/stock/item_base.html @@ -93,6 +93,11 @@ InvenTree | {% trans "Stock Item" %} - {{ item }} {% endif %} + {% if item.part.has_variants %} + + {% endif %} {% if item.part.has_test_report_templates %}