fix distribution delete bug, in signals
This commit is contained in:
@@ -51,7 +51,13 @@ def update_quota_remaining(sender, instance, **kwargs):
|
||||
# if _from_signal=True prevent from maximum recursion loop
|
||||
if getattr(instance, '_from_signal', False):
|
||||
return
|
||||
remaining_distribution_weight(instance)
|
||||
|
||||
# when delete object, prevent from update fields error
|
||||
if kwargs.get('signal') == post_delete:
|
||||
if instance.parent_distribution:
|
||||
remaining_distribution_weight(instance.parent_distribution)
|
||||
else:
|
||||
remaining_distribution_weight(instance)
|
||||
|
||||
|
||||
def update_product_stats(instance: Product):
|
||||
|
||||
@@ -147,16 +147,10 @@ class QuotaDistributionViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
|
||||
except APIException as e:
|
||||
return Response(e, status.HTTP_204_NO_CONTENT)
|
||||
|
||||
@action(
|
||||
methods=['post'],
|
||||
detail=True,
|
||||
url_name='delete',
|
||||
url_path='delete',
|
||||
name='delete'
|
||||
)
|
||||
@transaction.atomic
|
||||
def delete(self, request, pk=None):
|
||||
def destroy(self, request, pk=None, *args, **kwargs):
|
||||
""" Full delete of quota distribution object """
|
||||
|
||||
quota_distribution = self.get_object()
|
||||
|
||||
# check if distribution has inventory entry
|
||||
@@ -168,5 +162,5 @@ class QuotaDistributionViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
|
||||
try:
|
||||
delete(self.queryset, pk)
|
||||
return Response(status=status.HTTP_200_OK)
|
||||
except APIException as e:
|
||||
except Exception as e:
|
||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
Reference in New Issue
Block a user