diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 25b7ca66f4..5fe39656bf 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -22,6 +22,7 @@ class Part(models.Model): category = models.ForeignKey(PartCategory, on_delete=models.CASCADE) minimum_stock = models.IntegerField(default=0) units = models.CharField(max_length=20, default="pcs", blank=True) + trackable = models.BooleanField(default=False) def __str__(self): if self.IPN: @@ -35,4 +36,18 @@ class Part(models.Model): verbose_name = "Part" verbose_name_plural = "Parts" - \ No newline at end of file +class PartRevision(models.Model): + """ A PartRevision represents a change-notification to a Part + A Part may go through several revisions in its lifetime, + which should be tracked. + UniqueParts can have a single associated PartRevision + """ + + part = models.ForeignKey(Part, on_delete=models.CASCADE) + + name = models.CharField(max_length=100) + description = models.CharField(max_length=500) + revision_date = models.DateField(auto_now_add = True) + + def __str__(self): + return self.name \ No newline at end of file diff --git a/InvenTree/track/admin.py b/InvenTree/track/admin.py index 51037c0176..b6077f2080 100644 --- a/InvenTree/track/admin.py +++ b/InvenTree/track/admin.py @@ -2,4 +2,7 @@ from django.contrib import admin from .models import UniquePart -admin.site.register(UniquePart) \ No newline at end of file +class UniquePartAdmin(admin.ModelAdmin): + list_display = ('part', 'revision', 'serial', 'creation_date') + +admin.site.register(UniquePart, UniquePartAdmin) \ No newline at end of file diff --git a/InvenTree/track/models.py b/InvenTree/track/models.py index 3de10e9cde..145ada6021 100644 --- a/InvenTree/track/models.py +++ b/InvenTree/track/models.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals from django.db import models from django.contrib.auth.models import User -from part.models import Part +from part.models import Part, PartRevision class UniquePart(models.Model): """ A unique instance of a Part object. @@ -12,11 +12,20 @@ class UniquePart(models.Model): """ part = models.ForeignKey(Part, on_delete=models.CASCADE) - created = models.DateField(auto_now_add=True, + + revision = models.ForeignKey(PartRevision, + on_delete=models.CASCADE, + blank=True, + null=True) + + creation_date = models.DateField(auto_now_add=True, editable=False) serial = models.IntegerField() createdBy = models.ForeignKey(User) + + def __str__(self): + return self.part.name class PartTrackingInfo(models.Model): """ Single data-point in the life of a UniquePart