PEP fixes

This commit is contained in:
Oliver Walters 2017-03-28 23:09:51 +11:00
parent f4ef9d938e
commit 09cb067627
2 changed files with 37 additions and 34 deletions

View File

@ -5,54 +5,57 @@ from django.db import models
from InvenTree.models import Company
from part.models import Part
class Supplier(Company):
""" Represents a manufacturer or supplier
"""
pass
class Customer(Company):
pass
class SupplierPart(models.Model):
""" Represents a unique part as provided by a Supplier
Each SupplierPart is identified by a MPN (Manufacturer Part Number)
Each SupplierPart is also linked to a Part object
- A Part may be available from multiple suppliers
"""
supplier = models.ForeignKey(Supplier,
on_delete=models.CASCADE)
part = models.ForeignKey(Part,
on_delete=models.CASCADE)
MPN = models.CharField(max_length=100)
URL = models.URLField(blank=True)
description = models.CharField(max_length=250,
blank=True)
def __str__(self):
return "{mpn} - {supplier}".format(
mpn = self.MPN,
supplier = self.supplier.name)
class SupplierPriceBreak(models.Model):
""" Represents a quantity price break for a SupplierPart
- Suppliers can offer discounts at larger quantities
- SupplierPart(s) may have zero-or-more associated SupplierPriceBreak(s)
"""
part = models.ForeignKey(SupplierPart,
on_delete=models.CASCADE)
quantity = models.IntegerField()
cost = models.DecimalField(max_digits=10, decimal_places=3)
currency = models.CharField(max_length=10,
blank=True)
def __str__(self):
return "{mpn} - {cost}{currency} @ {quan}".format(
mpn = part.MPN,
cost = self.cost,
currency = self.currency if self.currency else '',
quan = self.quantity)
mpn=part.MPN,
cost=self.cost,
currency=self.currency if self.currency else '',
quan=self.quantity)

View File

@ -6,27 +6,28 @@ from django.contrib.auth.models import User
from supplier.models import Customer
from part.models import Part, PartRevision
class UniquePart(models.Model):
""" A unique instance of a Part object.
Used for tracking parts based on serial numbers,
and tracking all events in the life of a part
"""
part = models.ForeignKey(Part, on_delete=models.CASCADE)
revision = models.ForeignKey(PartRevision,
on_delete=models.CASCADE,
blank=True,
null=True)
creation_date = models.DateField(auto_now_add=True,
editable=False)
editable=False)
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
@ -34,29 +35,28 @@ class UniquePart(models.Model):
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"),
])
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
class PartTrackingInfo(models.Model):
""" Single data-point in the life of a UniquePart
Each time something happens to the UniquePart,
a new PartTrackingInfo object should be created.
"""
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)