fix --> bug of calculated distribution of tag batch
This commit is contained in:
@@ -25,7 +25,7 @@ class TagBatchService:
|
|||||||
|
|
||||||
base_data = qs.aggregate(
|
base_data = qs.aggregate(
|
||||||
batch_count=Count('id', distinct=True),
|
batch_count=Count('id', distinct=True),
|
||||||
total_distributed_tags=Coalesce(Sum('total_distributed_tags'), 0),
|
total_distributed_tags=Coalesce(Sum('total_distributed_tags', distinct=True), 0),
|
||||||
total_remaining_tags=Coalesce(Sum('total_remaining_tags'), 0),
|
total_remaining_tags=Coalesce(Sum('total_remaining_tags'), 0),
|
||||||
tag_count_created_by_batch=Count('tag'),
|
tag_count_created_by_batch=Count('tag'),
|
||||||
has_distributed_batches_number=Count(
|
has_distributed_batches_number=Count(
|
||||||
|
|||||||
@@ -14,7 +14,9 @@ def calculate_tag_batch_details(sender, instance: TagDistribution, **kwargs):
|
|||||||
|
|
||||||
distributed_tags = distributions.aggregate(count=Count('tag'))['count']
|
distributed_tags = distributions.aggregate(count=Count('tag'))['count']
|
||||||
|
|
||||||
instance.batch.total_distributed_tags = distributed_tags
|
instance.batch.total_distributed_tags = distributed_tags \
|
||||||
|
if not instance.batch.total_distributed_tags != 0 \
|
||||||
|
else instance.total_tag_count
|
||||||
instance.batch.total_remaining_tags = int(instance.batch.request_number) - distributed_tags
|
instance.batch.total_remaining_tags = int(instance.batch.request_number) - distributed_tags
|
||||||
instance.batch.save(update_fields=['total_distributed_tags', 'total_remaining_tags'])
|
instance.batch.save(update_fields=['total_distributed_tags', 'total_remaining_tags'])
|
||||||
|
|
||||||
|
|||||||
@@ -205,6 +205,8 @@ class TagDistributionBatchSerializer(serializers.ModelSerializer):
|
|||||||
'batch_identity': dist.batch.batch_identity if dist.batch else None,
|
'batch_identity': dist.batch.batch_identity if dist.batch else None,
|
||||||
'species_code': dist.species_code,
|
'species_code': dist.species_code,
|
||||||
'distributed_number': dist.distributed_number,
|
'distributed_number': dist.distributed_number,
|
||||||
|
'total_tag_count': dist.total_tag_count,
|
||||||
|
'remaining_number': dist.remaining_number,
|
||||||
'serial_from': dist.batch.serial_from if dist.batch else None,
|
'serial_from': dist.batch.serial_from if dist.batch else None,
|
||||||
'serial_to': dist.batch.serial_to if dist.batch else None,
|
'serial_to': dist.batch.serial_to if dist.batch else None,
|
||||||
} for dist in instance.distributions.all()]
|
} for dist in instance.distributions.all()]
|
||||||
|
|||||||
Reference in New Issue
Block a user