add pos devices sharing informations to list of rancher inventories
This commit is contained in:
18
apps/pos_device/services/services.py
Normal file
18
apps/pos_device/services/services.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from apps.pos_device.models import Device
|
||||
import typing
|
||||
|
||||
|
||||
def pos_organizations_sharing_information(device: Device) -> typing.Any:
|
||||
"""
|
||||
pos sharing organizations' information,
|
||||
device have multiple organizations (sub_accounts) for sharing money
|
||||
"""
|
||||
stake_holders = device.stake_holders.select_related('broker', 'broker_amount', 'organization')
|
||||
|
||||
sharing_information_list = [{
|
||||
"organization_name": item.organization.name,
|
||||
"broker": item.broker.name,
|
||||
"amount": item.broker_amount.value
|
||||
} for item in stake_holders]
|
||||
|
||||
return sharing_information_list
|
||||
@@ -60,6 +60,7 @@ class InventoryEntryViewSet(viewsets.ModelViewSet, DynamicSearchMixin, POSDevice
|
||||
def rancher_inventory_entries(self, request):
|
||||
""" """
|
||||
organization = self.get_device_organization()
|
||||
device = self.get_pos_device()
|
||||
rancher = Rancher.objects.filter(national_code=request.GET['national_code']).first()
|
||||
entries = self.queryset.filter(organization=organization)
|
||||
|
||||
@@ -68,7 +69,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, context={'rancher': rancher})
|
||||
serializer = self.get_serializer(page, many=True, context={'rancher': rancher, 'device': device})
|
||||
return self.get_paginated_response(serializer.data)
|
||||
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ from apps.product.services.services import (
|
||||
quota_brokers_value,
|
||||
quota_attribute_value
|
||||
)
|
||||
from apps.pos_device.services.services import pos_organizations_sharing_information
|
||||
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 (
|
||||
@@ -61,7 +62,8 @@ class InventoryEntrySerializer(serializers.ModelSerializer):
|
||||
|
||||
representation['pricing'] = {
|
||||
'brokers_info': quota_brokers_value(instance.distribution.quota),
|
||||
'pricing_attributes': quota_attribute_value(instance.distribution.quota)
|
||||
'pricing_attributes': quota_attribute_value(instance.distribution.quota),
|
||||
'sharing': pos_organizations_sharing_information(self.context['device'])
|
||||
}
|
||||
|
||||
if 'rancher' in self.context.keys():
|
||||
|
||||
Reference in New Issue
Block a user