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):
|
def my_distributions(self, request):
|
||||||
""" list of my distributions """
|
""" list of my distributions """
|
||||||
|
query = self.request.query_params
|
||||||
organization = get_organization_by_user(request.user)
|
organization = get_organization_by_user(request.user)
|
||||||
|
|
||||||
# paginate queryset
|
if query.get('param') == 'assigned':
|
||||||
page = self.paginate_queryset(
|
# paginate queryset
|
||||||
self.queryset.filter(
|
page = self.paginate_queryset(
|
||||||
Q(assigned_organization=organization)
|
self.queryset.filter(
|
||||||
).order_by('-modify_date')
|
Q(assigned_organization=organization)
|
||||||
)
|
).order_by('-modify_date')
|
||||||
if page is not None:
|
)
|
||||||
serializer = self.get_serializer(page, many=True)
|
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)
|
return self.get_paginated_response(serializer.data)
|
||||||
|
|
||||||
@action(
|
@action(
|
||||||
|
|||||||
@@ -47,10 +47,13 @@ class InventoryEntrySerializer(serializers.ModelSerializer):
|
|||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
def to_representation(self, instance):
|
def to_representation(self, instance):
|
||||||
|
""" custom output of inventory entry serializer """
|
||||||
|
|
||||||
representation = super().to_representation(instance)
|
representation = super().to_representation(instance)
|
||||||
if instance.document:
|
if instance.document:
|
||||||
representation['document'] = instance.document
|
representation['document'] = instance.document
|
||||||
if instance.distribution:
|
if instance.distribution:
|
||||||
|
# distribution data
|
||||||
representation['distribution'] = {
|
representation['distribution'] = {
|
||||||
'distribution': instance.distribution.distribution_id,
|
'distribution': instance.distribution.distribution_id,
|
||||||
'sale_unit': instance.distribution.quota.sale_unit.unit,
|
'sale_unit': instance.distribution.quota.sale_unit.unit,
|
||||||
|
|||||||
Reference in New Issue
Block a user