some changes in inventory serializer - creted date & distribution data
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user