diff --git a/InvenTree/InvenTree/models.py b/InvenTree/InvenTree/models.py index ca602f400c..c6aec418ad 100644 --- a/InvenTree/InvenTree/models.py +++ b/InvenTree/InvenTree/models.py @@ -35,6 +35,7 @@ class InvenTreeTree(models.Model): class Meta: abstract = True + unique_together = ('name', 'parent') name = models.CharField(max_length=100) description = models.CharField(max_length=250, blank=True) diff --git a/InvenTree/stock/serializers.py b/InvenTree/stock/serializers.py index 6a02db0439..5c69329f82 100644 --- a/InvenTree/stock/serializers.py +++ b/InvenTree/stock/serializers.py @@ -3,13 +3,13 @@ from rest_framework import serializers from .models import StockItem, StockLocation -class StockItemSerializer(serializers.ModelSerializer): +class StockItemSerializer(serializers.HyperlinkedModelSerializer): """ Serializer for a StockItem """ class Meta: model = StockItem - fields = ('pk', + fields = ('url', 'part', 'location', 'quantity', @@ -20,13 +20,13 @@ class StockItemSerializer(serializers.ModelSerializer): 'expected_arrival') -class LocationSerializer(serializers.ModelSerializer): +class LocationSerializer(serializers.HyperlinkedModelSerializer): """ Detailed information about a stock location """ class Meta: model = StockLocation - fields = ('pk', + fields = ('url', 'name', 'description', 'parent', diff --git a/InvenTree/stock/urls.py b/InvenTree/stock/urls.py index ad1e2ac28a..bb026d2a08 100644 --- a/InvenTree/stock/urls.py +++ b/InvenTree/stock/urls.py @@ -3,11 +3,11 @@ from django.conf.urls import url, include from . import views locpatterns = [ - url(r'^(?P[0-9]+)/?$', views.LocationDetail.as_view(), name='location-detail'), + url(r'^(?P[0-9]+)/?$', views.LocationDetail.as_view(), name='stocklocation-detail'), - url(r'^\?.*/?$', views.LocationList.as_view(), name='location-list'), + url(r'^\?.*/?$', views.LocationList.as_view()), - url(r'^$', views.LocationList.as_view(), name='location-list') + url(r'^$', views.LocationList.as_view()) ] urlpatterns = [ @@ -15,9 +15,9 @@ urlpatterns = [ url(r'^location/', include(locpatterns)), # Detail for a single stock item - url(r'^(?P[0-9]+)/?$', views.StockDetail.as_view(), name='stock-detail'), + url(r'^(?P[0-9]+)/?$', views.StockDetail.as_view(), name='stockitem-detail'), # List all stock items, with optional filters - url(r'^\?.*/?$', views.StockList.as_view(), name='stock-list'), - url(r'^$', views.StockList.as_view(), name='stock-list'), + url(r'^\?.*/?$', views.StockList.as_view()), + url(r'^$', views.StockList.as_view()), ] diff --git a/InvenTree/supplier/models.py b/InvenTree/supplier/models.py index bd5d20dc86..894621ea97 100644 --- a/InvenTree/supplier/models.py +++ b/InvenTree/supplier/models.py @@ -31,6 +31,9 @@ class SupplierPart(models.Model): - A Part may be available from multiple suppliers """ + class Meta: + unique_together = ('part', 'supplier', 'SKU') + part = models.ForeignKey(Part, null=True, blank=True, on_delete=models.CASCADE) supplier = models.ForeignKey(Supplier, on_delete=models.CASCADE) SKU = models.CharField(max_length=100)