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)
|
||||
comment = models.TextField(null=True, blank=True)
|
||||
is_archived = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
@@ -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',
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ urlpatterns = [
|
||||
[
|
||||
path('list/', cp_views.CounterpartyListApiView.as_view()),
|
||||
path('create/', cp_views.CounterpartyCreateApiView.as_view()),
|
||||
path('<uuid:id>/archive/', cp_views.ArchiveCounterpartyApiView.as_view()),
|
||||
]
|
||||
)),
|
||||
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.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
|
||||
@@ -33,3 +35,17 @@ class CounterpartyCreateApiView(generics.GenericAPIView):
|
||||
{'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
|
||||
)
|
||||
Reference in New Issue
Block a user