add: add archive api for counterparty
This commit is contained in:
@@ -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),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -42,6 +42,7 @@ class Counterparty(BaseModel):
|
|||||||
)
|
)
|
||||||
balance_date = models.DateField(null=True, blank=True)
|
balance_date = models.DateField(null=True, blank=True)
|
||||||
comment = models.TextField(null=True, blank=True)
|
comment = models.TextField(null=True, blank=True)
|
||||||
|
is_archived = models.BooleanField(default=False)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class CounterpartyListSerializer(serializers.ModelSerializer):
|
|||||||
model = Counterparty
|
model = Counterparty
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'inn', 'name', 'phone', 'type', 'folder', 'type', 'region', 'district',
|
'id', 'inn', 'name', 'phone', 'type', 'folder', 'type', 'region', 'district',
|
||||||
'balance', 'balance_currency', 'balance_date', 'comment',
|
'balance', 'balance_currency', 'balance_date', 'comment', 'is_archived',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ urlpatterns = [
|
|||||||
[
|
[
|
||||||
path('list/', cp_views.CounterpartyListApiView.as_view()),
|
path('list/', cp_views.CounterpartyListApiView.as_view()),
|
||||||
path('create/', cp_views.CounterpartyCreateApiView.as_view()),
|
path('create/', cp_views.CounterpartyCreateApiView.as_view()),
|
||||||
|
path('<uuid:id>/archive/', cp_views.ArchiveCounterpartyApiView.as_view()),
|
||||||
]
|
]
|
||||||
)),
|
)),
|
||||||
path('counterparty_folder/', include(
|
path('counterparty_folder/', include(
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
from django.shortcuts import get_object_or_404
|
||||||
|
|
||||||
from rest_framework import generics, views
|
from rest_framework import generics, views
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
@@ -9,7 +11,7 @@ from core.apps.counterparty.serializers import counterparty as serializers
|
|||||||
|
|
||||||
class CounterpartyListApiView(generics.ListAPIView):
|
class CounterpartyListApiView(generics.ListAPIView):
|
||||||
serializer_class = serializers.CounterpartyListSerializer
|
serializer_class = serializers.CounterpartyListSerializer
|
||||||
queryset = Counterparty.objects.all()
|
queryset = Counterparty.objects.exclude(is_archived=True)
|
||||||
pagination_class = [HasRolePermission]
|
pagination_class = [HasRolePermission]
|
||||||
required_permissions = []
|
required_permissions = []
|
||||||
pagination_class = CustomPageNumberPagination
|
pagination_class = CustomPageNumberPagination
|
||||||
@@ -32,4 +34,18 @@ class CounterpartyCreateApiView(generics.GenericAPIView):
|
|||||||
return Response(
|
return Response(
|
||||||
{'success': False, 'message': serializer.errors},
|
{'success': False, 'message': serializer.errors},
|
||||||
status=400
|
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
|
||||||
)
|
)
|
||||||
Reference in New Issue
Block a user