From 8eaaf62eda20708bc3e7edecb588ec5dd8c8f6db Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 18 Mar 2020 21:28:11 +1100 Subject: [PATCH] Limit choices for Part selection Based on is_template / virtual / active status --- .../migrations/0010_auto_20200318_1027.py | 19 +++++++++++++++ InvenTree/build/models.py | 3 ++- .../migrations/0030_auto_20200318_1027.py | 24 +++++++++++++++++++ InvenTree/part/models.py | 2 ++ .../migrations/0023_auto_20200318_1027.py | 19 +++++++++++++++ InvenTree/stock/models.py | 1 + 6 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 InvenTree/build/migrations/0010_auto_20200318_1027.py create mode 100644 InvenTree/part/migrations/0030_auto_20200318_1027.py create mode 100644 InvenTree/stock/migrations/0023_auto_20200318_1027.py diff --git a/InvenTree/build/migrations/0010_auto_20200318_1027.py b/InvenTree/build/migrations/0010_auto_20200318_1027.py new file mode 100644 index 0000000000..d6871c8431 --- /dev/null +++ b/InvenTree/build/migrations/0010_auto_20200318_1027.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2.9 on 2020-03-18 10:27 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('build', '0009_auto_20200210_1032'), + ] + + operations = [ + migrations.AlterField( + model_name='build', + name='part', + field=models.ForeignKey(help_text='Select part to build', limit_choices_to={'active': True, 'assembly': True, 'is_template': False, 'virtual': False}, on_delete=django.db.models.deletion.CASCADE, related_name='builds', to='part.Part'), + ), + ] diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index 54719ef17e..dae5789493 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -58,7 +58,8 @@ class Build(models.Model): limit_choices_to={ 'is_template': False, 'assembly': True, - 'active': True + 'active': True, + 'virtual': False, }, help_text=_('Select part to build'), ) diff --git a/InvenTree/part/migrations/0030_auto_20200318_1027.py b/InvenTree/part/migrations/0030_auto_20200318_1027.py new file mode 100644 index 0000000000..0c61e9717d --- /dev/null +++ b/InvenTree/part/migrations/0030_auto_20200318_1027.py @@ -0,0 +1,24 @@ +# Generated by Django 2.2.9 on 2020-03-18 10:27 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('part', '0029_auto_20200223_0901'), + ] + + operations = [ + migrations.AlterField( + model_name='bomitem', + name='part', + field=models.ForeignKey(help_text='Select parent part', limit_choices_to={'assembly': True, 'is_template': False}, on_delete=django.db.models.deletion.CASCADE, related_name='bom_items', to='part.Part'), + ), + migrations.AlterField( + model_name='bomitem', + name='sub_part', + field=models.ForeignKey(help_text='Select part to be used in BOM', limit_choices_to={'component': True, 'is_template': False}, on_delete=django.db.models.deletion.CASCADE, related_name='used_in', to='part.Part'), + ), + ] diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index f305b51c4c..312cdcaa69 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -1067,6 +1067,7 @@ class BomItem(models.Model): help_text=_('Select parent part'), limit_choices_to={ 'assembly': True, + 'is_template': False, }) # A link to the child item (sub-part) @@ -1075,6 +1076,7 @@ class BomItem(models.Model): help_text=_('Select part to be used in BOM'), limit_choices_to={ 'component': True, + 'is_template': False, }) # Quantity required diff --git a/InvenTree/stock/migrations/0023_auto_20200318_1027.py b/InvenTree/stock/migrations/0023_auto_20200318_1027.py new file mode 100644 index 0000000000..268bdd6cf2 --- /dev/null +++ b/InvenTree/stock/migrations/0023_auto_20200318_1027.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2.9 on 2020-03-18 10:27 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('stock', '0022_auto_20200217_1109'), + ] + + operations = [ + migrations.AlterField( + model_name='stockitem', + name='part', + field=models.ForeignKey(help_text='Base part', limit_choices_to={'active': True, 'is_template': False, 'virtual': False}, on_delete=django.db.models.deletion.CASCADE, related_name='stock_items', to='part.Part'), + ), + ] diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index 43d3eef145..64353d948d 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -307,6 +307,7 @@ class StockItem(MPTTModel): limit_choices_to={ 'is_template': False, 'active': True, + 'virtual': False }) supplier_part = models.ForeignKey('company.SupplierPart', blank=True, null=True, on_delete=models.SET_NULL,