fix ranvher invetory entry bug for existence of rancher - set pagination message

This commit is contained in:
2025-09-03 14:23:04 +03:30
parent 8cc77dcd43
commit 9df2cf6200
6 changed files with 36 additions and 11 deletions

View File

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