From 492c65132487601f79364a8ad0c5df10106a33df Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 28 Mar 2017 17:49:01 +1100 Subject: [PATCH 1/5] Improved admin view for part --- InvenTree/InvenTree/models.py | 18 ++++++++++-------- InvenTree/part/admin.py | 8 +++++--- InvenTree/part/models.py | 2 ++ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/InvenTree/InvenTree/models.py b/InvenTree/InvenTree/models.py index f607ffa19a..6c2d10d866 100644 --- a/InvenTree/InvenTree/models.py +++ b/InvenTree/InvenTree/models.py @@ -61,7 +61,7 @@ class InvenTreeTree(models.Model): return acceptable @property - def path(self): + def parentpath(self): """ Return the parent path of this category Todo: @@ -70,11 +70,16 @@ class InvenTreeTree(models.Model): """ if self.parent: - return self.parent.path + [self.parent] + return self.parent.parentpath + [self.parent] else: return [] - - return parent_path + + @property + def path(self): + if self.parent: + return "/".join([p.name for p in self.parentpath]) + "/" + self.name + else: + return self.name def __setattr__(self, attrname, val): """ Custom Attribute Setting function @@ -118,10 +123,7 @@ class InvenTreeTree(models.Model): This is recursive - Make it not so. """ - if self.parent: - return "/".join([p.name for p in self.path]) + "/" + self.name - else: - return self.name + return self.path class Meta: diff --git a/InvenTree/part/admin.py b/InvenTree/part/admin.py index 34e1ad40e6..fd2b241d21 100644 --- a/InvenTree/part/admin.py +++ b/InvenTree/part/admin.py @@ -2,12 +2,14 @@ from django.contrib import admin from .models import PartCategory, Part -admin.site.register(Part) +class PartAdmin(admin.ModelAdmin): + list_display = ('name', 'IPN', 'category') # Custom form for PartCategory class PartCategoryAdmin(admin.ModelAdmin): - # TODO - Only let valid parents be displayed - pass + + list_display = ('name', 'path') +admin.site.register(Part, PartAdmin) admin.site.register(PartCategory, PartCategoryAdmin) \ No newline at end of file diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 12394719e4..25b7ca66f4 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -20,6 +20,8 @@ class Part(models.Model): description = models.CharField(max_length=250, blank=True) IPN = models.CharField(max_length=100, blank=True) category = models.ForeignKey(PartCategory, on_delete=models.CASCADE) + minimum_stock = models.IntegerField(default=0) + units = models.CharField(max_length=20, default="pcs", blank=True) def __str__(self): if self.IPN: From a082eb2c8181459cdf3278c4360205365e7ff41c Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 28 Mar 2017 17:53:54 +1100 Subject: [PATCH 2/5] Improved project admin --- InvenTree/part/admin.py | 3 ++- InvenTree/project/admin.py | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/InvenTree/part/admin.py b/InvenTree/part/admin.py index fd2b241d21..cc0bd7dffb 100644 --- a/InvenTree/part/admin.py +++ b/InvenTree/part/admin.py @@ -3,11 +3,12 @@ from django.contrib import admin from .models import PartCategory, Part class PartAdmin(admin.ModelAdmin): + list_display = ('name', 'IPN', 'category') # Custom form for PartCategory class PartCategoryAdmin(admin.ModelAdmin): - + list_display = ('name', 'path') diff --git a/InvenTree/project/admin.py b/InvenTree/project/admin.py index 043b785587..081d29b9f9 100644 --- a/InvenTree/project/admin.py +++ b/InvenTree/project/admin.py @@ -2,6 +2,15 @@ from django.contrib import admin from .models import ProjectCategory, Project, ProjectPart -admin.site.register(ProjectCategory) -admin.site.register(Project) -admin.site.register(ProjectPart) \ No newline at end of file +class ProjectCategoryAdmin(admin.ModelAdmin): + list_display = ('name','path') + +class ProjectAdmin(admin.ModelAdmin): + list_display = ('name', 'description', 'category') + +class ProjectPartAdmin(admin.ModelAdmin): + list_display = ('part', 'project', 'quantity') + +admin.site.register(ProjectCategory, ProjectCategoryAdmin) +admin.site.register(Project, ProjectAdmin) +admin.site.register(ProjectPart, ProjectPartAdmin) \ No newline at end of file From 155151e98bc15fc92cb72314f4bf512d7da33589 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 28 Mar 2017 17:59:28 +1100 Subject: [PATCH 3/5] More admin updates --- InvenTree/part/admin.py | 2 +- InvenTree/stock/admin.py | 10 ++++++++-- InvenTree/supplier/admin.py | 5 ++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/InvenTree/part/admin.py b/InvenTree/part/admin.py index cc0bd7dffb..fce0c2d257 100644 --- a/InvenTree/part/admin.py +++ b/InvenTree/part/admin.py @@ -9,7 +9,7 @@ class PartAdmin(admin.ModelAdmin): # Custom form for PartCategory class PartCategoryAdmin(admin.ModelAdmin): - list_display = ('name', 'path') + list_display = ('name', 'path', 'description') admin.site.register(Part, PartAdmin) diff --git a/InvenTree/stock/admin.py b/InvenTree/stock/admin.py index 0ddf5d0b3e..4a6b7be4c0 100644 --- a/InvenTree/stock/admin.py +++ b/InvenTree/stock/admin.py @@ -2,5 +2,11 @@ from django.contrib import admin from .models import Warehouse, StockItem -admin.site.register(Warehouse) -admin.site.register(StockItem) \ No newline at end of file +class WarehouseAdmin(admin.ModelAdmin): + list_display = ('name', 'path', 'description') + +class StockItemAdmin(admin.ModelAdmin): + list_display = ('part', 'quantity', 'location', 'updated') + +admin.site.register(Warehouse, WarehouseAdmin) +admin.site.register(StockItem, StockItemAdmin) \ No newline at end of file diff --git a/InvenTree/supplier/admin.py b/InvenTree/supplier/admin.py index 74b182d9f8..4b76c26e0f 100644 --- a/InvenTree/supplier/admin.py +++ b/InvenTree/supplier/admin.py @@ -2,5 +2,8 @@ from django.contrib import admin from .models import Supplier, SupplierPart -admin.site.register(Supplier) +class SupplierAdmin(admin.ModelAdmin): + list_display=('name','URL','contact') + +admin.site.register(Supplier, SupplierAdmin) admin.site.register(SupplierPart) \ No newline at end of file From 6aa9f14b46aaa3ac2076fa6e66cbaa246e9ee3b0 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 28 Mar 2017 18:03:55 +1100 Subject: [PATCH 4/5] Fixed part display bug --- InvenTree/part/templates/part/category.html | 2 +- InvenTree/project/admin.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/InvenTree/part/templates/part/category.html b/InvenTree/part/templates/part/category.html index 70d4bd6246..8e999ea96c 100644 --- a/InvenTree/part/templates/part/category.html +++ b/InvenTree/part/templates/part/category.html @@ -1,6 +1,6 @@ {# Construct the category path #} Category/ -{% for path_item in category.path %} +{% for path_item in category.parentpath %} {{ path_item.name }}/ {% endfor %} diff --git a/InvenTree/project/admin.py b/InvenTree/project/admin.py index 081d29b9f9..f266fb3612 100644 --- a/InvenTree/project/admin.py +++ b/InvenTree/project/admin.py @@ -3,7 +3,7 @@ from django.contrib import admin from .models import ProjectCategory, Project, ProjectPart class ProjectCategoryAdmin(admin.ModelAdmin): - list_display = ('name','path') + list_display = ('name', 'path', 'description') class ProjectAdmin(admin.ModelAdmin): list_display = ('name', 'description', 'category') From be030991a523da8d3b57b52cd1e9b9c45f43c79b Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 28 Mar 2017 18:17:32 +1100 Subject: [PATCH 5/5] Added PartRevision model - Added 'trackable' field to Part --- InvenTree/part/models.py | 17 ++++++++++++++++- InvenTree/track/admin.py | 5 ++++- InvenTree/track/models.py | 13 +++++++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) 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