diff --git a/InvenTree/build/migrations/0004_auto_20190525_2356.py b/InvenTree/build/migrations/0004_auto_20190525_2356.py new file mode 100644 index 0000000000..1a43e5bfc8 --- /dev/null +++ b/InvenTree/build/migrations/0004_auto_20190525_2356.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2 on 2019-05-25 13:56 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('build', '0003_auto_20190525_2355'), + ] + + operations = [ + migrations.AlterField( + model_name='build', + name='part', + field=models.ForeignKey(help_text='Select part to build', limit_choices_to={'active': True, 'buildable': True, 'is_template': 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 d01c001ba8..ad482b8dc6 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -50,7 +50,7 @@ class Build(models.Model): part = models.ForeignKey('part.Part', on_delete=models.CASCADE, related_name='builds', limit_choices_to={ - 'has_variants': False, + 'is_template': False, 'buildable': True, 'active': True }, diff --git a/InvenTree/company/migrations/0005_auto_20190525_2356.py b/InvenTree/company/migrations/0005_auto_20190525_2356.py new file mode 100644 index 0000000000..fe02be0d84 --- /dev/null +++ b/InvenTree/company/migrations/0005_auto_20190525_2356.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2 on 2019-05-25 13:56 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('company', '0004_auto_20190525_2354'), + ] + + operations = [ + migrations.AlterField( + model_name='supplierpart', + name='part', + field=models.ForeignKey(help_text='Select part', limit_choices_to={'is_template': False, 'purchaseable': True}, on_delete=django.db.models.deletion.CASCADE, related_name='supplier_parts', to='part.Part'), + ), + ] diff --git a/InvenTree/company/models.py b/InvenTree/company/models.py index c62facb8ab..245264900d 100644 --- a/InvenTree/company/models.py +++ b/InvenTree/company/models.py @@ -190,7 +190,7 @@ class SupplierPart(models.Model): related_name='supplier_parts', limit_choices_to={ 'purchaseable': True, - 'has_variants': False, + 'is_template': False, }, help_text='Select part', ) diff --git a/InvenTree/part/migrations/0004_auto_20190525_2356.py b/InvenTree/part/migrations/0004_auto_20190525_2356.py new file mode 100644 index 0000000000..7b9a5fe6ac --- /dev/null +++ b/InvenTree/part/migrations/0004_auto_20190525_2356.py @@ -0,0 +1,24 @@ +# Generated by Django 2.2 on 2019-05-25 13:56 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('part', '0003_auto_20190525_2226'), + ] + + operations = [ + migrations.RenameField( + model_name='part', + old_name='has_variants', + new_name='is_template', + ), + migrations.AlterField( + model_name='part', + name='variant_of', + field=models.ForeignKey(blank=True, help_text='Is this part a variant of another part?', limit_choices_to={'active': True, 'is_template': True}, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='variants', to='part.Part'), + ), + ] diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index df948bb1c8..1511b7a0d8 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -192,7 +192,7 @@ class Part(models.Model): description: Longer form description of the part keywords: Optional keywords for improving part search results IPN: Internal part number (optional) - has_variants: If True, this part is a 'template' part and cannot be instantiated as a StockItem + is_template: If True, this part is a 'template' part and cannot be instantiated as a StockItem URL: Link to an external page with more information about this part (e.g. internal Wiki) image: Image of this part default_location: Where the item is normally stored (may be null) @@ -256,10 +256,10 @@ class Part(models.Model): def clean(self): """ Perform cleaning operations for the Part model """ - if self.has_variants and self.variant_of is not None: + if self.is_template and self.variant_of is not None: raise ValidationError({ + 'is_template': _("Part cannot be a template part if it is a variant of another part"), 'variant_of': _("Part cannot be a variant of another part if it is already a template"), - 'has_variants': _("Part cannot be a template part if it is a variant of another part") }) name = models.CharField(max_length=100, blank=False, help_text='Part name', @@ -268,12 +268,12 @@ class Part(models.Model): variant = models.CharField(max_length=32, blank=True, help_text='Part variant or revision code') - has_variants = models.BooleanField(default=False, help_text='Is this part a template part?') + is_template = models.BooleanField(default=False, help_text='Is this part a template part?') variant_of = models.ForeignKey('part.Part', related_name='variants', null=True, blank=True, limit_choices_to={ - 'has_variants': True, + 'is_template': True, 'active': True, }, on_delete=models.SET_NULL, diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index 42bbbbf8fd..748303df35 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -9,7 +9,7 @@ This part is not active: {% endif %} -{% if part.has_variants %} +{% if part.is_template %}
This part is a template part.
It is not a real part, but real parts can be based on this template. diff --git a/InvenTree/part/templates/part/tabs.html b/InvenTree/part/templates/part/tabs.html index a251c840de..6dd4a0ab80 100644 --- a/InvenTree/part/templates/part/tabs.html +++ b/InvenTree/part/templates/part/tabs.html @@ -2,7 +2,7 @@ Details - {% if part.has_variants %} + {% if part.is_template %} Variants {{ part.variants.count }} @@ -25,7 +25,7 @@ Used In{% if part.used_in_count > 0 %}{{ part.used_in_count }}{% endif %} {% endif %} - {% if part.purchaseable and part.has_variants == False %} + {% if part.purchaseable and part.is_template == False %} Suppliers {{ part.supplier_count }} diff --git a/InvenTree/part/templates/part/variants.html b/InvenTree/part/templates/part/variants.html index cea712ea03..1afcda25d3 100644 --- a/InvenTree/part/templates/part/variants.html +++ b/InvenTree/part/templates/part/variants.html @@ -15,7 +15,7 @@
- {% if part.has_variants and part.active %} + {% if part.is_template and part.active %} {% endif %}
diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index e548c233b9..aec679a46f 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -274,7 +274,7 @@ class StockList(generics.ListCreateAPIView): part = Part.objects.get(pk=part_id) # If the part is a Template part, select stock items for any "variant" parts under that template - if part.has_variants: + if part.is_template: stock_list = stock_list.filter(part__in=[part.id for part in Part.objects.filter(variant_of=part_id)]) else: stock_list = stock_list.filter(part=part_id) diff --git a/InvenTree/stock/migrations/0004_auto_20190525_2356.py b/InvenTree/stock/migrations/0004_auto_20190525_2356.py new file mode 100644 index 0000000000..4b2f939eb2 --- /dev/null +++ b/InvenTree/stock/migrations/0004_auto_20190525_2356.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2 on 2019-05-25 13:56 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('stock', '0003_auto_20190525_2303'), + ] + + operations = [ + migrations.AlterField( + model_name='stockitem', + name='part', + field=models.ForeignKey(help_text='Base part', limit_choices_to={'active': True, 'is_template': 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 46bab9ae73..5d297df946 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -159,7 +159,7 @@ class StockItem(models.Model): }) # A template part cannot be instantiated as a StockItem - if self.part.has_variants: + if self.part.is_template: raise ValidationError({ 'part': _('Stock item cannot be created for a template Part') }) @@ -213,7 +213,7 @@ class StockItem(models.Model): part = models.ForeignKey('part.Part', on_delete=models.CASCADE, related_name='stock_items', help_text='Base part', limit_choices_to={ - 'has_variants': False, + 'is_template': False, 'active': True, })