diff --git a/InvenTree/part/admin.py b/InvenTree/part/admin.py index 71bdeeadd8..d1c025c6fb 100644 --- a/InvenTree/part/admin.py +++ b/InvenTree/part/admin.py @@ -8,7 +8,7 @@ from .models import PartAttachment class PartAdmin(ImportExportModelAdmin): - list_display = ('name', 'IPN', 'description', 'stock', 'category') + list_display = ('name', 'IPN', 'description', 'total_stock', 'category') class PartCategoryAdmin(admin.ModelAdmin): diff --git a/InvenTree/part/forms.py b/InvenTree/part/forms.py index 6eec8fa3c4..f986e1a0ae 100644 --- a/InvenTree/part/forms.py +++ b/InvenTree/part/forms.py @@ -25,6 +25,7 @@ class EditPartForm(forms.ModelForm): 'IPN', 'URL', 'minimum_stock', + 'buildable', 'trackable', 'purchaseable', ] @@ -58,7 +59,7 @@ class EditBomItemForm(forms.ModelForm): self.helper.form_id = 'id-edit-part-form' self.helper.form_method = 'post' - + self.helper.add_input(Submit('submit', 'Submit')) class Meta: diff --git a/InvenTree/part/migrations/0018_part_buildable.py b/InvenTree/part/migrations/0018_part_buildable.py new file mode 100644 index 0000000000..8c4ca8d631 --- /dev/null +++ b/InvenTree/part/migrations/0018_part_buildable.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2018-04-16 12:08 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('part', '0017_part_purchaseable'), + ] + + operations = [ + migrations.AddField( + model_name='part', + name='buildable', + field=models.BooleanField(default=False), + ), + ] diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index bf421cef3b..f0e1b7a436 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -110,6 +110,9 @@ 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? + buildable = models.BooleanField(default=False) + # Is this part "trackable"? # Trackable parts can have unique instances # which are assigned serial numbers (or batch numbers) @@ -139,7 +142,8 @@ class Part(models.Model): """ # TODO - For now, just return total stock count - return self.stock + # TODO - In future must take account of allocated stock + return self.total_stock @property def can_build(self): @@ -152,6 +156,7 @@ class Part(models.Model): total = None + # Calculate the minimum number of parts that can be built using each sub-part for item in self.bom_items.all(): stock = item.sub_part.available_stock n = int(1.0 * stock / item.quantity) @@ -162,7 +167,7 @@ class Part(models.Model): return total @property - def stock(self): + def total_stock(self): """ Return the total stock quantity for this part. Part may be stored in multiple locations """ @@ -176,16 +181,21 @@ class Part(models.Model): @property def has_bom(self): - return self.bom_item_count > 0 + return self.bom_count > 0 @property - def bom_item_count(self): + def bom_count(self): return self.bom_items.all().count() @property def used_in_count(self): return self.used_in.all().count() + @property + def supplier_count(self): + # Return the number of supplier parts available for this part + return self.supplier_parts.all().count() + """ @property def projects(self): diff --git a/InvenTree/part/templates/part/detail.html b/InvenTree/part/templates/part/detail.html index 3d38521dca..766a9bbf71 100644 --- a/InvenTree/part/templates/part/detail.html +++ b/InvenTree/part/templates/part/detail.html @@ -25,6 +25,10 @@