diff --git a/apps/tag/services/tag_distribution_services.py b/apps/tag/services/tag_distribution_services.py index 067ae5b..ea5187d 100644 --- a/apps/tag/services/tag_distribution_services.py +++ b/apps/tag/services/tag_distribution_services.py @@ -245,7 +245,7 @@ class TagDistributionService: with transaction.atomic(): if tag_batch.assigner_org != org: - raise PermissionDenied("اجازه ویرایش این توزیع را ندارید") + raise PermissionDenied("اجازه ویرایش این توزیع را ندارید") # noqa for dist in tag_batch.distributions.all(): dist.tag.all().update( @@ -268,7 +268,9 @@ class TagDistributionService: parent_tag_distribution = TagDistribution.objects.get( id=dist_data['parent_tag_distribution'] ) - batch = TagBatch.objects.get(batch_identity=dist_data.get('batch_identity')) + batch = TagBatch.objects.get( + batch_identity=dist_data.get('batch_identity') + ) if dist_data.get('batch_identity') else None count = dist_data['count'] tags = Tag.objects.filter( diff --git a/apps/tag/signals/tag_distribution_signals.py b/apps/tag/signals/tag_distribution_signals.py index 6e8c185..61af9f6 100644 --- a/apps/tag/signals/tag_distribution_signals.py +++ b/apps/tag/signals/tag_distribution_signals.py @@ -1,3 +1,4 @@ +from django.db.models import Sum from django.db.models.signals import m2m_changed from django.db.models.signals import post_save from django.dispatch import receiver @@ -53,7 +54,9 @@ def calculate_tag_distribution_detail(sender, instance: TagDistributionBatch, ** tag_dist_batch = instance parent = tag_dist_batch.parent if parent: - parent.total_distributed_tag_count += tag_dist_batch.total_tag_count + parent.total_distributed_tag_count = parent.children.aggregate( + total=Sum('total_tag_count') + )['total'] parent.remaining_tag_count = ( parent.total_tag_count - parent.total_distributed_tag_count ) diff --git a/apps/tag/web/api/v1/api.py b/apps/tag/web/api/v1/api.py index 3dc238b..9496ad4 100644 --- a/apps/tag/web/api/v1/api.py +++ b/apps/tag/web/api/v1/api.py @@ -478,9 +478,9 @@ class TagDistributionViewSet( @action( methods=['put'], detail=True, - url_path='distribute_distribution', - url_name='distribute_distribution', - name='distribute_distribution', + url_path='edit_distribute_distribution', + url_name='edit_distribute_distribution', + name='edit_distribute_distribution', ) def update_distribute_from_distribution(self, request, pk=None): """