mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
commit
a2a2c9821e
@ -1,8 +1,21 @@
|
|||||||
from django.conf.urls import url, include
|
from django.conf.urls import url, include
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
|
from rest_framework import status
|
||||||
|
from rest_framework.response import Response
|
||||||
|
from rest_framework.decorators import api_view
|
||||||
|
|
||||||
admin.site.site_header = "InvenTree Admin"
|
admin.site.site_header = "InvenTree Admin"
|
||||||
|
|
||||||
|
|
||||||
|
@api_view()
|
||||||
|
def Inventree404(self):
|
||||||
|
""" Supplied URL is invalid
|
||||||
|
"""
|
||||||
|
content = {'detail': 'Malformed API URL'}
|
||||||
|
return Response(content, status=status.HTTP_404_NOT_FOUND)
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^stock/', include('stock.urls')),
|
url(r'^stock/', include('stock.urls')),
|
||||||
url(r'^part/', include('part.urls')),
|
url(r'^part/', include('part.urls')),
|
||||||
@ -10,5 +23,8 @@ urlpatterns = [
|
|||||||
url(r'^track/', include('track.urls')),
|
url(r'^track/', include('track.urls')),
|
||||||
url(r'^project/', include('project.urls')),
|
url(r'^project/', include('project.urls')),
|
||||||
url(r'^admin/', admin.site.urls),
|
url(r'^admin/', admin.site.urls),
|
||||||
url(r'^auth/', include('rest_framework.urls', namespace='rest_framework'))
|
url(r'^auth/', include('rest_framework.urls', namespace='rest_framework')),
|
||||||
|
|
||||||
|
# Any other URL
|
||||||
|
url(r'', Inventree404)
|
||||||
]
|
]
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
{# Construct the category path #}
|
|
||||||
<a href="../">Category</a>/
|
|
||||||
{% for path_item in category.parentpath %}
|
|
||||||
<a href="../{{ path_item.pk }}">{{ path_item.name }}</a>/
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
{{ category.name }}
|
|
||||||
|
|
||||||
<br><br>Children:<br>
|
|
||||||
{% for child in children %}
|
|
||||||
<a href="/part/category/{{ child.pk }}">{{ child.name }}</a><br>
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
<br>
|
|
||||||
<br>
|
|
||||||
Parts:
|
|
||||||
<br>
|
|
||||||
|
|
||||||
{% for part in category.part_set.all %}
|
|
||||||
<a href="/part/{{ part.pk }}">{{ part.name }}</a><br>
|
|
||||||
{% endfor %}
|
|
@ -1,8 +0,0 @@
|
|||||||
Top Level Part Categories:
|
|
||||||
|
|
||||||
{% for category in categories %}
|
|
||||||
|
|
||||||
<br>
|
|
||||||
<a href="./{{ category.pk }}">{{ category.name }}<a/>
|
|
||||||
|
|
||||||
{% endfor %}
|
|
@ -1,4 +0,0 @@
|
|||||||
{{part}}
|
|
||||||
|
|
||||||
<br>
|
|
||||||
Category: <a href="/part/category/{{ part.category.pk}}">{{ part.category }}</a>
|
|
@ -61,10 +61,7 @@ class PartFilter(django_filters.rest_framework.FilterSet):
|
|||||||
|
|
||||||
|
|
||||||
class PartList(generics.ListCreateAPIView):
|
class PartList(generics.ListCreateAPIView):
|
||||||
""" Display a list of parts, with optional filters
|
""" List of parts, with optional filters
|
||||||
Filters are specified in the url, e.g.
|
|
||||||
/part/?category=127
|
|
||||||
/part/?min_stock=100
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
Warehouses:
|
|
||||||
|
|
||||||
{% for warehouse in warehouse %}
|
|
||||||
|
|
||||||
<br>
|
|
||||||
<a href="./{{ warehouse.pk }}">{{ warehouse.name }}</a>
|
|
||||||
|
|
||||||
{% endfor %}
|
|
42
InvenTree/supplier/serializers.py
Normal file
42
InvenTree/supplier/serializers.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
from .models import Supplier, SupplierPart, SupplierPriceBreak
|
||||||
|
|
||||||
|
|
||||||
|
class SupplierSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Supplier
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
|
|
||||||
|
class SupplierPartSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
price_breaks = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = SupplierPart
|
||||||
|
fields = ['pk',
|
||||||
|
'part',
|
||||||
|
'supplier',
|
||||||
|
'SKU',
|
||||||
|
'manufacturer',
|
||||||
|
'MPN',
|
||||||
|
'URL',
|
||||||
|
'description',
|
||||||
|
'single_price',
|
||||||
|
'packaging',
|
||||||
|
'multiple',
|
||||||
|
'minimum',
|
||||||
|
'price_breaks',
|
||||||
|
'lead_time']
|
||||||
|
|
||||||
|
|
||||||
|
class SupplierPriceBreakSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = SupplierPriceBreak
|
||||||
|
fields = ['pk',
|
||||||
|
'part',
|
||||||
|
'quantity',
|
||||||
|
'cost']
|
@ -1 +0,0 @@
|
|||||||
{{ supplier }}
|
|
@ -1,11 +1,30 @@
|
|||||||
from django.conf.urls import url
|
from django.conf.urls import url, include
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
partpatterns = [
|
||||||
|
url(r'^(?P<pk>[0-9]+)/?$', views.SupplierPartDetail.as_view()),
|
||||||
# Display details of a supplier
|
|
||||||
url(r'^(?P<supplier_id>[0-9]+)/$', views.supplierDetail, name='detail'),
|
url(r'^\?*[^/]*/?$', views.SupplierPartList.as_view())
|
||||||
|
]
|
||||||
url(r'^$', views.index, name='index')
|
|
||||||
|
pricepatterns = [
|
||||||
|
url(r'^(?P<pk>[0-9]+)/?$', views.SupplierPriceBreakDetail.as_view()),
|
||||||
|
|
||||||
|
url(r'^\?*[^/]*/?$', views.SupplierPriceBreakList.as_view())
|
||||||
|
]
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
|
||||||
|
# Supplier part information
|
||||||
|
url(r'part/?', include(partpatterns)),
|
||||||
|
|
||||||
|
# Supplier price information
|
||||||
|
url(r'price/?', include(pricepatterns)),
|
||||||
|
|
||||||
|
# Display details of a supplier
|
||||||
|
url(r'^(?P<pk>[0-9]+)/?$', views.SupplierDetail.as_view()),
|
||||||
|
|
||||||
|
# List suppliers
|
||||||
|
url(r'^\?*[^/]*/?$', views.SupplierList.as_view())
|
||||||
]
|
]
|
||||||
|
@ -1,15 +1,74 @@
|
|||||||
from django.shortcuts import render, get_object_or_404
|
from rest_framework import generics, permissions
|
||||||
from django.http import HttpResponse
|
|
||||||
|
|
||||||
from .models import Supplier
|
from .models import Supplier, SupplierPart, SupplierPriceBreak
|
||||||
|
from .serializers import SupplierSerializer
|
||||||
|
from .serializers import SupplierPartSerializer
|
||||||
|
from .serializers import SupplierPriceBreakSerializer
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
class SupplierDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||||
return HttpResponse("This is the suppliers page")
|
|
||||||
|
queryset = Supplier.objects.all()
|
||||||
|
serializer_class = SupplierSerializer
|
||||||
|
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||||
|
|
||||||
|
|
||||||
def supplierDetail(request, supplier_id):
|
class SupplierList(generics.ListCreateAPIView):
|
||||||
supplier = get_object_or_404(Supplier, pk=supplier_id)
|
|
||||||
|
queryset = Supplier.objects.all()
|
||||||
return render(request, 'supplier/detail.html',
|
serializer_class = SupplierSerializer
|
||||||
{'supplier': supplier})
|
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||||
|
|
||||||
|
|
||||||
|
class SupplierPartDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||||
|
|
||||||
|
queryset = SupplierPart.objects.all()
|
||||||
|
serializer_class = SupplierPartSerializer
|
||||||
|
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||||
|
|
||||||
|
|
||||||
|
class SupplierPartList(generics.ListCreateAPIView):
|
||||||
|
|
||||||
|
serializer_class = SupplierPartSerializer
|
||||||
|
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
parts = SupplierPart.objects.all()
|
||||||
|
params = self.request.query_params
|
||||||
|
|
||||||
|
supplier_id = params.get('supplier', None)
|
||||||
|
if supplier_id:
|
||||||
|
parts = parts.filter(supplier=supplier_id)
|
||||||
|
|
||||||
|
part_id = params.get('part', None)
|
||||||
|
if part_id:
|
||||||
|
parts = parts.filter(part=part_id)
|
||||||
|
|
||||||
|
manu_id = params.get('manufacturer', None)
|
||||||
|
if manu_id:
|
||||||
|
parts = parts.filter(manufacturer=manu_id)
|
||||||
|
|
||||||
|
return parts
|
||||||
|
|
||||||
|
|
||||||
|
class SupplierPriceBreakDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||||
|
|
||||||
|
queryset = SupplierPriceBreak.objects.all()
|
||||||
|
serializer_class = SupplierPriceBreakSerializer
|
||||||
|
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||||
|
|
||||||
|
|
||||||
|
class SupplierPriceBreakList(generics.ListCreateAPIView):
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
prices = SupplierPriceBreak.objects.all()
|
||||||
|
params = self.request.query_params
|
||||||
|
|
||||||
|
part_id = params.get('part', None)
|
||||||
|
if part_id:
|
||||||
|
prices = prices.filter(part=part_id)
|
||||||
|
|
||||||
|
return prices
|
||||||
|
|
||||||
|
serializer_class = SupplierPriceBreakSerializer
|
||||||
|
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||||
|
Loading…
Reference in New Issue
Block a user