Added stock page

This commit is contained in:
Oliver Walters 2017-03-27 21:04:15 +11:00
parent cc7593b44f
commit e98c20048b
9 changed files with 80 additions and 0 deletions

View File

@ -17,6 +17,7 @@ from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^stock/', include('stock.urls')),
url(r'^part/', include('part.urls')),
url(r'^admin/', admin.site.urls),
]

View File

6
InvenTree/stock/admin.py Normal file
View File

@ -0,0 +1,6 @@
from django.contrib import admin
from .models import Warehouse, StockItem
admin.site.register(Warehouse)
admin.site.register(StockItem)

7
InvenTree/stock/apps.py Normal file
View File

@ -0,0 +1,7 @@
from __future__ import unicode_literals
from django.apps import AppConfig
class StockConfig(AppConfig):
name = 'stock'

36
InvenTree/stock/models.py Normal file
View 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)

View File

@ -0,0 +1,8 @@
Warehouses:
{% for warehouse in warehouse %}
<br>
<a href="./{{ warehouse.pk }}">{{ warehouse.name }}</a>
{% endfor %}

3
InvenTree/stock/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

7
InvenTree/stock/urls.py Normal file
View File

@ -0,0 +1,7 @@
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index')
]

12
InvenTree/stock/views.py Normal file
View File

@ -0,0 +1,12 @@
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse
from .models import Warehouse, StockItem
def index(request):
warehouses = Warehouse.objects.filter(parent = None)
return render(request, 'stock/index.html',
{'warehouses': warehouses
})