remove bank account when remove org

This commit is contained in:
2025-11-05 12:33:53 +03:30
parent 82e004166b
commit 1942042a2b
3 changed files with 61 additions and 48 deletions

View File

@@ -231,7 +231,7 @@ class OrganizationTypeViewSet(BaseViewSet, SoftDeleteMixin, ModelViewSet):
return self.get_paginated_response(serializer.data)
class OrganizationViewSet(BaseViewSet, SoftDeleteMixin, ModelViewSet, DynamicSearchMixin):
class OrganizationViewSet(BaseViewSet, ModelViewSet, DynamicSearchMixin):
""" Crud operations for organization model """ #
queryset = Organization.objects.all()
serializer_class = OrganizationSerializer
@@ -384,6 +384,19 @@ class OrganizationViewSet(BaseViewSet, SoftDeleteMixin, ModelViewSet, DynamicSea
serializer = self.serializer_class(page, many=True)
return self.get_paginated_response(serializer.data)
@transaction.atomic
def destroy(self, request, pk=None, *args, **kwargs):
""" remove organization with bank accounts """
org = self.get_object()
org.bank_information.all().update(trash=True)
org.soft_delete()
return Response(
{"detail": "رکورد با موفقیت حذف شد (Soft Delete)."}, # noqa
status=status.HTTP_204_NO_CONTENT
)
class BankAccountViewSet(SoftDeleteMixin, ModelViewSet):
""" Crud operations for bank account model """ #