mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Added stock page
This commit is contained in:
parent
cc7593b44f
commit
e98c20048b
@ -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),
|
||||
]
|
||||
|
0
InvenTree/stock/__init__.py
Normal file
0
InvenTree/stock/__init__.py
Normal file
6
InvenTree/stock/admin.py
Normal file
6
InvenTree/stock/admin.py
Normal 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
7
InvenTree/stock/apps.py
Normal 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
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)
|
8
InvenTree/stock/templates/stock/index.html
Normal file
8
InvenTree/stock/templates/stock/index.html
Normal 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
3
InvenTree/stock/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
7
InvenTree/stock/urls.py
Normal file
7
InvenTree/stock/urls.py
Normal 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
12
InvenTree/stock/views.py
Normal 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
|
||||
})
|
Loading…
Reference in New Issue
Block a user