fix ranvher invetory entry bug for existence of rancher - set pagination message
This commit is contained in:
@@ -58,18 +58,25 @@ class InventoryEntryViewSet(viewsets.ModelViewSet, DynamicSearchMixin, POSDevice
|
||||
)
|
||||
@transaction.atomic
|
||||
def rancher_inventory_entries(self, request):
|
||||
""" """
|
||||
""" list of inventory entries (quotas) for rancher """
|
||||
|
||||
organization = self.get_device_organization()
|
||||
device = self.get_pos_device()
|
||||
rancher = Rancher.objects.filter(national_code=request.GET['national_code']).first()
|
||||
rancher = Rancher.objects.filter(national_code=request.GET['national_code'])
|
||||
entries = self.queryset.filter(organization=organization)
|
||||
|
||||
available_entries = [entry for entry in entries if can_buy_from_inventory(rancher, entry)]
|
||||
# check quota inventory entries for rancher
|
||||
available_entries = [
|
||||
entry for entry in entries if (can_buy_from_inventory(rancher.first(), entry) & rancher.exists())
|
||||
]
|
||||
|
||||
# paginate & response
|
||||
page = self.paginate_queryset(available_entries)
|
||||
if page is not None:
|
||||
serializer = self.get_serializer(page, many=True, context={'rancher': rancher, 'device': device})
|
||||
serializer = self.get_serializer(page, many=True, context={'rancher': rancher.first(), 'device': device})
|
||||
# set custom message for paginator
|
||||
if not available_entries:
|
||||
self.paginator.set_message("دامدار با کد ملی مد نظر یافت نشد") # noqa
|
||||
return self.get_paginated_response(serializer.data)
|
||||
|
||||
|
||||
|
||||
@@ -61,9 +61,10 @@ class InventoryEntrySerializer(serializers.ModelSerializer):
|
||||
}
|
||||
|
||||
representation['pricing'] = {
|
||||
'brokers_info': quota_brokers_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']),
|
||||
'base_price_factory': instance.distribution.quota.base_price_factory,
|
||||
'base_price_cooperative': instance.distribution.quota.base_price_cooperative,
|
||||
}
|
||||
|
||||
if 'rancher' in self.context.keys():
|
||||
|
||||
Reference in New Issue
Block a user