diff --git a/apps/product/signals.py b/apps/product/signals.py index d82cce6..99b53e3 100644 --- a/apps/product/signals.py +++ b/apps/product/signals.py @@ -1,10 +1,15 @@ +from crum import get_current_user +from django.contrib.auth.models import AnonymousUser +from django.db import models from django.db.models import Sum, Q from django.db.models.signals import post_save, post_delete -from django.contrib.auth.models import AnonymousUser -from common.helpers import get_organization_by_user -from rest_framework.exceptions import APIException from django.dispatch import receiver -from apps.authentication.models import User + +from apps.warehouse.models import ( + InventoryQuotaSaleTransaction, + InventoryEntry +) +from common.helpers import get_organization_by_user from .models import ( QuotaDistribution, Quota, @@ -12,18 +17,13 @@ from .models import ( ProductStats, QuotaStats ) -from apps.warehouse.models import ( - InventoryQuotaSaleTransaction, - InventoryEntry -) -from django.db import models -from crum import get_current_user def recalculate_remaining_amount(quota): """ calculate remaining weight from distribution """ total_distributed = quota.distributions_assigned.filter( parent_distribution__isnull=True, + trash=False, ).aggregate( total=Sum('weight') )['total'] or 0 @@ -36,12 +36,12 @@ def recalculate_remaining_amount(quota): def remaining_distribution_weight(instance: QuotaDistribution): """ calculate remaining & distributed weight from distribution """ - total_children_weight = instance.children.aggregate( + total_children_weight = instance.children.filter(trash=False).aggregate( total=Sum('weight') )['total'] or 0 # total warehouse inventory entry - total_entry = instance.inventory_entry.aggregate( + total_entry = instance.inventory_entry.filter(trash=False).aggregate( total=Sum('weight') )['total'] or 0