From 6e2b111b9c2c07476c0683c4c8e0e89a37210099 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 16 Apr 2019 00:01:15 +1000 Subject: [PATCH] Add 'consumable' field to Part - Indicates that a part can be used to make other parts - This is the inverse of 'buildable' - Add this field to the serializer and edit forms - Display parameter on part info page - BOM edit window only requests sub-parts that are marked as 'consumable' - Also added option to edit 'units' field for part --- InvenTree/part/api.py | 5 +++++ InvenTree/part/forms.py | 2 ++ .../part/migrations/0005_part_consumable.py | 18 ++++++++++++++++++ InvenTree/part/models.py | 5 ++++- InvenTree/part/serializers.py | 1 + InvenTree/part/templates/part/detail.html | 8 ++++++-- InvenTree/part/templates/part/part_base.html | 2 +- InvenTree/part/templates/part/tabs.html | 2 +- 8 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 InvenTree/part/migrations/0005_part_consumable.py diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index 61e91bc2e1..bbb44a14e6 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -107,6 +107,11 @@ class PartList(generics.ListCreateAPIView): ] filter_fields = [ + 'buildable', + 'consumable', + 'trackable', + 'purchaseable', + 'salable', ] ordering_fields = [ diff --git a/InvenTree/part/forms.py b/InvenTree/part/forms.py index 294da2f114..19f899c919 100644 --- a/InvenTree/part/forms.py +++ b/InvenTree/part/forms.py @@ -48,8 +48,10 @@ class EditPartForm(HelperForm): 'URL', 'default_location', 'default_supplier', + 'units', 'minimum_stock', 'buildable', + 'consumable', 'trackable', 'purchaseable', 'salable', diff --git a/InvenTree/part/migrations/0005_part_consumable.py b/InvenTree/part/migrations/0005_part_consumable.py new file mode 100644 index 0000000000..4bb1056ae7 --- /dev/null +++ b/InvenTree/part/migrations/0005_part_consumable.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2 on 2019-04-15 13:48 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('part', '0004_bomitem_note'), + ] + + operations = [ + migrations.AddField( + model_name='part', + name='consumable', + field=models.BooleanField(default=False, help_text='Can this part be used to build other parts?'), + ), + ] diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 2f65744139..bcb9163c7d 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -126,9 +126,12 @@ class Part(models.Model): # Units of quantity for this part. Default is "pcs" units = models.CharField(max_length=20, default="pcs", blank=True) - # Can this part be built? + # Can this part be built from other parts? buildable = models.BooleanField(default=False, help_text='Can this part be built from other parts?') + # Can this part be used to make other parts? + consumable = models.BooleanField(default=True, help_text='Can this part be used to build other parts?') + # Is this part "trackable"? # Trackable parts can have unique instances # which are assigned serial numbers (or batch numbers) diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py index d037e86499..5e2596d126 100644 --- a/InvenTree/part/serializers.py +++ b/InvenTree/part/serializers.py @@ -61,6 +61,7 @@ class PartSerializer(serializers.ModelSerializer): 'units', 'trackable', 'buildable', + 'consumable', 'trackable', 'salable', ] diff --git a/InvenTree/part/templates/part/detail.html b/InvenTree/part/templates/part/detail.html index c43aec77eb..b340ec35c5 100644 --- a/InvenTree/part/templates/part/detail.html +++ b/InvenTree/part/templates/part/detail.html @@ -32,7 +32,7 @@ Description - {{ part.decription }} + {{ part.description }} {% if part.IPN %} @@ -44,7 +44,7 @@ Category {% if part.category %} - {{ part.category.name }} + {{ part.category.pathstring }} {% endif %} @@ -70,6 +70,10 @@ Buildable {% include "yesnolabel.html" with value=part.buildable %} + + Consumable + {% include "yesnolabel.html" with value=part.consumable %} + Trackable {% include "yesnolabel.html" with value=part.trackable %} diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index f7314a41a3..bd6859777e 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -37,7 +37,7 @@
-

Stock Status - {{ part.available_stock }} available

+

Stock Status - {{ part.available_stock }}{% if part.units %} {{ part.units }} {% endif%} available

diff --git a/InvenTree/part/templates/part/tabs.html b/InvenTree/part/templates/part/tabs.html index 3c5773b8e2..aa9d798bb7 100644 --- a/InvenTree/part/templates/part/tabs.html +++ b/InvenTree/part/templates/part/tabs.html @@ -7,7 +7,7 @@ Build{{ part.active_builds|length }} {% endif %} - {% if part.used_in_count > 0 %} + {% if part.consumable or part.used_in_count > 0 %} Used In{% if part.used_in_count > 0 %}{{ part.used_in_count }}{% endif %} {% endif %}
In Stock