fix ranvher invetory entry bug for existence of rancher - set pagination message
This commit is contained in:
@@ -1,7 +1,21 @@
|
||||
from rest_framework.pagination import PageNumberPagination
|
||||
from rest_framework.response import Response
|
||||
|
||||
|
||||
class CustomPageNumberPagination(PageNumberPagination):
|
||||
page_size = 20 # default
|
||||
page_size_query_param = 'page_size' # set from client
|
||||
max_page_size = 100 # maximum items to show
|
||||
message = None
|
||||
|
||||
def get_paginated_response(self, data):
|
||||
return Response({
|
||||
'message': self.message, # Custom message
|
||||
'count': self.page.paginator.count,
|
||||
'next': self.get_next_link(),
|
||||
'previous': self.get_previous_link(),
|
||||
'results': data
|
||||
})
|
||||
|
||||
def set_message(self, message):
|
||||
self.message = message
|
||||
|
||||
@@ -11,8 +11,11 @@ def pos_organizations_sharing_information(device: Device) -> typing.Any:
|
||||
|
||||
sharing_information_list = [{
|
||||
"organization_name": item.organization.name,
|
||||
"broker": item.broker.name,
|
||||
"amount": item.broker_amount.value
|
||||
# "credit_card": item.organization.bank_information.first().card or "",
|
||||
# "sheba": item.organization.bank_information.first().sheba,
|
||||
# "account": item.organization.bank_information.first().account,
|
||||
"broker": item.broker.name if item.broker else None,
|
||||
"amount": item.broker_amount.value if item.broker else None
|
||||
} for item in stake_holders]
|
||||
|
||||
return sharing_information_list
|
||||
|
||||
@@ -311,7 +311,7 @@ class StakeHoldersViewSet(viewsets.ModelViewSet, DynamicSearchMixin, SoftDeleteM
|
||||
raise OrganizationBankAccountException()
|
||||
|
||||
serializer = self.serializer_class(data=stakeholder)
|
||||
if serializer.is_valid():
|
||||
if serializer.is_valid(raise_exception=True):
|
||||
serializer.save()
|
||||
stakeholders_data.append(serializer.data)
|
||||
|
||||
|
||||
@@ -358,8 +358,8 @@ class Quota(BaseModel):
|
||||
related_name='quota_limits',
|
||||
blank=True
|
||||
)
|
||||
base_price_factory = models.DecimalField(max_digits=12, decimal_places=2)
|
||||
base_price_cooperative = models.DecimalField(max_digits=12, decimal_places=2)
|
||||
base_price_factory = models.PositiveBigIntegerField(default=0)
|
||||
base_price_cooperative = models.PositiveBigIntegerField(default=0)
|
||||
final_price = models.DecimalField(max_digits=12, decimal_places=2, null=True, blank=True)
|
||||
is_closed = models.BooleanField(default=False)
|
||||
closed_at = models.DateTimeField(null=True, blank=True)
|
||||
|
||||
@@ -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