fix - signals bug for quota stat
This commit is contained in:
@@ -243,26 +243,6 @@ def update_quota_stats(instance: Quota):
|
|||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=Quota)
|
|
||||||
def organization_quota_stats(sender, quota: Quota, created: bool, **kwargs):
|
|
||||||
"""
|
|
||||||
set total received distributions for every organization
|
|
||||||
"""
|
|
||||||
org_quota_stat, created = OrganizationQuotaStats.objects.get_or_create(
|
|
||||||
quota=quota,
|
|
||||||
organization=quota.registerer_organization,
|
|
||||||
)
|
|
||||||
org_quota_stat.total_amount = quota.quota_weight
|
|
||||||
org_quota_stat.save(update_fields=['total_amount'])
|
|
||||||
|
|
||||||
# delete quota
|
|
||||||
if quota.trash:
|
|
||||||
org_quota_stat.soft_delete()
|
|
||||||
|
|
||||||
# prevent from maximum recursion loop
|
|
||||||
quota.stat_from_signal = True
|
|
||||||
|
|
||||||
|
|
||||||
@receiver([post_save, post_delete], sender=QuotaDistribution)
|
@receiver([post_save, post_delete], sender=QuotaDistribution)
|
||||||
@receiver([post_save, post_delete], sender=InventoryQuotaSaleTransaction)
|
@receiver([post_save, post_delete], sender=InventoryQuotaSaleTransaction)
|
||||||
def update_stats_on_change(sender, instance, **kwargs):
|
def update_stats_on_change(sender, instance, **kwargs):
|
||||||
@@ -275,14 +255,26 @@ def update_stats_on_change(sender, instance, **kwargs):
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
@receiver([post_save, post_delete], sender=Quota)
|
@receiver(post_save, sender=Quota)
|
||||||
def update_quota_stats_on_change(sender, instance, **kwargs):
|
def organization_quota_stats(sender, instance: Quota, created: bool, **kwargs):
|
||||||
if sender == Quota:
|
"""
|
||||||
# if _from_signal=True prevent from maximum recursion loop
|
set total received distributions for every organization
|
||||||
|
"""
|
||||||
if getattr(instance, 'stat_from_signal', False):
|
if getattr(instance, 'stat_from_signal', False):
|
||||||
return
|
return
|
||||||
|
org_quota_stat, created = OrganizationQuotaStats.objects.get_or_create(
|
||||||
|
quota=instance,
|
||||||
|
organization=instance.registerer_organization,
|
||||||
|
)
|
||||||
|
org_quota_stat.total_amount = instance.quota_weight
|
||||||
|
org_quota_stat.save(update_fields=['total_amount'])
|
||||||
|
|
||||||
organization_quota_stats(instance)
|
# delete quota
|
||||||
|
if instance.trash:
|
||||||
|
org_quota_stat.soft_delete()
|
||||||
|
|
||||||
|
# prevent from maximum recursion loop
|
||||||
|
instance.stat_from_signal = True
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=QuotaDistribution)
|
@receiver(post_save, sender=QuotaDistribution)
|
||||||
|
|||||||
Reference in New Issue
Block a user