import --> activate canceled tag distribution batches
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import random
|
||||
|
||||
from django.db import transaction
|
||||
from django.db.models import Sum
|
||||
from django.db.models import Sum, Q
|
||||
from django.db.models.aggregates import Count
|
||||
|
||||
from apps.authentication.models import Organization
|
||||
from apps.tag.exceptions import TagException
|
||||
@@ -154,10 +155,21 @@ class TagDistributionService:
|
||||
distribution batch main page dashboard detail
|
||||
"""
|
||||
|
||||
if org.type.key == 'ADM':
|
||||
distributions_batch = TagDistributionBatch.objects.prefetch_related('distributions')
|
||||
else:
|
||||
distributions_batch = TagDistributionBatch.objects.filter(
|
||||
Q(assigner_org=org) |
|
||||
Q(assigned_org=org)
|
||||
)
|
||||
|
||||
distributions_batch.aggregate(
|
||||
data = distributions_batch.aggregate(
|
||||
count=Count('id'),
|
||||
total_tag_count=Sum('total_tag_count'),
|
||||
total_recieved_distributions=Count('id', filter=Q(assigned_org=org)),
|
||||
total_sent_distributions=Count('id', filter=Q(assigner_org=org)),
|
||||
total_distributed_tag_count=Sum('total_distributed_tag_count'),
|
||||
remaining_tag_count=Sum('remaining_tag_count'),
|
||||
)
|
||||
|
||||
return data
|
||||
|
||||
@@ -532,3 +532,37 @@ class TagDistributionBatchViewSet(
|
||||
serializer = self.get_serializer(page, many=True)
|
||||
return self.get_paginated_response(serializer.data)
|
||||
return Response(self.serializer_class(queryset).data)
|
||||
|
||||
@action(
|
||||
methods=['post'],
|
||||
detail=True,
|
||||
url_name='reactivate_tag_dist_batch',
|
||||
url_path='reactivate_tag_dist_batch',
|
||||
name='reactivate_tag_dist_batch',
|
||||
)
|
||||
def reactivate_tag_dist_batch(self, request, pk=None):
|
||||
"""
|
||||
reactivate canceled distribution batch
|
||||
"""
|
||||
|
||||
dist_batch = self.get_object()
|
||||
dist_batch.is_closed = False
|
||||
dist_batch.save(update_fields=['is_closed'])
|
||||
|
||||
return Response(status=status.HTTP_200_OK)
|
||||
|
||||
@action(
|
||||
methods=['get'],
|
||||
detail=False,
|
||||
url_path='main_dashboard',
|
||||
url_name='main_dashboard',
|
||||
name='main_dashboard'
|
||||
)
|
||||
def main_dashboard(self, request):
|
||||
"""
|
||||
dashboard of main page
|
||||
"""
|
||||
org = get_organization_by_user(request.user)
|
||||
dashboard_data = self.distribution_batch_main_dashboard(org=org)
|
||||
|
||||
return Response(dashboard_data, status=status.HTTP_200_OK)
|
||||
|
||||
Reference in New Issue
Block a user