change my distributions to assigner & assigned by param
This commit is contained in:
@@ -81,16 +81,26 @@ class QuotaDistributionViewSet(viewsets.ModelViewSet):
|
||||
)
|
||||
def my_distributions(self, request):
|
||||
""" list of my distributions """
|
||||
query = self.request.query_params
|
||||
organization = get_organization_by_user(request.user)
|
||||
|
||||
# paginate queryset
|
||||
page = self.paginate_queryset(
|
||||
self.queryset.filter(
|
||||
Q(assigned_organization=organization)
|
||||
).order_by('-modify_date')
|
||||
)
|
||||
if page is not None:
|
||||
serializer = self.get_serializer(page, many=True)
|
||||
if query.get('param') == 'assigned':
|
||||
# paginate queryset
|
||||
page = self.paginate_queryset(
|
||||
self.queryset.filter(
|
||||
Q(assigned_organization=organization)
|
||||
).order_by('-modify_date')
|
||||
)
|
||||
elif query.get('param') == 'assigner':
|
||||
# paginate queryset
|
||||
page = self.paginate_queryset(
|
||||
self.queryset.filter(
|
||||
Q(assigner_organization=organization)
|
||||
).order_by('-modify_date')
|
||||
)
|
||||
|
||||
if page is not None: # noqa
|
||||
serializer = self.get_serializer(page, many=True) # noqa
|
||||
return self.get_paginated_response(serializer.data)
|
||||
|
||||
@action(
|
||||
|
||||
@@ -47,10 +47,13 @@ class InventoryEntrySerializer(serializers.ModelSerializer):
|
||||
return attrs
|
||||
|
||||
def to_representation(self, instance):
|
||||
""" custom output of inventory entry serializer """
|
||||
|
||||
representation = super().to_representation(instance)
|
||||
if instance.document:
|
||||
representation['document'] = instance.document
|
||||
if instance.distribution:
|
||||
# distribution data
|
||||
representation['distribution'] = {
|
||||
'distribution': instance.distribution.distribution_id,
|
||||
'sale_unit': instance.distribution.quota.sale_unit.unit,
|
||||
|
||||
Reference in New Issue
Block a user