fix - comment quota stat on sale in warehouse signals
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
@@ -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()
|
||||
# برای محصولات ازاد چک شود و کنترل
|
||||
|
||||
Reference in New Issue
Block a user