From b85a4d089587a398b95d61457ee733af8265f13f Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 5 May 2019 22:34:00 +1000 Subject: [PATCH 1/3] Limit choices for BomItem Part foreignkey fields - Only allow 'active' Parts --- .../migrations/0018_auto_20190505_2231.py | 24 +++++++++++++++++++ InvenTree/part/models.py | 10 ++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 InvenTree/part/migrations/0018_auto_20190505_2231.py diff --git a/InvenTree/part/migrations/0018_auto_20190505_2231.py b/InvenTree/part/migrations/0018_auto_20190505_2231.py new file mode 100644 index 0000000000..32aa1e3a1b --- /dev/null +++ b/InvenTree/part/migrations/0018_auto_20190505_2231.py @@ -0,0 +1,24 @@ +# Generated by Django 2.2 on 2019-05-05 12:31 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('part', '0017_auto_20190505_0848'), + ] + + operations = [ + migrations.AlterField( + model_name='bomitem', + name='part', + field=models.ForeignKey(limit_choices_to={'active': True, 'buildable': True}, 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(limit_choices_to={'active': True, 'consumable': True}, 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 e5497faa4c..f9a91fd345 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -464,12 +464,18 @@ class BomItem(models.Model): # A link to the parent part # Each part will get a reverse lookup field 'bom_items' part = models.ForeignKey(Part, on_delete=models.CASCADE, related_name='bom_items', - limit_choices_to={'buildable': True}) + limit_choices_to={ + 'buildable': True, + 'active': True, + }) # A link to the child item (sub-part) # Each part will get a reverse lookup field 'used_in' sub_part = models.ForeignKey(Part, on_delete=models.CASCADE, related_name='used_in', - limit_choices_to={'consumable': True}) + limit_choices_to={ + 'consumable': True, + 'active': True + }) # Quantity required quantity = models.PositiveIntegerField(default=1, validators=[MinValueValidator(0)]) From 9bbcc35959f7ee7ffbfdc2fb8e6bef619df66607 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 5 May 2019 22:34:14 +1000 Subject: [PATCH 2/3] Builds can only be made for active parts --- .../migrations/0010_auto_20190505_2233.py | 19 +++++++++++++++++++ InvenTree/build/models.py | 5 ++++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 InvenTree/build/migrations/0010_auto_20190505_2233.py diff --git a/InvenTree/build/migrations/0010_auto_20190505_2233.py b/InvenTree/build/migrations/0010_auto_20190505_2233.py new file mode 100644 index 0000000000..5be6c393c9 --- /dev/null +++ b/InvenTree/build/migrations/0010_auto_20190505_2233.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2 on 2019-05-05 12:33 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('build', '0009_build_completed_by'), + ] + + operations = [ + migrations.AlterField( + model_name='build', + name='part', + field=models.ForeignKey(limit_choices_to={'active': True, 'buildable': True}, 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 7175a18650..80feefc547 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -84,7 +84,10 @@ class Build(models.Model): part = models.ForeignKey('part.Part', on_delete=models.CASCADE, related_name='builds', - limit_choices_to={'buildable': True}, + limit_choices_to={ + 'buildable': True, + 'active': True + }, ) title = models.CharField( From b9e5afa768afe5c57618653a4b1116071fd71c5f Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 5 May 2019 22:35:39 +1000 Subject: [PATCH 3/3] PEP --- InvenTree/build/models.py | 2 +- InvenTree/part/models.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index 80feefc547..e81ae6a45d 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -87,7 +87,7 @@ class Build(models.Model): limit_choices_to={ 'buildable': True, 'active': True - }, + }, ) title = models.CharField( diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index f9a91fd345..2a3c31552e 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -467,7 +467,7 @@ class BomItem(models.Model): limit_choices_to={ 'buildable': True, 'active': True, - }) + }) # A link to the child item (sub-part) # Each part will get a reverse lookup field 'used_in' @@ -475,7 +475,7 @@ class BomItem(models.Model): limit_choices_to={ 'consumable': True, 'active': True - }) + }) # Quantity required quantity = models.PositiveIntegerField(default=1, validators=[MinValueValidator(0)])