fix bug of rancher inventory entries - list of all cities
This commit is contained in:
@@ -18,12 +18,12 @@ class CityViewSet(ModelViewSet, SoftDeleteMixin): # noqa
|
|||||||
|
|
||||||
def list(self, request, *args, **kwargs):
|
def list(self, request, *args, **kwargs):
|
||||||
""" return list of cities by province """
|
""" return list of cities by province """
|
||||||
|
if 'province' in self.request.query_params.keys():
|
||||||
|
query = self.queryset.filter(province_id=int(request.GET['province']))
|
||||||
|
else:
|
||||||
|
query = self.queryset
|
||||||
|
|
||||||
serializer = self.serializer_class(
|
serializer = self.serializer_class(query, many=True)
|
||||||
self.queryset.filter(
|
|
||||||
province_id=int(request.GET['province'])
|
|
||||||
), many=True
|
|
||||||
)
|
|
||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
from apps.pos_device.models import Device
|
from apps.product.models import Quota, QuotaDistribution
|
||||||
from apps.product.models import Quota
|
from apps.pos_device.models import Device, StakeHolderShareAmount
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
|
|
||||||
def pos_organizations_sharing_information(device: Device, quota: Quota = None) -> typing.Any:
|
def pos_organizations_sharing_information(
|
||||||
|
device: Device,
|
||||||
|
quota: Quota = None,
|
||||||
|
distribution: QuotaDistribution = None
|
||||||
|
) -> typing.Any:
|
||||||
"""
|
"""
|
||||||
pos sharing organizations' information,
|
pos sharing organizations' information,
|
||||||
device have multiple organizations (sub_accounts) for sharing money
|
device have multiple organizations (sub_accounts) for sharing money
|
||||||
"""
|
"""
|
||||||
stake_holders = device.stake_holders.select_related('broker', 'broker_amount', 'organization')
|
stake_holders = device.stake_holders.select_related('broker', 'organization')
|
||||||
|
|
||||||
sharing_information_list = [{
|
sharing_information_list = [{
|
||||||
"organization_name": item.organization.name,
|
"organization_name": item.organization.name,
|
||||||
@@ -20,7 +24,9 @@ def pos_organizations_sharing_information(device: Device, quota: Quota = None) -
|
|||||||
"broker": item.broker.name if item.broker else None,
|
"broker": item.broker.name if item.broker else None,
|
||||||
"amount": quota.broker_values.filter(
|
"amount": quota.broker_values.filter(
|
||||||
broker=item.broker
|
broker=item.broker
|
||||||
).first().value if quota and item.broker else item.share_amount
|
).first().value if quota and item.broker else item.holders_share_amount.filter(
|
||||||
|
quota_distribution=distribution
|
||||||
|
).first().share_amount
|
||||||
} for item in stake_holders]
|
} for item in stake_holders]
|
||||||
|
|
||||||
return sharing_information_list
|
return sharing_information_list
|
||||||
|
|||||||
@@ -98,7 +98,11 @@ class QuotaDistributionSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
representation['pricing'] = { # noqa
|
representation['pricing'] = { # noqa
|
||||||
'pricing_attributes': quota_attribute_value(instance.quota),
|
'pricing_attributes': quota_attribute_value(instance.quota),
|
||||||
'sharing': pos_organizations_sharing_information(self.context['device'], instance.quota),
|
'sharing': pos_organizations_sharing_information(
|
||||||
|
self.context['device'],
|
||||||
|
instance.quota,
|
||||||
|
distribution=instance
|
||||||
|
),
|
||||||
'base_prices': [
|
'base_prices': [
|
||||||
{
|
{
|
||||||
"text": "قیمت درب کارخانه", # noqa
|
"text": "قیمت درب کارخانه", # noqa
|
||||||
|
|||||||
@@ -63,7 +63,11 @@ class InventoryEntrySerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
representation['pricing'] = {
|
representation['pricing'] = {
|
||||||
'pricing_attributes': quota_attribute_value(instance.distribution.quota),
|
'pricing_attributes': quota_attribute_value(instance.distribution.quota),
|
||||||
'sharing': pos_organizations_sharing_information(self.context['device']),
|
'sharing': pos_organizations_sharing_information(
|
||||||
|
self.context['device'],
|
||||||
|
instance.distribution.quota,
|
||||||
|
instance.distribution
|
||||||
|
),
|
||||||
'base_prices': [
|
'base_prices': [
|
||||||
{
|
{
|
||||||
"text": "قیمت درب کارخانه", # noqa
|
"text": "قیمت درب کارخانه", # noqa
|
||||||
|
|||||||
Reference in New Issue
Block a user