quota stat by organization - v1
This commit is contained in:
@@ -87,9 +87,6 @@ class QuotaDistributionSerializer(serializers.ModelSerializer):
|
||||
if not self.instance.parent_distribution:
|
||||
if amount + total > self.instance.quota.quota_weight:
|
||||
raise APIException("وزن وارد شده بیشتر از وزن باقیمانده است", code=403) # noqa
|
||||
# else:
|
||||
# if amount > self.instance.parent_distribution.remaining_weight:
|
||||
# raise QuotaWeightException()
|
||||
|
||||
return data
|
||||
|
||||
|
||||
@@ -10,8 +10,15 @@ class QuotaSerializer(serializers.ModelSerializer):
|
||||
model = product_models.Quota
|
||||
fields = '__all__'
|
||||
|
||||
def to_representation(self, instance):
|
||||
def to_representation(self, instance: product_models.Quota):
|
||||
representation = super().to_representation(instance)
|
||||
|
||||
# change quota weight by organization received weight
|
||||
if self.context['org']:
|
||||
quota_weight_by_org = instance.quota_amount_by_org(self.context['org'])
|
||||
if quota_weight_by_org:
|
||||
representation['quota_weight'] = quota_weight_by_org
|
||||
|
||||
if isinstance(instance, product_models.Quota):
|
||||
if instance.sale_unit:
|
||||
representation['sale_unit'] = product_serializers.SaleUnitSerializer(
|
||||
|
||||
@@ -355,7 +355,7 @@ class QuotaViewSet(BaseViewSet, SoftDeleteMixin, viewsets.ModelViewSet, DynamicS
|
||||
queryset.order_by('-modify_date')
|
||||
)
|
||||
if page is not None: # noqa
|
||||
serializer = self.get_serializer(page, many=True)
|
||||
serializer = self.get_serializer(page, many=True, context={'org': get_organization_by_user(request.user)})
|
||||
return self.get_paginated_response(serializer.data)
|
||||
|
||||
@action(
|
||||
|
||||
@@ -65,6 +65,10 @@ class QuotaDistributionViewSet(BaseViewSet, SoftDeleteMixin, viewsets.ModelViewS
|
||||
if serializer.is_valid():
|
||||
distribution = serializer.save()
|
||||
|
||||
# add this organization to quota assigned_organizations
|
||||
# this org is received a distribution from quota
|
||||
distribution.quota.assigned_organizations.add(distribution.assigned_organization)
|
||||
|
||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||
return Response(serializer.errors, status=status.HTTP_403_FORBIDDEN)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user