edit tag distribute from distribution

This commit is contained in:
2026-02-03 08:46:38 +03:30
parent c5b87e8591
commit fb58e6c3aa
3 changed files with 11 additions and 6 deletions

View File

@@ -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(

View File

@@ -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
)

View File

@@ -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):
"""