More model updates

This commit is contained in:
Oliver Walters 2017-03-28 22:45:43 +11:00
parent deda73a50f
commit 7eb00e8d47
5 changed files with 58 additions and 24 deletions

View File

@ -4,12 +4,37 @@ from django.db import models
from django.core.exceptions import ObjectDoesNotExist
from django.contrib.contenttypes.models import ContentType
class ExternalEntity(models.Model):
""" Abstract model representing an external person / supplier / etc
"""
class Meta:
abstract = True
name = models.CharField(max_length=100)
URL = models.URLField(blank=True)
address = models.CharField(max_length=200,
blank=True)
phone = models.CharField(max_length=50,
blank=True)
email = models.EmailField(blank=True)
contact = models.CharField(max_length=100,
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).
- Each Category can have zero-or-more child Categor(y/ies)
"""
class Meta:
abstract = True
name = models.CharField(max_length=100)
description = models.CharField(max_length=250)
parent = models.ForeignKey('self',
@ -123,8 +148,4 @@ class InvenTreeTree(models.Model):
This is recursive - Make it not so.
"""
return self.path
class Meta:
abstract = True
return self.path

View File

@ -18,14 +18,14 @@ class StockItem(models.Model):
# Stock status types
ITEM_IN_PROGRESS = 0
ITEM_DAMAGED = 10
ITEM_RETURNED = 20
ITEM_ATTENTION = 20
ITEM_COMPLETE = 50
status = models.IntegerField(default=ITEM_IN_PROGRESS,
choices=[
(ITEM_IN_PROGRESS, "In progress"),
(ITEM_DAMAGED, "Damaged"),
(ITEM_RETURNED, "Returned"),
(ITEM_ATTENTION, "Requires attention"),
(ITEM_COMPLETE, "Complete")
])

View File

@ -1,9 +1,10 @@
from django.contrib import admin
from .models import Supplier, SupplierPart
from .models import Supplier, SupplierPart, Customer
class SupplierAdmin(admin.ModelAdmin):
class CompanyAdmin(admin.ModelAdmin):
list_display=('name','URL','contact')
admin.site.register(Supplier, SupplierAdmin)
admin.site.register(Customer, CompanyAdmin)
admin.site.register(Supplier, CompanyAdmin)
admin.site.register(SupplierPart)

View File

@ -2,26 +2,17 @@ from __future__ import unicode_literals
from django.db import models
from InvenTree.models import ExternalEntity
from part.models import Part
class Supplier(models.Model):
class Supplier(ExternalEntity):
""" Represents a manufacturer or supplier
"""
name = models.CharField(max_length=100)
URL = models.URLField(blank=True)
address = models.CharField(max_length=200,
blank=True)
phone = models.CharField(max_length=50,
blank=True)
email = models.EmailField(blank=True)
contact = models.CharField(max_length=100,
blank=True)
notes = models.CharField(max_length=500,
blank=True)
pass
def __str__(self):
return self.name
class Customer(ExternalEntity):
pass
class SupplierPart(models.Model):
""" Represents a unique part as provided by a Supplier

View File

@ -3,6 +3,7 @@ from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.models import User
from supplier.models import Customer
from part.models import Part, PartRevision
class UniquePart(models.Model):
@ -23,6 +24,26 @@ class UniquePart(models.Model):
serial = models.IntegerField()
createdBy = models.ForeignKey(User)
customer = models.ForeignKey(Customer, blank=True, null=True)
# Part status types
PART_IN_PROGRESS = 0
PART_IN_STOCK = 10
PART_SHIPPED = 20
PART_RETURNED = 30
PART_DAMAGED = 40
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"),
])
def __str__(self):
return self.part.name