diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index 46a15cfc62..27a5b24894 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -70,7 +70,7 @@ class CategoryDetail(generics.RetrieveUpdateDestroyAPIView): queryset = PartCategory.objects.all() -class PartDetail(generics.RetrieveUpdateDestroyAPIView): +class PartDetail(generics.RetrieveUpdateAPIView): """ API endpoint for detail view of a single Part object """ queryset = Part.objects.all() serializer_class = PartSerializer @@ -135,6 +135,7 @@ class PartList(generics.ListCreateAPIView): 'trackable', 'purchaseable', 'salable', + 'active', ] ordering_fields = [ diff --git a/InvenTree/part/migrations/0012_part_active.py b/InvenTree/part/migrations/0012_part_active.py new file mode 100644 index 0000000000..c2f3b55f6c --- /dev/null +++ b/InvenTree/part/migrations/0012_part_active.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2 on 2019-04-28 13:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('part', '0011_auto_20190428_0841'), + ] + + operations = [ + migrations.AddField( + model_name='part', + name='active', + field=models.BooleanField(default=True, help_text='Is this part active?'), + ), + ] diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 887c983511..04d5471f92 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -171,6 +171,9 @@ class Part(models.Model): # Can this part be sold to customers? salable = models.BooleanField(default=False, help_text="Can this part be sold to customers?") + # Is this part active? + active = models.BooleanField(default=True, help_text='Is this part active?') + notes = models.TextField(blank=True) def __str__(self): diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py index 0344e46fe7..e5c23b730a 100644 --- a/InvenTree/part/serializers.py +++ b/InvenTree/part/serializers.py @@ -53,6 +53,7 @@ class PartSerializer(serializers.ModelSerializer): class Meta: model = Part + partial = True fields = [ 'pk', 'url', # Link to the part detail page @@ -70,6 +71,7 @@ class PartSerializer(serializers.ModelSerializer): 'consumable', 'trackable', 'salable', + 'active', ] diff --git a/InvenTree/part/templates/part/build.html b/InvenTree/part/templates/part/build.html index 999fe7e231..84642f4de8 100644 --- a/InvenTree/part/templates/part/build.html +++ b/InvenTree/part/templates/part/build.html @@ -7,7 +7,9 @@

Part Builds

+ {% if part.active %} + {% endif %}
diff --git a/InvenTree/part/templates/part/category.html b/InvenTree/part/templates/part/category.html index cc10828f80..3d514389bc 100644 --- a/InvenTree/part/templates/part/category.html +++ b/InvenTree/part/templates/part/category.html @@ -115,16 +115,15 @@ method: 'get', pagination: true, rememberOrder: true, - {% if category %} queryParams: function(p) { return { + active: true, {% if category %} category: {{ category.id }}, include_child_categories: true, {% endif %} } }, - {% endif %} columns: [ { checkbox: true, @@ -160,7 +159,7 @@ else { return ''; } - } + } }, { field: 'total_stock', diff --git a/InvenTree/part/templates/part/detail.html b/InvenTree/part/templates/part/detail.html index f0bdc49df2..7b148318c9 100644 --- a/InvenTree/part/templates/part/detail.html +++ b/InvenTree/part/templates/part/detail.html @@ -17,7 +17,12 @@
  • Duplicate
  • Edit
  • Stocktake
  • -
  • Delete
  • +
    + {% if part.active %} +
  • Deactivate
  • + {% else %} +
  • Activate
  • + {% endif %} @@ -141,6 +146,33 @@ }); }); + $('#activate-part').click(function() { + inventreeUpdate( + "{% url 'api-part-detail' part.id %}", + { + active: true, + }, + { + method: 'PATCH', + reloadOnSuccess: true, + } + ); + }); + + $('#deactivate-part').click(function() { + inventreeUpdate( + "{% url 'api-part-detail' part.id %}", + { + active: false, + }, + { + method: 'PATCH', + reloadOnSuccess: true, + } + ); + }); + + $('#delete-part').click(function() { launchDeleteForm( "{% url 'part-delete' part.id %}", diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index ceda740c16..79be275307 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -5,6 +5,11 @@ {% block content %}
    + {% if part.active == False %} +
    + This part ({{ part.name }}) is not active: +
    + {% endif %}
    @@ -16,7 +21,7 @@ {% endif %}/>
    -

    {{ part.name }}

    +

    {{ part.name }}{% if part.active == False %} - INACTIVE{% endif %}

    {% if part.description %}

    {{ part.description }}

    {% endif %} diff --git a/InvenTree/part/templates/part/stock.html b/InvenTree/part/templates/part/stock.html index a821652aae..fb620c1b7b 100644 --- a/InvenTree/part/templates/part/stock.html +++ b/InvenTree/part/templates/part/stock.html @@ -7,7 +7,9 @@

    Part Stock

    + {% if part.active %} + {% endif %}