diff --git a/InvenTree/stock/migrations/0051_auto_20200928_0928.py b/InvenTree/stock/migrations/0051_auto_20200928_0928.py new file mode 100644 index 0000000000..dd82e6edd0 --- /dev/null +++ b/InvenTree/stock/migrations/0051_auto_20200928_0928.py @@ -0,0 +1,19 @@ +# Generated by Django 3.0.7 on 2020-09-28 09:28 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('stock', '0050_auto_20200821_1403'), + ] + + operations = [ + migrations.AlterField( + model_name='stockitem', + name='belongs_to', + field=models.ForeignKey(blank=True, help_text='Is this item installed in another item?', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='installed_parts', to='stock.StockItem', verbose_name='Installed In'), + ), + ] diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index 40c80e882c..e2468772e2 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -341,7 +341,7 @@ class StockItem(MPTTModel): 'self', verbose_name=_('Installed In'), on_delete=models.DO_NOTHING, - related_name='owned_parts', blank=True, null=True, + related_name='installed_parts', blank=True, null=True, help_text=_('Is this item installed in another item?') ) @@ -585,6 +585,20 @@ class StockItem(MPTTModel): return True + def installedItemCount(self): + """ + Return the number of stock items installed inside this one. + """ + + return self.installed_parts.count() + + def hasInstalledItems(self): + """ + Returns true if this stock item has other stock items installed in it. + """ + + return self.installedItemCount() > 0 + @property def children(self): """ Return a list of the child items which have been split from this stock item """