add rancher statistics to inventory entries list - fix bug of login for empty string device identity
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
from django.urls import path, include
|
||||
from rest_framework.routers import DefaultRouter
|
||||
from .viewsets import device
|
||||
|
||||
router = DefaultRouter()
|
||||
|
||||
urlpatterns = [
|
||||
path('v1/', include(router.urls))
|
||||
path('v1/', include(router.urls)),
|
||||
path('test_webserver', device.test_web_server, name='test_web_server'),
|
||||
]
|
||||
|
||||
@@ -4,12 +4,18 @@ from apps.pos_device import models as pos_models
|
||||
from rest_framework.permissions import AllowAny
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
from django.http.response import JsonResponse
|
||||
from common.generics import get_client_ip
|
||||
from rest_framework import viewsets
|
||||
from django.db import transaction
|
||||
from rest_framework import status
|
||||
|
||||
|
||||
def test_web_server(request):
|
||||
""" testing from pos device to check server status """
|
||||
return JsonResponse({"message": "OK"}, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class POSDeviceViewSet(viewsets.ModelViewSet, POSDeviceMixin):
|
||||
device_queryset = pos_models.Device.objects.all()
|
||||
session_queryset = pos_models.Sessions.objects.all()
|
||||
@@ -46,7 +52,7 @@ class POSDeviceViewSet(viewsets.ModelViewSet, POSDeviceMixin):
|
||||
organization = pos_models.Organization.objects.get(en_name=psp_name)
|
||||
|
||||
# check if device exists
|
||||
if 'device_identity' in request.data.keys():
|
||||
if 'device_identity' in request.data.keys() and request.data['device_identity'] != "":
|
||||
device = self.device_queryset.filter(device_identity=request.data['device_identity']).first()
|
||||
else:
|
||||
device = self.device_queryset.filter(serial=serial).first()
|
||||
|
||||
@@ -8,5 +8,6 @@ router.register(r'', device.POSDeviceViewSet, basename='auth')
|
||||
urlpatterns = [
|
||||
path('web/', include('apps.pos_device.web.api.v1.urls')),
|
||||
path('pos/', include('apps.pos_device.pos.api.v1.urls')),
|
||||
path('test_webserver', device.test_web_server, name='test_web_server'),
|
||||
path('auth/', include(router.urls)),
|
||||
]
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
from apps.warehouse.pos.api.v1 import serializers as warehouse_serializers
|
||||
from apps.warehouse.services.services import can_buy_from_inventory
|
||||
from apps.warehouse.services.services import (
|
||||
can_buy_from_inventory,
|
||||
rancher_quota_weight,
|
||||
get_rancher_statistics
|
||||
)
|
||||
from apps.pos_device.mixins.pos_device_mixin import POSDeviceMixin
|
||||
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
||||
from apps.warehouse import models as warehouse_models
|
||||
@@ -64,7 +68,7 @@ class InventoryEntryViewSet(viewsets.ModelViewSet, DynamicSearchMixin, POSDevice
|
||||
# paginate & response
|
||||
page = self.paginate_queryset(available_entries)
|
||||
if page is not None:
|
||||
serializer = self.get_serializer(page, many=True)
|
||||
serializer = self.get_serializer(page, many=True, context={'rancher': rancher})
|
||||
return self.get_paginated_response(serializer.data)
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from apps.herd.services.services import get_rancher_statistics, rancher_quota_weight
|
||||
from apps.pos_device.pos.api.v1.serializers.device import DeviceSerializer
|
||||
from apps.herd.pos.api.v1.serializers import RancherSerializer
|
||||
from apps.warehouse.exceptions import (
|
||||
@@ -47,6 +48,14 @@ class InventoryEntrySerializer(serializers.ModelSerializer):
|
||||
'id': instance.distribution.quota.product.id,
|
||||
}
|
||||
|
||||
# rancher herd & live stock statistics
|
||||
representation['rancher_statistics'] = get_rancher_statistics(self.context['rancher'])
|
||||
|
||||
# rancher live stock statistics by inventory entry
|
||||
representation['rancher_quota_weight_statistics'] = rancher_quota_weight(
|
||||
self.context['rancher'], instance
|
||||
)
|
||||
|
||||
return representation
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from apps.warehouse.models import InventoryEntry, InventoryQuotaSaleTransaction
|
||||
from apps.herd.services.services import rancher_quota_weight
|
||||
from apps.herd.services.services import rancher_quota_weight, get_rancher_statistics
|
||||
from django.db.models import Sum
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user