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:
|
||||
# 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
|
||||
"""
|
||||
@ -26,6 +27,7 @@ class Company(models.Model):
|
||||
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)
|
||||
@ -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)
|
||||
|
@ -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)
|
@ -6,6 +6,7 @@ from django.core.exceptions import ObjectDoesNotExist
|
||||
|
||||
from InvenTree.models import 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
|
@ -2,6 +2,7 @@ from rest_framework import serializers
|
||||
|
||||
from .models import Part, PartCategory
|
||||
|
||||
|
||||
class PartSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Part
|
||||
@ -11,6 +12,7 @@ class PartSerializer(serializers.ModelSerializer):
|
||||
'category',
|
||||
'stock')
|
||||
|
||||
|
||||
class PartCategorySerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = PartCategory
|
||||
|
@ -6,24 +6,29 @@ 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()
|
||||
|
@ -2,12 +2,15 @@ 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')
|
||||
|
||||
|
@ -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,6 +35,7 @@ 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.
|
||||
@ -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)
|
||||
|
@ -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")
|
@ -2,9 +2,11 @@ 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')
|
||||
|
||||
|
@ -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,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,8 +2,9 @@ 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)
|
||||
|
@ -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):
|
||||
|
@ -3,9 +3,11 @@ 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)
|
||||
|
||||
|
@ -2,6 +2,7 @@ from django.contrib import admin
|
||||
|
||||
from .models import UniquePart
|
||||
|
||||
|
||||
class UniquePartAdmin(admin.ModelAdmin):
|
||||
list_display = ('part', 'revision', 'serial', 'creation_date')
|
||||
|
||||
|
@ -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
|
||||
|
@ -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")
|
Loading…
x
Reference in New Issue
Block a user