some changes in inventory serializer - creted date & distribution data

This commit is contained in:
2025-07-29 07:58:32 +03:30
parent e96da0ecc4
commit 63898533a3
5 changed files with 86 additions and 15 deletions

View File

@@ -1,5 +1,6 @@
from django.db.models import Sum
from django.db.models.signals import post_save, post_delete
from common.helpers import get_organization_by_user
from django.dispatch import receiver
from .models import (
QuotaDistribution,
@@ -13,6 +14,7 @@ from apps.warehouse.models import (
InventoryEntry
)
from django.db import models
from crum import get_current_user
def recalculate_remaining_amount(quota):
@@ -34,10 +36,12 @@ def update_quota_remaining(sender, instance, **kwargs):
def update_product_stats(instance: Product):
""" update all stats of product """
if hasattr(instance, 'stats'):
stat = instance.stats
organization = get_organization_by_user(get_current_user())
if ProductStats.objects.filter(organization=organization, product=instance):
stat = instance.stats.get(organization=organization, product=instance)
else:
stat = ProductStats.objects.create(product=instance)
stat = ProductStats.objects.create(product=instance, organization=organization)
# number of quotas
quotas_count = instance.quotas.filter(is_closed=False).count() # noqa