add company code to organization serialzier

This commit is contained in:
2025-06-16 08:29:17 +03:30
parent d8ca9d2256
commit 8df059bee9
7 changed files with 41 additions and 7 deletions

View File

@@ -294,6 +294,12 @@ class Quota(BaseModel):
return factor_total + broker_total + coop + factory
@property
def remaining_quota_weight(self):
""" calculate remaining quota weight after distribution """
distributed_weight = self.distributions_assigned.aggregate(total=models.Sum("weight"))["total"] or 0
return self.quota_weight - distributed_weight
def save(self, calculate_final_price=None, *args, **kwargs):
if not self.quota_id:
self.quota_id = self.generate_quota_id()
@@ -424,4 +430,3 @@ class QuotaDistribution(BaseModel):
def save(self, *args, **kwargs):
return super(QuotaDistribution, self).save(*args, **kwargs)

View File

@@ -424,6 +424,10 @@ class QuotaViewSet(viewsets.ModelViewSet): # noqa
quota.save(calculate_final_price=True)
return Response(data, status=status.HTTP_201_CREATED)
@transaction.atomic
def update(self, request, *args, **kwargs):
pass
@action(
methods=['get'],
detail=False,
@@ -489,7 +493,7 @@ class QuotaViewSet(viewsets.ModelViewSet): # noqa
return Response(e, status=status.HTTP_204_NO_CONTENT)
class QuotaIncentiveAssignmentViewSet(viewsets.ModelViewSet):
class QuotaIncentiveAssignmentViewSet(viewsets.ModelViewSet): # noqa
""" apis for incentive assignment """
queryset = product_models.QuotaIncentiveAssignment.objects.all()

View File

@@ -50,6 +50,23 @@ class QuotaDistributionViewSet(viewsets.ModelViewSet):
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_403_FORBIDDEN)
@transaction.atomic
def update(self, request, *args, **kwargs):
""" Custom update of quota distribution """
partial = kwargs.pop('partial', False)
instance = self.get_object()
serializer = self.get_serializer(instance, data=request.data, partial=partial)
serializer.is_valid(raise_exception=True)
self.perform_update(serializer)
if getattr(instance, '_prefetched_objects_cache', None):
# If 'prefetch_related' has been applied to a queryset, we need to
# forcibly invalidate the prefetch cache on the instance.
instance._prefetched_objects_cache = {}
return Response(serializer.data)
@action(
methods=['put'],
detail=True,