diff --git a/core/apps/counterparty/migrations/0003_counterparty_is_archived.py b/core/apps/counterparty/migrations/0003_counterparty_is_archived.py new file mode 100644 index 0000000..0c16321 --- /dev/null +++ b/core/apps/counterparty/migrations/0003_counterparty_is_archived.py @@ -0,0 +1,18 @@ +# Generated by Django 5.2.4 on 2025-09-03 17:15 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('counterparty', '0002_counterpartyfolder_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='counterparty', + name='is_archived', + field=models.BooleanField(default=False), + ), + ] diff --git a/core/apps/counterparty/models/conterparty.py b/core/apps/counterparty/models/conterparty.py index 14cc583..cb569e9 100644 --- a/core/apps/counterparty/models/conterparty.py +++ b/core/apps/counterparty/models/conterparty.py @@ -42,6 +42,7 @@ class Counterparty(BaseModel): ) balance_date = models.DateField(null=True, blank=True) comment = models.TextField(null=True, blank=True) + is_archived = models.BooleanField(default=False) def __str__(self): return self.name diff --git a/core/apps/counterparty/serializers/counterparty.py b/core/apps/counterparty/serializers/counterparty.py index 7ff25b5..98d5624 100644 --- a/core/apps/counterparty/serializers/counterparty.py +++ b/core/apps/counterparty/serializers/counterparty.py @@ -11,7 +11,7 @@ class CounterpartyListSerializer(serializers.ModelSerializer): model = Counterparty fields = [ 'id', 'inn', 'name', 'phone', 'type', 'folder', 'type', 'region', 'district', - 'balance', 'balance_currency', 'balance_date', 'comment', + 'balance', 'balance_currency', 'balance_date', 'comment', 'is_archived', ] diff --git a/core/apps/counterparty/urls.py b/core/apps/counterparty/urls.py index 85b3825..c095561 100644 --- a/core/apps/counterparty/urls.py +++ b/core/apps/counterparty/urls.py @@ -9,6 +9,7 @@ urlpatterns = [ [ path('list/', cp_views.CounterpartyListApiView.as_view()), path('create/', cp_views.CounterpartyCreateApiView.as_view()), + path('/archive/', cp_views.ArchiveCounterpartyApiView.as_view()), ] )), path('counterparty_folder/', include( diff --git a/core/apps/counterparty/views/counterparty.py b/core/apps/counterparty/views/counterparty.py index 0c3b6d4..6225949 100644 --- a/core/apps/counterparty/views/counterparty.py +++ b/core/apps/counterparty/views/counterparty.py @@ -1,3 +1,5 @@ +from django.shortcuts import get_object_or_404 + from rest_framework import generics, views from rest_framework.response import Response @@ -9,7 +11,7 @@ from core.apps.counterparty.serializers import counterparty as serializers class CounterpartyListApiView(generics.ListAPIView): serializer_class = serializers.CounterpartyListSerializer - queryset = Counterparty.objects.all() + queryset = Counterparty.objects.exclude(is_archived=True) pagination_class = [HasRolePermission] required_permissions = [] pagination_class = CustomPageNumberPagination @@ -32,4 +34,18 @@ class CounterpartyCreateApiView(generics.GenericAPIView): return Response( {'success': False, 'message': serializer.errors}, status=400 + ) + + +class ArchiveCounterpartyApiView(views.APIView): + permission_classes = [HasRolePermission] + required_permissions = [] + + def get(self, request, id): + counterparty = get_object_or_404(Counterparty, id=id) + counterparty.is_archived = True + counterparty.save() + return Response( + {'success': True, 'message': 'counterparty archived'}, + status=200 ) \ No newline at end of file