add - whole system of inventory entry in organization quotas stat
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
from django.db.models import Sum
|
||||
from django.db.models.signals import post_save, post_delete
|
||||
from django.db.models.signals import post_save, post_delete, post_init
|
||||
from django.dispatch import receiver
|
||||
|
||||
from apps.product.models import QuotaDistribution
|
||||
from .models import InventoryEntry, InventoryQuotaSaleItem
|
||||
from .services.warehouse_allocation_service import WarehouseAllocationService
|
||||
from ..product.services.quota_stat_service import QuotaStatsService
|
||||
|
||||
|
||||
def calculate_warehouse_entry(quota_distribution):
|
||||
@@ -50,17 +52,34 @@ def warehouse_sold_and_balance(quota_distribution: QuotaDistribution):
|
||||
quota_distribution.save(update_fields=['been_sold', 'warehouse_balance', 'free_sale_balance', 'pre_sale_balance'])
|
||||
|
||||
|
||||
@receiver(post_init, sender=InventoryEntry)
|
||||
def inventory_entry_pre_save(sender, instance: InventoryEntry, **kwargs):
|
||||
if instance.pk:
|
||||
instance._is_update = True
|
||||
instance._old_weight = instance.weight
|
||||
else:
|
||||
instance._is_update = False
|
||||
|
||||
|
||||
@receiver(post_save, sender=InventoryEntry)
|
||||
def update_quota_stat_on_entry_update(sender, instance: InventoryEntry, created, **kwargs):
|
||||
if instance._is_update: # noqa
|
||||
QuotaStatsService.apply_inventory_entry(instance, created=False)
|
||||
else:
|
||||
WarehouseAllocationService.allocate(entry=instance)
|
||||
|
||||
|
||||
@receiver(post_save, sender=InventoryEntry)
|
||||
def update_quota_stat_on_entry_soft_delete(sender, instance, **kwargs):
|
||||
if instance.trash:
|
||||
pass
|
||||
QuotaStatsService.remove_inventory_entry(instance)
|
||||
|
||||
|
||||
@receiver(post_save, sender=InventoryEntry)
|
||||
@receiver(post_delete, sender=InventoryEntry)
|
||||
def update_distribution_warehouse_entry(sender, instance, **kwargs):
|
||||
calculate_warehouse_entry(instance.distribution)
|
||||
warehouse_sold_and_balance(instance.distribution)
|
||||
# @receiver(post_save, sender=InventoryEntry)
|
||||
# @receiver(post_delete, sender=InventoryEntry)
|
||||
# def update_distribution_warehouse_entry(sender, instance, **kwargs):
|
||||
# calculate_warehouse_entry(instance.distribution)
|
||||
# warehouse_sold_and_balance(instance.distribution)
|
||||
|
||||
|
||||
@receiver(post_save, sender=InventoryQuotaSaleItem)
|
||||
|
||||
Reference in New Issue
Block a user