Files
RasadDam_Backend/apps/product/services/quota_distribution_service.py

29 lines
801 B
Python

from django.db.models import Sum
from apps.product import models as product_models
class QuotaDistributionService:
"""
Service layer to manage multiple quota distributions as one unified entity.
Used for organization-based views and POS operations.
"""
def __init__(self, quota, organization):
self.quota = quota
self.organization = organization
self.distribution = product_models.QuotaDistribution.objects.filter(
quota=quota,
assigned_organization=organization,
quota__is_closed=False,
warehouse_entry__gt=0
).first()
@property
def total_weight(self):
return self.distribution.aggregate(
total=Sum('weight')
)['total'] or 0
pass