From ba26acd48722d037e89ca04b6d28828ae199e30e Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 2 Jun 2019 19:46:30 +1000 Subject: [PATCH] Rename some fields - Oops didn't think that through, gotta go through and fix the data now... --- InvenTree/InvenTree/views.py | 4 +- InvenTree/part/api.py | 4 +- InvenTree/part/fixtures/part.yaml | 2 +- InvenTree/part/forms.py | 4 +- .../migrations/0007_auto_20190602_1944.py | 42 +++++++++++++++++++ InvenTree/part/models.py | 12 +++--- InvenTree/part/serializers.py | 4 +- InvenTree/part/templates/part/detail.html | 4 +- InvenTree/part/templates/part/part_base.html | 2 +- InvenTree/part/templates/part/tabs.html | 4 +- InvenTree/part/test_api.py | 2 +- .../static/script/inventree/inventree.js | 4 ++ .../migrations/0005_auto_20190602_1944.py | 19 +++++++++ InvenTree/templates/InvenTree/search.html | 11 +++++ 14 files changed, 97 insertions(+), 21 deletions(-) create mode 100644 InvenTree/part/migrations/0007_auto_20190602_1944.py create mode 100644 InvenTree/stock/migrations/0005_auto_20190602_1944.py diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index 338e664252..71f87ffd19 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -445,9 +445,9 @@ class IndexView(TemplateView): # TODO - Is there a less expensive way to get these from the database context['to_order'] = [part for part in Part.objects.filter(purchaseable=True) if part.need_to_restock()] - # Generate a list of buildable parts which have stock below their minimum values + # Generate a list of assembly parts which have stock below their minimum values # TODO - Is there a less expensive way to get these from the database - context['to_build'] = [part for part in Part.objects.filter(buildable=True) if part.need_to_restock()] + context['to_build'] = [part for part in Part.objects.filter(assembly=True) if part.need_to_restock()] return context diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index acfb02144d..d0beee54ce 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -129,8 +129,8 @@ class PartList(generics.ListCreateAPIView): filter_fields = [ 'is_template', 'variant_of', - 'buildable', - 'consumable', + 'assembly', + 'component', 'trackable', 'purchaseable', 'salable', diff --git a/InvenTree/part/fixtures/part.yaml b/InvenTree/part/fixtures/part.yaml index 632a265e23..7d669cf49d 100644 --- a/InvenTree/part/fixtures/part.yaml +++ b/InvenTree/part/fixtures/part.yaml @@ -57,5 +57,5 @@ fields: name: 'Bob' description: 'Can we build it?' - buildable: true + assembly: true \ No newline at end of file diff --git a/InvenTree/part/forms.py b/InvenTree/part/forms.py index a2ec613429..841622b865 100644 --- a/InvenTree/part/forms.py +++ b/InvenTree/part/forms.py @@ -101,8 +101,8 @@ class EditPartForm(HelperForm): 'default_supplier', 'units', 'minimum_stock', - 'buildable', - 'consumable', + 'assembly', + 'component', 'trackable', 'purchaseable', 'salable', diff --git a/InvenTree/part/migrations/0007_auto_20190602_1944.py b/InvenTree/part/migrations/0007_auto_20190602_1944.py new file mode 100644 index 0000000000..9bfeb7fb8d --- /dev/null +++ b/InvenTree/part/migrations/0007_auto_20190602_1944.py @@ -0,0 +1,42 @@ +# Generated by Django 2.2 on 2019-06-02 09:44 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('part', '0006_auto_20190526_1215'), + ] + + operations = [ + migrations.RemoveField( + model_name='part', + name='buildable', + ), + migrations.RemoveField( + model_name='part', + name='consumable', + ), + migrations.AddField( + model_name='part', + name='assembly', + field=models.BooleanField(default=False, help_text='Can this part be built from other parts?', verbose_name='Assembly'), + ), + migrations.AddField( + model_name='part', + name='component', + field=models.BooleanField(default=True, help_text='Can this part be used to build other parts?', verbose_name='Component'), + ), + migrations.AlterField( + model_name='bomitem', + name='part', + field=models.ForeignKey(help_text='Select parent part', limit_choices_to={'active': True, 'assembly': 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(help_text='Select part to be used in BOM', limit_choices_to={'active': True, 'component': 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 048330c2c6..fa6f40915f 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -201,8 +201,8 @@ class Part(models.Model): minimum_stock: Minimum preferred quantity to keep in stock units: Units of measure for this part (default='pcs') salable: Can this part be sold to customers? - buildable: Can this part be build from other parts? - consumable: Can this part be used to make other parts? + assembly: Can this part be build from other parts? + component: Can this part be used to make other parts? purchaseable: Can this part be purchased from suppliers? trackable: Trackable parts can have unique serial numbers assigned, etc, etc active: Is this part active? Parts are deactivated instead of being deleted @@ -343,9 +343,9 @@ class Part(models.Model): units = models.CharField(max_length=20, default="pcs", blank=True, help_text='Stock keeping units for this part') - buildable = models.BooleanField(default=False, help_text='Can this part be built from other parts?') + assembly = models.BooleanField(default=False, verbose_name='Assembly', help_text='Can this part be built from other parts?') - consumable = models.BooleanField(default=True, help_text='Can this part be used to build other parts?') + component = models.BooleanField(default=True, verbose_name='Component', help_text='Can this part be used to build other parts?') trackable = models.BooleanField(default=False, help_text='Does this part have tracking for unique items?') @@ -858,7 +858,7 @@ class BomItem(models.Model): part = models.ForeignKey(Part, on_delete=models.CASCADE, related_name='bom_items', help_text='Select parent part', limit_choices_to={ - 'buildable': True, + 'assembly': True, 'active': True, }) @@ -867,7 +867,7 @@ class BomItem(models.Model): sub_part = models.ForeignKey(Part, on_delete=models.CASCADE, related_name='used_in', help_text='Select part to be used in BOM', limit_choices_to={ - 'consumable': True, + 'component': True, 'active': True }) diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py index fe858091c7..224e41cd97 100644 --- a/InvenTree/part/serializers.py +++ b/InvenTree/part/serializers.py @@ -94,8 +94,8 @@ class PartSerializer(serializers.ModelSerializer): # 'available_stock', 'units', 'trackable', - 'buildable', - 'consumable', + 'assembly', + 'component', 'trackable', 'salable', 'active', diff --git a/InvenTree/part/templates/part/detail.html b/InvenTree/part/templates/part/detail.html index 4522d47236..b536a5542e 100644 --- a/InvenTree/part/templates/part/detail.html +++ b/InvenTree/part/templates/part/detail.html @@ -100,13 +100,13 @@
- {% if part.buildable %} + {% if part.assembly %} {% endif %} - {% if part.consumable %} + {% if part.component %} diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index d8af6d2ec9..1354a9a4a4 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -78,7 +78,7 @@ - {% if part.buildable %} + {% if part.assembly %} diff --git a/InvenTree/part/templates/part/tabs.html b/InvenTree/part/templates/part/tabs.html index 53a551f36c..dd5034040d 100644 --- a/InvenTree/part/templates/part/tabs.html +++ b/InvenTree/part/templates/part/tabs.html @@ -15,13 +15,13 @@ Allocated {{ part.allocation_count }} {% endif %} - {% if part.buildable %} + {% if part.assembly %} BOM{{ part.bom_count }} Build{{ part.active_builds|length }} {% endif %} - {% if part.consumable or part.used_in_count > 0 %} + {% if part.component or part.used_in_count > 0 %} Used In{% if part.used_in_count > 0 %}{{ part.used_in_count }}{% endif %} {% endif %} diff --git a/InvenTree/part/test_api.py b/InvenTree/part/test_api.py index 15c6f58dcd..b0859e5c1e 100644 --- a/InvenTree/part/test_api.py +++ b/InvenTree/part/test_api.py @@ -149,7 +149,7 @@ class PartAPITest(APITestCase): response = self.client.post(url, data, format='json') self.assertEqual(response.status_code, status.HTTP_201_CREATED) - # Now try to create a BomItem which points to a non-buildable part (should fail) + # Now try to create a BomItem which points to a non-assembly part (should fail) data['part'] = 3 response = self.client.post(url, data, format='json') self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) diff --git a/InvenTree/static/script/inventree/inventree.js b/InvenTree/static/script/inventree/inventree.js index 48ba874262..703c49218b 100644 --- a/InvenTree/static/script/inventree/inventree.js +++ b/InvenTree/static/script/inventree/inventree.js @@ -124,6 +124,10 @@ function imageHoverIcon(url) { * On mouseover, display a full-size version of the image */ + if (!url) { + url = '/static/img/blank_image.png'; + } + var html = ` diff --git a/InvenTree/stock/migrations/0005_auto_20190602_1944.py b/InvenTree/stock/migrations/0005_auto_20190602_1944.py new file mode 100644 index 0000000000..1d134288cc --- /dev/null +++ b/InvenTree/stock/migrations/0005_auto_20190602_1944.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2 on 2019-06-02 09:44 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('stock', '0004_auto_20190525_2356'), + ] + + operations = [ + migrations.AlterField( + model_name='stockitem', + name='status', + field=models.PositiveIntegerField(choices=[(10, 'OK'), (50, 'Attention needed'), (55, 'Damaged'), (60, 'Destroyed'), (70, 'Lost')], default=10, validators=[django.core.validators.MinValueValidator(0)]), + ), + ] diff --git a/InvenTree/templates/InvenTree/search.html b/InvenTree/templates/InvenTree/search.html index 2f88d3caed..7de08fd9b6 100644 --- a/InvenTree/templates/InvenTree/search.html +++ b/InvenTree/templates/InvenTree/search.html @@ -37,17 +37,28 @@ InvenTree | Search Results function onSearchResults(table, output) { $(table).on('load-success.bs.table', function() { + + var panel = $(output).parent('.panel-group'); + var n = $(table).bootstrapTable('getData').length; var text = ''; if (n == 0) { text = 'No results' + + $(panel).hide(); + + $(table).hide(); + + } else { text = n + ' result'; if (n > 1) { text += 's'; } + + $(panel).show(); } $(output).html(text);
Assembly This part can be assembled from other parts
Component This part can be used in assembliesIn Stock {{ part.total_stock }}
Can Build {{ part.can_build }}