mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
Added User API and serializer
This commit is contained in:
parent
92cbd43f0f
commit
4777b02080
@ -8,9 +8,12 @@ from stock.urls import stock_urls, stock_loc_urls, stock_track_urls
|
|||||||
from project.urls import prj_urls, prj_part_urls, prj_cat_urls, prj_run_urls
|
from project.urls import prj_urls, prj_part_urls, prj_cat_urls, prj_run_urls
|
||||||
from supplier.urls import cust_urls, manu_urls, supplier_part_urls, price_break_urls, supplier_urls
|
from supplier.urls import cust_urls, manu_urls, supplier_part_urls, price_break_urls, supplier_urls
|
||||||
from track.urls import unique_urls, part_track_urls
|
from track.urls import unique_urls, part_track_urls
|
||||||
|
from users.urls import user_urls
|
||||||
|
|
||||||
admin.site.site_header = "InvenTree Admin"
|
admin.site.site_header = "InvenTree Admin"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
apipatterns = [
|
apipatterns = [
|
||||||
|
|
||||||
# Stock URLs
|
# Stock URLs
|
||||||
@ -40,6 +43,9 @@ apipatterns = [
|
|||||||
url(r'^project-category/', include(prj_cat_urls)),
|
url(r'^project-category/', include(prj_cat_urls)),
|
||||||
url(r'^project-part/', include(prj_part_urls)),
|
url(r'^project-part/', include(prj_part_urls)),
|
||||||
url(r'^project-run/', include(prj_run_urls)),
|
url(r'^project-run/', include(prj_run_urls)),
|
||||||
|
|
||||||
|
# User URLs
|
||||||
|
url(r'^user/', include(user_urls)),
|
||||||
]
|
]
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
@ -2,6 +2,7 @@ from __future__ import unicode_literals
|
|||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.core.validators import MinValueValidator
|
from django.core.validators import MinValueValidator
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
from supplier.models import SupplierPart
|
from supplier.models import SupplierPart
|
||||||
from part.models import Part
|
from part.models import Part
|
||||||
@ -29,6 +30,7 @@ class StockItem(models.Model):
|
|||||||
|
|
||||||
# last time the stock was checked / counted
|
# last time the stock was checked / counted
|
||||||
stocktake_date = models.DateField(blank=True, null=True)
|
stocktake_date = models.DateField(blank=True, null=True)
|
||||||
|
stocktake_user = models.ForeignKey(User, on_delete=models.SET_NULL, blank=True, null=True)
|
||||||
|
|
||||||
review_needed = models.BooleanField(default=False)
|
review_needed = models.BooleanField(default=False)
|
||||||
|
|
||||||
@ -63,7 +65,7 @@ class StockItem(models.Model):
|
|||||||
|
|
||||||
infinite = models.BooleanField(default=False)
|
infinite = models.BooleanField(default=False)
|
||||||
|
|
||||||
def stocktake(self, count):
|
def stocktake(self, count, user):
|
||||||
""" Perform item stocktake.
|
""" Perform item stocktake.
|
||||||
When the quantity of an item is counted,
|
When the quantity of an item is counted,
|
||||||
record the date of stocktake
|
record the date of stocktake
|
||||||
@ -76,6 +78,7 @@ class StockItem(models.Model):
|
|||||||
|
|
||||||
self.quantity = count
|
self.quantity = count
|
||||||
self.stocktake_date = datetime.now().date()
|
self.stocktake_date = datetime.now().date()
|
||||||
|
self.stocktake_user = user
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
def add_stock(self, amount):
|
def add_stock(self, amount):
|
||||||
|
@ -18,6 +18,7 @@ class StockItemSerializer(serializers.HyperlinkedModelSerializer):
|
|||||||
'notes',
|
'notes',
|
||||||
'updated',
|
'updated',
|
||||||
'stocktake_date',
|
'stocktake_date',
|
||||||
|
'stocktake_user',
|
||||||
'review_needed',
|
'review_needed',
|
||||||
'expected_arrival')
|
'expected_arrival')
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ class StockStocktakeEndpoint(generics.UpdateAPIView):
|
|||||||
|
|
||||||
def update(self, request, *args, **kwargs):
|
def update(self, request, *args, **kwargs):
|
||||||
object = self.get_object()
|
object = self.get_object()
|
||||||
object.stocktake(request.data['quantity'])
|
object.stocktake(request.data['quantity'], request.user)
|
||||||
|
|
||||||
serializer = self.get_serializer(object)
|
serializer = self.get_serializer(object)
|
||||||
|
|
||||||
|
0
InvenTree/users/__init__.py
Normal file
0
InvenTree/users/__init__.py
Normal file
6
InvenTree/users/admin.py
Normal file
6
InvenTree/users/admin.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
8
InvenTree/users/apps.py
Normal file
8
InvenTree/users/apps.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class UsersConfig(AppConfig):
|
||||||
|
name = 'users'
|
6
InvenTree/users/models.py
Normal file
6
InvenTree/users/models.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
15
InvenTree/users/serializers.py
Normal file
15
InvenTree/users/serializers.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
from rest_framework import serializers
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
|
|
||||||
|
class UserSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
""" Serializer for a User
|
||||||
|
"""
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = User
|
||||||
|
fields = ('username',
|
||||||
|
'first_name',
|
||||||
|
'last_name',
|
||||||
|
'email',)
|
||||||
|
|
6
InvenTree/users/tests.py
Normal file
6
InvenTree/users/tests.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
9
InvenTree/users/urls.py
Normal file
9
InvenTree/users/urls.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from django.conf.urls import url, include
|
||||||
|
|
||||||
|
from . import views
|
||||||
|
|
||||||
|
user_urls = [
|
||||||
|
url(r'^(?P<pk>[0-9]+)/?$', views.UserDetail.as_view(), name='user-detail'),
|
||||||
|
|
||||||
|
url(r'^$', views.UserList.as_view()),
|
||||||
|
]
|
17
InvenTree/users/views.py
Normal file
17
InvenTree/users/views.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
from rest_framework import generics, permissions, response
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
from .serializers import UserSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class UserDetail(generics.RetrieveAPIView):
|
||||||
|
|
||||||
|
queryset = User.objects.all()
|
||||||
|
serializer_class = UserSerializer
|
||||||
|
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||||
|
|
||||||
|
|
||||||
|
class UserList(generics.ListAPIView):
|
||||||
|
|
||||||
|
queryset = User.objects.all()
|
||||||
|
serializer_class = UserSerializer
|
||||||
|
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
Loading…
x
Reference in New Issue
Block a user