mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 13:05:42 +00:00
Added stock page
This commit is contained in:
36
InvenTree/stock/models.py
Normal file
36
InvenTree/stock/models.py
Normal file
@ -0,0 +1,36 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models
|
||||
|
||||
from part.models import Part
|
||||
|
||||
class Warehouse(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
description = models.CharField(max_length=250, blank=True)
|
||||
parent = models.ForeignKey('self', on_delete=models.CASCADE, blank=True, null=True)
|
||||
|
||||
def __str__(self):
|
||||
if self.parent:
|
||||
return "/".join([p.name for p in self.path]) + "/" + self.name
|
||||
else:
|
||||
return self.name
|
||||
|
||||
# Return path of this category
|
||||
@property
|
||||
def path(self):
|
||||
if self.parent:
|
||||
return self.parent.path + [self.parent]
|
||||
else:
|
||||
return []
|
||||
|
||||
class StockItem(models.Model):
|
||||
part = models.ForeignKey(Part, on_delete=models.CASCADE)
|
||||
location = models.ForeignKey(Warehouse, on_delete=models.CASCADE)
|
||||
quantity = models.IntegerField()
|
||||
updated = models.DateField(auto_now=True)
|
||||
|
||||
def __str__(self):
|
||||
return "{n} x {part} @ {loc}".format(
|
||||
n = self.quantity,
|
||||
part = self.part.name,
|
||||
loc = self.location.name)
|
Reference in New Issue
Block a user