fix distribution delete bug, in signals
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 5.0 on 2025-08-02 04:25
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('pos_device', '0017_alter_deviceactivationcode_expires_at'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='deviceactivationcode',
|
||||
name='expires_at',
|
||||
field=models.DateTimeField(default=datetime.datetime(2025, 8, 2, 7, 55, 41, 619525)),
|
||||
),
|
||||
]
|
||||
@@ -51,6 +51,12 @@ def update_quota_remaining(sender, instance, **kwargs):
|
||||
# if _from_signal=True prevent from maximum recursion loop
|
||||
if getattr(instance, '_from_signal', False):
|
||||
return
|
||||
|
||||
# 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)
|
||||
|
||||
|
||||
|
||||
@@ -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