mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 12:06:44 +00:00
commit
f6b3dde1bb
@ -7,4 +7,4 @@ before_install:
|
|||||||
|
|
||||||
script:
|
script:
|
||||||
# TODO - Only perform PEP8 checks on files that have been changed in this push / PR
|
# TODO - Only perform PEP8 checks on files that have been changed in this push / PR
|
||||||
- find . -name \*.py -exec pep8 --ignore=E402,W293 {} +
|
- find . -name \*.py -exec pep8 --ignore=E402,W293,E501 {} +
|
@ -4,6 +4,7 @@ from django.db import models
|
|||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
|
||||||
|
|
||||||
class Company(models.Model):
|
class Company(models.Model):
|
||||||
""" Abstract model representing an external company
|
""" Abstract model representing an external company
|
||||||
"""
|
"""
|
||||||
@ -26,6 +27,7 @@ class Company(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class InvenTreeTree(models.Model):
|
class InvenTreeTree(models.Model):
|
||||||
""" Provides an abstracted self-referencing tree model for data categories.
|
""" Provides an abstracted self-referencing tree model for data categories.
|
||||||
- Each Category has one parent Category, which can be blank (for a top-level Category).
|
- Each Category has one parent Category, which can be blank (for a top-level Category).
|
||||||
@ -41,7 +43,6 @@ class InvenTreeTree(models.Model):
|
|||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
blank=True,
|
blank=True,
|
||||||
null=True)
|
null=True)
|
||||||
#limit_choices_to={id: getAcceptableParents})
|
|
||||||
|
|
||||||
def getUniqueChildren(self, unique=None):
|
def getUniqueChildren(self, unique=None):
|
||||||
""" Return a flat set of all child items that exist under this node.
|
""" Return a flat set of all child items that exist under this node.
|
||||||
@ -58,7 +59,7 @@ class InvenTreeTree(models.Model):
|
|||||||
|
|
||||||
# Some magic to get around the limitations of abstract models
|
# Some magic to get around the limitations of abstract models
|
||||||
contents = ContentType.objects.get_for_model(type(self))
|
contents = ContentType.objects.get_for_model(type(self))
|
||||||
children = contents.get_all_objects_for_this_type(parent = self.id)
|
children = contents.get_all_objects_for_this_type(parent=self.id)
|
||||||
|
|
||||||
for child in children:
|
for child in children:
|
||||||
child.getUniqueChildren(unique)
|
child.getUniqueChildren(unique)
|
||||||
@ -120,7 +121,8 @@ class InvenTreeTree(models.Model):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
if attrname == 'parent_id':
|
if attrname == 'parent_id':
|
||||||
# If current ID is None, continue (as this object is just being created)
|
# If current ID is None, continue
|
||||||
|
# - This object is just being created
|
||||||
if self.id is None:
|
if self.id is None:
|
||||||
pass
|
pass
|
||||||
# Parent cannot be set to same ID (this would cause looping)
|
# Parent cannot be set to same ID (this would cause looping)
|
||||||
|
@ -2,15 +2,15 @@ from django.contrib import admin
|
|||||||
|
|
||||||
from .models import PartCategory, Part
|
from .models import PartCategory, Part
|
||||||
|
|
||||||
|
|
||||||
class PartAdmin(admin.ModelAdmin):
|
class PartAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
list_display = ('name', 'IPN', 'stock', 'category')
|
list_display = ('name', 'IPN', 'stock', 'category')
|
||||||
|
|
||||||
# Custom form for PartCategory
|
|
||||||
class PartCategoryAdmin(admin.ModelAdmin):
|
class PartCategoryAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
list_display = ('name', 'path', 'description')
|
list_display = ('name', 'path', 'description')
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Part, PartAdmin)
|
admin.site.register(Part, PartAdmin)
|
||||||
admin.site.register(PartCategory, PartCategoryAdmin)
|
admin.site.register(PartCategory, PartCategoryAdmin)
|
@ -6,6 +6,7 @@ from django.core.exceptions import ObjectDoesNotExist
|
|||||||
|
|
||||||
from InvenTree.models import InvenTreeTree
|
from InvenTree.models import InvenTreeTree
|
||||||
|
|
||||||
|
|
||||||
class PartCategory(InvenTreeTree):
|
class PartCategory(InvenTreeTree):
|
||||||
""" PartCategory provides hierarchical organization of Part objects.
|
""" PartCategory provides hierarchical organization of Part objects.
|
||||||
"""
|
"""
|
||||||
@ -14,6 +15,7 @@ class PartCategory(InvenTreeTree):
|
|||||||
verbose_name = "Part Category"
|
verbose_name = "Part Category"
|
||||||
verbose_name_plural = "Part Categories"
|
verbose_name_plural = "Part Categories"
|
||||||
|
|
||||||
|
|
||||||
class Part(models.Model):
|
class Part(models.Model):
|
||||||
""" Represents a """
|
""" Represents a """
|
||||||
|
|
||||||
@ -28,8 +30,8 @@ class Part(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.IPN:
|
if self.IPN:
|
||||||
return "{name} ({ipn})".format(
|
return "{name} ({ipn})".format(
|
||||||
ipn = self.IPN,
|
ipn=self.IPN,
|
||||||
name = self.name)
|
name=self.name)
|
||||||
else:
|
else:
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
@ -74,6 +76,7 @@ class Part(models.Model):
|
|||||||
|
|
||||||
return projects
|
return projects
|
||||||
|
|
||||||
|
|
||||||
class PartRevision(models.Model):
|
class PartRevision(models.Model):
|
||||||
""" A PartRevision represents a change-notification to a Part
|
""" A PartRevision represents a change-notification to a Part
|
||||||
A Part may go through several revisions in its lifetime,
|
A Part may go through several revisions in its lifetime,
|
||||||
@ -85,7 +88,7 @@ class PartRevision(models.Model):
|
|||||||
|
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
description = models.CharField(max_length=500)
|
description = models.CharField(max_length=500)
|
||||||
revision_date = models.DateField(auto_now_add = True)
|
revision_date = models.DateField(auto_now_add=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
@ -2,6 +2,7 @@ from rest_framework import serializers
|
|||||||
|
|
||||||
from .models import Part, PartCategory
|
from .models import Part, PartCategory
|
||||||
|
|
||||||
|
|
||||||
class PartSerializer(serializers.ModelSerializer):
|
class PartSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Part
|
model = Part
|
||||||
@ -11,6 +12,7 @@ class PartSerializer(serializers.ModelSerializer):
|
|||||||
'category',
|
'category',
|
||||||
'stock')
|
'stock')
|
||||||
|
|
||||||
|
|
||||||
class PartCategorySerializer(serializers.ModelSerializer):
|
class PartCategorySerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = PartCategory
|
model = PartCategory
|
||||||
|
@ -6,24 +6,29 @@ from rest_framework import generics
|
|||||||
from .models import PartCategory, Part
|
from .models import PartCategory, Part
|
||||||
from .serializers import PartSerializer, PartCategorySerializer
|
from .serializers import PartSerializer, PartCategorySerializer
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
return HttpResponse("Hello world. This is the parts page")
|
return HttpResponse("Hello world. This is the parts page")
|
||||||
|
|
||||||
|
|
||||||
class PartDetail(generics.RetrieveAPIView):
|
class PartDetail(generics.RetrieveAPIView):
|
||||||
|
|
||||||
queryset = Part.objects.all()
|
queryset = Part.objects.all()
|
||||||
serializer_class = PartSerializer
|
serializer_class = PartSerializer
|
||||||
|
|
||||||
|
|
||||||
class PartList(generics.ListAPIView):
|
class PartList(generics.ListAPIView):
|
||||||
|
|
||||||
queryset = Part.objects.all()
|
queryset = Part.objects.all()
|
||||||
serializer_class = PartSerializer
|
serializer_class = PartSerializer
|
||||||
|
|
||||||
|
|
||||||
class PartCategoryDetail(generics.RetrieveAPIView):
|
class PartCategoryDetail(generics.RetrieveAPIView):
|
||||||
|
|
||||||
queryset = PartCategory.objects.all()
|
queryset = PartCategory.objects.all()
|
||||||
serializer_class = PartCategorySerializer
|
serializer_class = PartCategorySerializer
|
||||||
|
|
||||||
|
|
||||||
class PartCategoryList(generics.ListAPIView):
|
class PartCategoryList(generics.ListAPIView):
|
||||||
|
|
||||||
queryset = PartCategory.objects.all()
|
queryset = PartCategory.objects.all()
|
||||||
|
@ -2,12 +2,15 @@ from django.contrib import admin
|
|||||||
|
|
||||||
from .models import ProjectCategory, Project, ProjectPart
|
from .models import ProjectCategory, Project, ProjectPart
|
||||||
|
|
||||||
|
|
||||||
class ProjectCategoryAdmin(admin.ModelAdmin):
|
class ProjectCategoryAdmin(admin.ModelAdmin):
|
||||||
list_display = ('name', 'path', 'description')
|
list_display = ('name', 'path', 'description')
|
||||||
|
|
||||||
|
|
||||||
class ProjectAdmin(admin.ModelAdmin):
|
class ProjectAdmin(admin.ModelAdmin):
|
||||||
list_display = ('name', 'description', 'category')
|
list_display = ('name', 'description', 'category')
|
||||||
|
|
||||||
|
|
||||||
class ProjectPartAdmin(admin.ModelAdmin):
|
class ProjectPartAdmin(admin.ModelAdmin):
|
||||||
list_display = ('part', 'project', 'quantity')
|
list_display = ('part', 'project', 'quantity')
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ from django.db import models
|
|||||||
from InvenTree.models import InvenTreeTree
|
from InvenTree.models import InvenTreeTree
|
||||||
from part.models import Part
|
from part.models import Part
|
||||||
|
|
||||||
|
|
||||||
class ProjectCategory(InvenTreeTree):
|
class ProjectCategory(InvenTreeTree):
|
||||||
""" ProjectCategory provides hierarchical organization of Project objects.
|
""" ProjectCategory provides hierarchical organization of Project objects.
|
||||||
Each ProjectCategory can contain zero-or-more child categories,
|
Each ProjectCategory can contain zero-or-more child categories,
|
||||||
@ -15,6 +16,7 @@ class ProjectCategory(InvenTreeTree):
|
|||||||
verbose_name = "Project Category"
|
verbose_name = "Project Category"
|
||||||
verbose_name_plural = "Project Categories"
|
verbose_name_plural = "Project Categories"
|
||||||
|
|
||||||
|
|
||||||
class Project(models.Model):
|
class Project(models.Model):
|
||||||
""" A Project takes multiple Part objects.
|
""" A Project takes multiple Part objects.
|
||||||
A project can output zero-or-more Part objects
|
A project can output zero-or-more Part objects
|
||||||
@ -33,6 +35,7 @@ class Project(models.Model):
|
|||||||
"""
|
"""
|
||||||
return self.projectpart_set.all()
|
return self.projectpart_set.all()
|
||||||
|
|
||||||
|
|
||||||
class ProjectPart(models.Model):
|
class ProjectPart(models.Model):
|
||||||
""" A project part associates a single part with a project
|
""" A project part associates a single part with a project
|
||||||
The quantity of parts required for a single-run of that project is stored.
|
The quantity of parts required for a single-run of that project is stored.
|
||||||
@ -56,5 +59,5 @@ class ProjectPart(models.Model):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "{quan} x {name}".format(
|
return "{quan} x {name}".format(
|
||||||
name = self.part.name,
|
name=self.part.name,
|
||||||
quan = self.quantity)
|
quan=self.quantity)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from django.shortcuts import render, get_object_or_404
|
from django.shortcuts import render, get_object_or_404
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
return HttpResponse("This is the Projects page")
|
return HttpResponse("This is the Projects page")
|
@ -2,9 +2,11 @@ from django.contrib import admin
|
|||||||
|
|
||||||
from .models import Warehouse, StockItem
|
from .models import Warehouse, StockItem
|
||||||
|
|
||||||
|
|
||||||
class WarehouseAdmin(admin.ModelAdmin):
|
class WarehouseAdmin(admin.ModelAdmin):
|
||||||
list_display = ('name', 'path', 'description')
|
list_display = ('name', 'path', 'description')
|
||||||
|
|
||||||
|
|
||||||
class StockItemAdmin(admin.ModelAdmin):
|
class StockItemAdmin(admin.ModelAdmin):
|
||||||
list_display = ('part', 'quantity', 'location', 'status', 'updated')
|
list_display = ('part', 'quantity', 'location', 'status', 'updated')
|
||||||
|
|
||||||
|
@ -5,9 +5,11 @@ from django.db import models
|
|||||||
from part.models import Part
|
from part.models import Part
|
||||||
from InvenTree.models import InvenTreeTree
|
from InvenTree.models import InvenTreeTree
|
||||||
|
|
||||||
|
|
||||||
class Warehouse(InvenTreeTree):
|
class Warehouse(InvenTreeTree):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class StockItem(models.Model):
|
class StockItem(models.Model):
|
||||||
part = models.ForeignKey(Part,
|
part = models.ForeignKey(Part,
|
||||||
on_delete=models.CASCADE)
|
on_delete=models.CASCADE)
|
||||||
@ -31,6 +33,6 @@ class StockItem(models.Model):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "{n} x {part} @ {loc}".format(
|
return "{n} x {part} @ {loc}".format(
|
||||||
n = self.quantity,
|
n=self.quantity,
|
||||||
part = self.part.name,
|
part=self.part.name,
|
||||||
loc = self.location.name)
|
loc=self.location.name)
|
||||||
|
@ -3,10 +3,9 @@ from django.http import HttpResponse
|
|||||||
|
|
||||||
from .models import Warehouse, StockItem
|
from .models import Warehouse, StockItem
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
|
|
||||||
warehouses = Warehouse.objects.filter(parent = None)
|
warehouses = Warehouse.objects.filter(parent=None)
|
||||||
|
|
||||||
return render(request, 'stock/index.html',
|
return render(request, 'stock/index.html', {'warehouses': warehouses})
|
||||||
{'warehouses': warehouses
|
|
||||||
})
|
|
||||||
|
@ -2,8 +2,9 @@ from django.contrib import admin
|
|||||||
|
|
||||||
from .models import Supplier, SupplierPart, Customer
|
from .models import Supplier, SupplierPart, Customer
|
||||||
|
|
||||||
|
|
||||||
class CompanyAdmin(admin.ModelAdmin):
|
class CompanyAdmin(admin.ModelAdmin):
|
||||||
list_display=('name','URL','contact')
|
list_display = ('name', 'URL', 'contact')
|
||||||
|
|
||||||
admin.site.register(Customer, CompanyAdmin)
|
admin.site.register(Customer, CompanyAdmin)
|
||||||
admin.site.register(Supplier, CompanyAdmin)
|
admin.site.register(Supplier, CompanyAdmin)
|
||||||
|
@ -14,6 +14,8 @@ class Supplier(Company):
|
|||||||
|
|
||||||
|
|
||||||
class Customer(Company):
|
class Customer(Company):
|
||||||
|
""" Represents a customer
|
||||||
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@ -31,13 +33,12 @@ class SupplierPart(models.Model):
|
|||||||
|
|
||||||
MPN = models.CharField(max_length=100)
|
MPN = models.CharField(max_length=100)
|
||||||
URL = models.URLField(blank=True)
|
URL = models.URLField(blank=True)
|
||||||
description = models.CharField(max_length=250,
|
description = models.CharField(max_length=250, blank=True)
|
||||||
blank=True)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "{mpn} - {supplier}".format(
|
return "{mpn} - {supplier}".format(
|
||||||
mpn = self.MPN,
|
mpn=self.MPN,
|
||||||
supplier = self.supplier.name)
|
supplier=self.supplier.name)
|
||||||
|
|
||||||
|
|
||||||
class SupplierPriceBreak(models.Model):
|
class SupplierPriceBreak(models.Model):
|
||||||
|
@ -3,9 +3,11 @@ from django.http import HttpResponse
|
|||||||
|
|
||||||
from .models import Supplier
|
from .models import Supplier
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
return HttpResponse("This is the suppliers page")
|
return HttpResponse("This is the suppliers page")
|
||||||
|
|
||||||
|
|
||||||
def supplierDetail(request, supplier_id):
|
def supplierDetail(request, supplier_id):
|
||||||
supplier = get_object_or_404(Supplier, pk=supplier_id)
|
supplier = get_object_or_404(Supplier, pk=supplier_id)
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ from django.contrib import admin
|
|||||||
|
|
||||||
from .models import UniquePart
|
from .models import UniquePart
|
||||||
|
|
||||||
|
|
||||||
class UniquePartAdmin(admin.ModelAdmin):
|
class UniquePartAdmin(admin.ModelAdmin):
|
||||||
list_display = ('part', 'revision', 'serial', 'creation_date')
|
list_display = ('part', 'revision', 'serial', 'creation_date')
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from django.shortcuts import render, get_object_or_404
|
from django.shortcuts import render, get_object_or_404
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
return HttpResponse("This is the Tracking page")
|
return HttpResponse("This is the Tracking page")
|
Loading…
x
Reference in New Issue
Block a user