fix - device pre register & exception handling with json response
This commit is contained in:
28
apps/product/services/quota_distribution_service.py
Normal file
28
apps/product/services/quota_distribution_service.py
Normal file
@@ -0,0 +1,28 @@
|
||||
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
|
||||
Reference in New Issue
Block a user