From 78ddd9cdeb1093e1b74f7f92f132952b6e71cd24 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Mon, 17 Nov 2025 11:53:56 +0330 Subject: [PATCH] fix - comment quota stat on sale in warehouse signals --- apps/product/services/quota_stat_service.py | 14 +++++++---- apps/warehouse/signals.py | 28 ++++++++++----------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/apps/product/services/quota_stat_service.py b/apps/product/services/quota_stat_service.py index 3dbabd3..5f89f21 100644 --- a/apps/product/services/quota_stat_service.py +++ b/apps/product/services/quota_stat_service.py @@ -8,17 +8,20 @@ class QuotaStatsService: # origin org assigner = distribution.assigner_organization + print(assigner) # destination org assigned = distribution.assigned_organization - print(assigned) # ================ origin ================ - assigner_stat, _ = OrganizationQuotaStats.objects.get_or_create( + assigner_stat, created = OrganizationQuotaStats.objects.get_or_create( organization=assigner, quota=quota, - stat_type='distribution' ) - + if created: + assigner_stat.stat_type = 'distribution' + assigner_stat.save() + print(assigner_stat.remaining_amount) assigner_stat.remaining_amount -= distribution.weight + print(assigner_stat.remaining_amount) assigner_stat.total_distributed += distribution.weight assigner_stat.save() @@ -60,8 +63,9 @@ class QuotaStatsService: assigner_stat.total_distributed += diff print(assigner_stat.total_distributed, diff) assigner_stat.save() - + print(assigned_stat.total_amount) assigned_stat.total_amount += diff + print(assigned_stat.total_amount) assigned_stat.remaining_amount += diff assigned_stat.save() diff --git a/apps/warehouse/signals.py b/apps/warehouse/signals.py index 19dabe0..441a995 100644 --- a/apps/warehouse/signals.py +++ b/apps/warehouse/signals.py @@ -2,7 +2,7 @@ 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, OrganizationQuotaStats +from apps.product.models import QuotaDistribution from .models import InventoryEntry, InventoryQuotaSaleItem @@ -69,16 +69,16 @@ 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() +# @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() +# برای محصولات ازاد چک شود و کنترل