2017-03-27 10:04:15 +00:00
|
|
|
from __future__ import unicode_literals
|
2017-03-29 12:19:53 +00:00
|
|
|
from django.utils.translation import ugettext as _
|
2017-03-27 10:04:15 +00:00
|
|
|
from django.db import models
|
2017-04-16 07:05:02 +00:00
|
|
|
from django.core.validators import MinValueValidator
|
2017-03-27 10:04:15 +00:00
|
|
|
|
2017-04-15 15:43:30 +00:00
|
|
|
from supplier.models import SupplierPart
|
2017-03-27 10:04:15 +00:00
|
|
|
from part.models import Part
|
2017-03-27 11:55:21 +00:00
|
|
|
from InvenTree.models import InvenTreeTree
|
2017-03-27 10:04:15 +00:00
|
|
|
|
2017-03-28 12:25:38 +00:00
|
|
|
|
2017-04-11 08:58:44 +00:00
|
|
|
class StockLocation(InvenTreeTree):
|
|
|
|
""" Organization tree for StockItem objects
|
|
|
|
"""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def items(self):
|
|
|
|
stock_list = self.stockitem_set.all()
|
|
|
|
return stock_list
|
2017-03-29 11:55:28 +00:00
|
|
|
|
2017-03-28 12:25:38 +00:00
|
|
|
|
2017-03-27 10:04:15 +00:00
|
|
|
class StockItem(models.Model):
|
2017-04-15 15:24:00 +00:00
|
|
|
part = models.ForeignKey(Part, on_delete=models.CASCADE, related_name='locations')
|
2017-04-15 15:43:30 +00:00
|
|
|
supplier_part = models.ForeignKey(SupplierPart, blank=True, null=True, on_delete=models.SET_NULL)
|
2017-04-11 08:58:44 +00:00
|
|
|
location = models.ForeignKey(StockLocation, on_delete=models.CASCADE)
|
2017-04-16 07:05:02 +00:00
|
|
|
quantity = models.PositiveIntegerField(validators=[MinValueValidator(0)])
|
2017-03-27 10:04:15 +00:00
|
|
|
updated = models.DateField(auto_now=True)
|
2017-03-29 11:55:28 +00:00
|
|
|
|
2017-03-29 12:36:06 +00:00
|
|
|
# last time the stock was checked / counted
|
|
|
|
last_checked = models.DateField(blank=True, null=True)
|
|
|
|
|
|
|
|
review_needed = models.BooleanField(default=False)
|
|
|
|
|
2017-03-28 11:27:46 +00:00
|
|
|
# Stock status types
|
2017-03-29 12:19:53 +00:00
|
|
|
ITEM_IN_STOCK = 10
|
|
|
|
ITEM_INCOMING = 15
|
|
|
|
ITEM_IN_PROGRESS = 20
|
|
|
|
ITEM_COMPLETE = 25
|
|
|
|
ITEM_ATTENTION = 50
|
|
|
|
ITEM_DAMAGED = 55
|
|
|
|
ITEM_DESTROYED = 60
|
|
|
|
|
|
|
|
ITEM_STATUS_CODES = {
|
|
|
|
ITEM_IN_STOCK: _("In stock"),
|
|
|
|
ITEM_INCOMING: _("Incoming"),
|
|
|
|
ITEM_IN_PROGRESS: _("In progress"),
|
|
|
|
ITEM_COMPLETE: _("Complete"),
|
|
|
|
ITEM_ATTENTION: _("Attention needed"),
|
|
|
|
ITEM_DAMAGED: _("Damaged"),
|
|
|
|
ITEM_DESTROYED: _("Destroyed")
|
|
|
|
}
|
2017-03-29 11:55:28 +00:00
|
|
|
|
|
|
|
status = models.PositiveIntegerField(
|
2017-03-29 12:19:53 +00:00
|
|
|
default=ITEM_IN_STOCK,
|
2017-04-16 07:05:02 +00:00
|
|
|
choices=ITEM_STATUS_CODES.items(),
|
|
|
|
validators=[MinValueValidator(0)])
|
2017-03-29 11:55:28 +00:00
|
|
|
|
2017-04-15 15:43:30 +00:00
|
|
|
notes = models.CharField(max_length=100, blank=True)
|
|
|
|
|
2017-03-29 11:55:28 +00:00
|
|
|
# If stock item is incoming, an (optional) ETA field
|
|
|
|
expected_arrival = models.DateField(null=True, blank=True)
|
|
|
|
|
2017-03-27 10:04:15 +00:00
|
|
|
def __str__(self):
|
|
|
|
return "{n} x {part} @ {loc}".format(
|
2017-03-28 12:25:38 +00:00
|
|
|
n=self.quantity,
|
|
|
|
part=self.part.name,
|
|
|
|
loc=self.location.name)
|
2017-04-15 15:43:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
class StockTracking(models.Model):
|
|
|
|
""" Tracks a single movement of stock
|
|
|
|
- Used to track stock being taken from a location
|
|
|
|
- Used to track stock being added to a location
|
|
|
|
- "Pending" flag shows that stock WILL be taken / added
|
|
|
|
"""
|
|
|
|
|
|
|
|
item = models.ForeignKey(StockItem, on_delete=models.CASCADE, related_name='tracking')
|
|
|
|
quantity = models.IntegerField()
|
|
|
|
when = models.DateTimeField(auto_now=True)
|