mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
commit
f6b3dde1bb
@ -7,4 +7,4 @@ before_install:
|
||||
|
||||
script:
|
||||
# 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.contrib.contenttypes.models import ContentType
|
||||
|
||||
|
||||
class Company(models.Model):
|
||||
""" Abstract model representing an external company
|
||||
"""
|
||||
@ -22,10 +23,11 @@ class Company(models.Model):
|
||||
blank=True)
|
||||
notes = models.CharField(max_length=500,
|
||||
blank=True)
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class InvenTreeTree(models.Model):
|
||||
""" 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).
|
||||
@ -41,7 +43,6 @@ class InvenTreeTree(models.Model):
|
||||
on_delete=models.CASCADE,
|
||||
blank=True,
|
||||
null=True)
|
||||
#limit_choices_to={id: getAcceptableParents})
|
||||
|
||||
def getUniqueChildren(self, unique=None):
|
||||
""" 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
|
||||
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:
|
||||
child.getUniqueChildren(unique)
|
||||
@ -74,7 +75,7 @@ class InvenTreeTree(models.Model):
|
||||
|
||||
available = contents.get_all_objects_for_this_type()
|
||||
|
||||
# List of child IDs
|
||||
# List of child IDs
|
||||
childs = getUniqueChildren()
|
||||
|
||||
acceptable = [None]
|
||||
@ -99,7 +100,7 @@ class InvenTreeTree(models.Model):
|
||||
else:
|
||||
return []
|
||||
|
||||
@property
|
||||
@property
|
||||
def path(self):
|
||||
if self.parent:
|
||||
return "/".join([p.name for p in self.parentpath]) + "/" + self.name
|
||||
@ -120,7 +121,8 @@ class InvenTreeTree(models.Model):
|
||||
"""
|
||||
|
||||
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:
|
||||
pass
|
||||
# Parent cannot be set to same ID (this would cause looping)
|
||||
@ -129,18 +131,18 @@ class InvenTreeTree(models.Model):
|
||||
# Null parent is OK
|
||||
elif val is None:
|
||||
pass
|
||||
# Ensure that the new parent is not already a child
|
||||
# Ensure that the new parent is not already a child
|
||||
else:
|
||||
kids = self.getUniqueChildren()
|
||||
if val in kids:
|
||||
return
|
||||
|
||||
|
||||
# Prohibit certain characters from tree node names
|
||||
elif attrname == 'name':
|
||||
val = val.translate({ord(c): None for c in "!@#$%^&*'\"\\/[]{}<>,|+=~`"})
|
||||
|
||||
super(InvenTreeTree, self).__setattr__(attrname, val)
|
||||
|
||||
|
||||
def __str__(self):
|
||||
""" String representation of a category is the full path to that category
|
||||
|
||||
@ -148,4 +150,4 @@ class InvenTreeTree(models.Model):
|
||||
This is recursive - Make it not so.
|
||||
"""
|
||||
|
||||
return self.path
|
||||
return self.path
|
||||
|
@ -2,15 +2,15 @@ from django.contrib import admin
|
||||
|
||||
from .models import PartCategory, Part
|
||||
|
||||
|
||||
class PartAdmin(admin.ModelAdmin):
|
||||
|
||||
list_display = ('name', 'IPN', 'stock', 'category')
|
||||
|
||||
# Custom form for PartCategory
|
||||
|
||||
class PartCategoryAdmin(admin.ModelAdmin):
|
||||
|
||||
|
||||
list_display = ('name', 'path', 'description')
|
||||
|
||||
|
||||
admin.site.register(Part, PartAdmin)
|
||||
admin.site.register(PartCategory, PartCategoryAdmin)
|
||||
admin.site.register(PartCategory, PartCategoryAdmin)
|
||||
|
@ -6,7 +6,8 @@ from django.core.exceptions import ObjectDoesNotExist
|
||||
|
||||
from InvenTree.models import InvenTreeTree
|
||||
|
||||
class PartCategory(InvenTreeTree):
|
||||
|
||||
class PartCategory(InvenTreeTree):
|
||||
""" PartCategory provides hierarchical organization of Part objects.
|
||||
"""
|
||||
|
||||
@ -14,6 +15,7 @@ class PartCategory(InvenTreeTree):
|
||||
verbose_name = "Part Category"
|
||||
verbose_name_plural = "Part Categories"
|
||||
|
||||
|
||||
class Part(models.Model):
|
||||
""" Represents a """
|
||||
|
||||
@ -28,8 +30,8 @@ class Part(models.Model):
|
||||
def __str__(self):
|
||||
if self.IPN:
|
||||
return "{name} ({ipn})".format(
|
||||
ipn = self.IPN,
|
||||
name = self.name)
|
||||
ipn=self.IPN,
|
||||
name=self.name)
|
||||
else:
|
||||
return self.name
|
||||
|
||||
@ -74,6 +76,7 @@ class Part(models.Model):
|
||||
|
||||
return projects
|
||||
|
||||
|
||||
class PartRevision(models.Model):
|
||||
""" A PartRevision represents a change-notification to a Part
|
||||
A Part may go through several revisions in its lifetime,
|
||||
@ -85,7 +88,7 @@ class PartRevision(models.Model):
|
||||
|
||||
name = models.CharField(max_length=100)
|
||||
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):
|
||||
return self.name
|
||||
return self.name
|
||||
|
@ -2,6 +2,7 @@ from rest_framework import serializers
|
||||
|
||||
from .models import Part, PartCategory
|
||||
|
||||
|
||||
class PartSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Part
|
||||
@ -11,10 +12,11 @@ class PartSerializer(serializers.ModelSerializer):
|
||||
'category',
|
||||
'stock')
|
||||
|
||||
|
||||
class PartCategorySerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = PartCategory
|
||||
fields = ('pk',
|
||||
'name',
|
||||
'description',
|
||||
'path')
|
||||
'path')
|
||||
|
@ -14,4 +14,4 @@ urlpatterns = [
|
||||
|
||||
# Display list of parts
|
||||
url(r'^$', views.PartList.as_view())
|
||||
]
|
||||
]
|
||||
|
@ -6,25 +6,30 @@ from rest_framework import generics
|
||||
from .models import PartCategory, Part
|
||||
from .serializers import PartSerializer, PartCategorySerializer
|
||||
|
||||
|
||||
def index(request):
|
||||
return HttpResponse("Hello world. This is the parts page")
|
||||
|
||||
|
||||
class PartDetail(generics.RetrieveAPIView):
|
||||
|
||||
queryset = Part.objects.all()
|
||||
serializer_class = PartSerializer
|
||||
|
||||
|
||||
class PartList(generics.ListAPIView):
|
||||
|
||||
queryset = Part.objects.all()
|
||||
serializer_class = PartSerializer
|
||||
|
||||
|
||||
class PartCategoryDetail(generics.RetrieveAPIView):
|
||||
|
||||
queryset = PartCategory.objects.all()
|
||||
serializer_class = PartCategorySerializer
|
||||
|
||||
|
||||
|
||||
class PartCategoryList(generics.ListAPIView):
|
||||
|
||||
queryset = PartCategory.objects.all()
|
||||
serializer_class = PartCategorySerializer
|
||||
serializer_class = PartCategorySerializer
|
||||
|
@ -2,15 +2,18 @@ from django.contrib import admin
|
||||
|
||||
from .models import ProjectCategory, Project, ProjectPart
|
||||
|
||||
|
||||
class ProjectCategoryAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'path', 'description')
|
||||
|
||||
|
||||
|
||||
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)
|
||||
admin.site.register(ProjectPart, ProjectPartAdmin)
|
||||
|
@ -5,6 +5,7 @@ from django.db import models
|
||||
from InvenTree.models import InvenTreeTree
|
||||
from part.models import Part
|
||||
|
||||
|
||||
class ProjectCategory(InvenTreeTree):
|
||||
""" ProjectCategory provides hierarchical organization of Project objects.
|
||||
Each ProjectCategory can contain zero-or-more child categories,
|
||||
@ -15,6 +16,7 @@ class ProjectCategory(InvenTreeTree):
|
||||
verbose_name = "Project Category"
|
||||
verbose_name_plural = "Project Categories"
|
||||
|
||||
|
||||
class Project(models.Model):
|
||||
""" A Project takes multiple Part objects.
|
||||
A project can output zero-or-more Part objects
|
||||
@ -33,11 +35,12 @@ class Project(models.Model):
|
||||
"""
|
||||
return self.projectpart_set.all()
|
||||
|
||||
|
||||
class ProjectPart(models.Model):
|
||||
""" 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 overage is the number of extra parts that are generally used for a single run.
|
||||
"""
|
||||
"""
|
||||
|
||||
# Overage types
|
||||
OVERAGE_PERCENT = 0
|
||||
@ -50,11 +53,11 @@ class ProjectPart(models.Model):
|
||||
overage_type = models.IntegerField(
|
||||
default=1,
|
||||
choices=[
|
||||
(OVERAGE_PERCENT, "Percent"),
|
||||
(OVERAGE_ABSOLUTE, "Absolute")
|
||||
(OVERAGE_PERCENT, "Percent"),
|
||||
(OVERAGE_ABSOLUTE, "Absolute")
|
||||
])
|
||||
|
||||
def __str__(self):
|
||||
return "{quan} x {name}".format(
|
||||
name = self.part.name,
|
||||
quan = self.quantity)
|
||||
name=self.part.name,
|
||||
quan=self.quantity)
|
||||
|
@ -4,4 +4,4 @@ from . import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', views.index, name='index')
|
||||
]
|
||||
]
|
||||
|
@ -1,5 +1,6 @@
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from django.http import HttpResponse
|
||||
|
||||
|
||||
def index(request):
|
||||
return HttpResponse("This is the Projects page")
|
||||
return HttpResponse("This is the Projects page")
|
||||
|
@ -2,11 +2,13 @@ from django.contrib import admin
|
||||
|
||||
from .models import Warehouse, StockItem
|
||||
|
||||
|
||||
class WarehouseAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'path', 'description')
|
||||
|
||||
|
||||
|
||||
class StockItemAdmin(admin.ModelAdmin):
|
||||
list_display = ('part', 'quantity', 'location', 'status', 'updated')
|
||||
|
||||
admin.site.register(Warehouse, WarehouseAdmin)
|
||||
admin.site.register(StockItem, StockItemAdmin)
|
||||
admin.site.register(StockItem, StockItemAdmin)
|
||||
|
@ -5,9 +5,11 @@ from django.db import models
|
||||
from part.models import Part
|
||||
from InvenTree.models import InvenTreeTree
|
||||
|
||||
|
||||
class Warehouse(InvenTreeTree):
|
||||
pass
|
||||
|
||||
|
||||
class StockItem(models.Model):
|
||||
part = models.ForeignKey(Part,
|
||||
on_delete=models.CASCADE)
|
||||
@ -23,14 +25,14 @@ class StockItem(models.Model):
|
||||
|
||||
status = models.IntegerField(default=ITEM_IN_PROGRESS,
|
||||
choices=[
|
||||
(ITEM_IN_PROGRESS, "In progress"),
|
||||
(ITEM_DAMAGED, "Damaged"),
|
||||
(ITEM_ATTENTION, "Requires attention"),
|
||||
(ITEM_COMPLETE, "Complete")
|
||||
(ITEM_IN_PROGRESS, "In progress"),
|
||||
(ITEM_DAMAGED, "Damaged"),
|
||||
(ITEM_ATTENTION, "Requires attention"),
|
||||
(ITEM_COMPLETE, "Complete")
|
||||
])
|
||||
|
||||
def __str__(self):
|
||||
return "{n} x {part} @ {loc}".format(
|
||||
n = self.quantity,
|
||||
part = self.part.name,
|
||||
loc = self.location.name)
|
||||
n=self.quantity,
|
||||
part=self.part.name,
|
||||
loc=self.location.name)
|
||||
|
@ -3,5 +3,5 @@ from django.conf.urls import url
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', views.index, name='index')
|
||||
]
|
||||
url(r'^$', views.index, name='index')
|
||||
]
|
||||
|
@ -3,10 +3,9 @@ from django.http import HttpResponse
|
||||
|
||||
from .models import Warehouse, StockItem
|
||||
|
||||
|
||||
def index(request):
|
||||
|
||||
warehouses = Warehouse.objects.filter(parent = None)
|
||||
warehouses = Warehouse.objects.filter(parent=None)
|
||||
|
||||
return render(request, 'stock/index.html',
|
||||
{'warehouses': warehouses
|
||||
})
|
||||
return render(request, 'stock/index.html', {'warehouses': warehouses})
|
||||
|
@ -2,9 +2,10 @@ from django.contrib import admin
|
||||
|
||||
from .models import Supplier, SupplierPart, Customer
|
||||
|
||||
|
||||
class CompanyAdmin(admin.ModelAdmin):
|
||||
list_display=('name','URL','contact')
|
||||
list_display = ('name', 'URL', 'contact')
|
||||
|
||||
admin.site.register(Customer, CompanyAdmin)
|
||||
admin.site.register(Supplier, CompanyAdmin)
|
||||
admin.site.register(SupplierPart)
|
||||
admin.site.register(SupplierPart)
|
||||
|
@ -14,6 +14,8 @@ class Supplier(Company):
|
||||
|
||||
|
||||
class Customer(Company):
|
||||
""" Represents a customer
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
@ -31,13 +33,12 @@ class SupplierPart(models.Model):
|
||||
|
||||
MPN = models.CharField(max_length=100)
|
||||
URL = models.URLField(blank=True)
|
||||
description = models.CharField(max_length=250,
|
||||
blank=True)
|
||||
description = models.CharField(max_length=250, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return "{mpn} - {supplier}".format(
|
||||
mpn = self.MPN,
|
||||
supplier = self.supplier.name)
|
||||
mpn=self.MPN,
|
||||
supplier=self.supplier.name)
|
||||
|
||||
|
||||
class SupplierPriceBreak(models.Model):
|
||||
@ -58,4 +59,4 @@ class SupplierPriceBreak(models.Model):
|
||||
mpn=part.MPN,
|
||||
cost=self.cost,
|
||||
currency=self.currency if self.currency else '',
|
||||
quan=self.quantity)
|
||||
quan=self.quantity)
|
||||
|
@ -8,4 +8,4 @@ urlpatterns = [
|
||||
url(r'^(?P<supplier_id>[0-9]+)/$', views.supplierDetail, name='detail'),
|
||||
|
||||
url(r'^$', views.index, name='index')
|
||||
]
|
||||
]
|
||||
|
@ -3,11 +3,13 @@ from django.http import HttpResponse
|
||||
|
||||
from .models import Supplier
|
||||
|
||||
|
||||
def index(request):
|
||||
return HttpResponse("This is the suppliers page")
|
||||
|
||||
|
||||
def supplierDetail(request, supplier_id):
|
||||
supplier = get_object_or_404(Supplier, pk=supplier_id)
|
||||
|
||||
return render(request, 'supplier/detail.html',
|
||||
{'supplier': supplier})
|
||||
{'supplier': supplier})
|
||||
|
@ -2,7 +2,8 @@ from django.contrib import admin
|
||||
|
||||
from .models import UniquePart
|
||||
|
||||
|
||||
class UniquePartAdmin(admin.ModelAdmin):
|
||||
list_display = ('part', 'revision', 'serial', 'creation_date')
|
||||
|
||||
admin.site.register(UniquePart, UniquePartAdmin)
|
||||
admin.site.register(UniquePart, UniquePartAdmin)
|
||||
|
@ -37,14 +37,14 @@ class UniquePart(models.Model):
|
||||
PART_DESTROYED = 50
|
||||
|
||||
status = models.IntegerField(default=PART_IN_PROGRESS,
|
||||
choices=[
|
||||
(PART_IN_PROGRESS, "In progress"),
|
||||
(PART_IN_STOCK, "In stock"),
|
||||
(PART_SHIPPED, "Shipped"),
|
||||
(PART_RETURNED, "Returned"),
|
||||
(PART_DAMAGED, "Damaged"),
|
||||
(PART_DESTROYED, "Destroyed"),
|
||||
])
|
||||
choices=[
|
||||
(PART_IN_PROGRESS, "In progress"),
|
||||
(PART_IN_STOCK, "In stock"),
|
||||
(PART_SHIPPED, "Shipped"),
|
||||
(PART_RETURNED, "Returned"),
|
||||
(PART_DAMAGED, "Damaged"),
|
||||
(PART_DESTROYED, "Destroyed"),
|
||||
])
|
||||
|
||||
def __str__(self):
|
||||
return self.part.name
|
||||
@ -59,4 +59,4 @@ class PartTrackingInfo(models.Model):
|
||||
part = models.ForeignKey(UniquePart, on_delete=models.CASCADE)
|
||||
date = models.DateField(auto_now_add=True,
|
||||
editable=False)
|
||||
notes = models.CharField(max_length=500)
|
||||
notes = models.CharField(max_length=500)
|
||||
|
@ -4,4 +4,4 @@ from . import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', views.index, name='index')
|
||||
]
|
||||
]
|
||||
|
@ -1,5 +1,6 @@
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from django.http import HttpResponse
|
||||
|
||||
|
||||
def index(request):
|
||||
return HttpResponse("This is the Tracking page")
|
||||
return HttpResponse("This is the Tracking page")
|
||||
|
Loading…
Reference in New Issue
Block a user