add rancher statistics to inventory entries list - fix bug of login for empty string device identity

This commit is contained in:
2025-08-25 14:43:56 +03:30
parent 7722ddfc84
commit 2725bc5077
6 changed files with 27 additions and 5 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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