add - new changes on OrganizationQuotaStat & calculative signals on quota/distribution
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
from django.db.models import Sum
|
||||
from django.db.models.signals import post_save, post_delete
|
||||
from django.dispatch import receiver
|
||||
from apps.product.models import QuotaDistribution
|
||||
|
||||
from apps.product.models import QuotaDistribution, OrganizationQuotaStats
|
||||
from .models import InventoryEntry, InventoryQuotaSaleItem
|
||||
|
||||
|
||||
@@ -67,3 +68,17 @@ def update_distribution_warehouse_sold_and_balance(sender, instance: InventoryQu
|
||||
)
|
||||
else:
|
||||
print("quota distribution is null - warehouse app signals")
|
||||
|
||||
|
||||
@receiver(post_save, sender=InventoryQuotaSaleItem)
|
||||
def update_quota_stats_on_sale(sender, instance: InventoryQuotaSaleItem, created, **kwargs):
|
||||
if instance.transaction.transaction_status == 'success':
|
||||
return
|
||||
|
||||
stats = OrganizationQuotaStats.objects.filter(
|
||||
organization=instance.quota_distribution.assigned_organization,
|
||||
quota=instance.quota_distribution.quota
|
||||
).first()
|
||||
|
||||
if stats:
|
||||
stats.update_amounts()
|
||||
|
||||
Reference in New Issue
Block a user