add: add counterparty filter for counterparty list api
This commit is contained in:
0
core/apps/counterparty/filters/__init__.py
Normal file
0
core/apps/counterparty/filters/__init__.py
Normal file
11
core/apps/counterparty/filters/counterparty.py
Normal file
11
core/apps/counterparty/filters/counterparty.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import django_filters
|
||||
|
||||
from core.apps.counterparty.models import Counterparty
|
||||
|
||||
|
||||
class CounterpartyFilter(django_filters.FilterSet):
|
||||
class Meta:
|
||||
model = Counterparty
|
||||
fields = [
|
||||
'type', 'status'
|
||||
]
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.2.4 on 2025-09-03 17:47
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('counterparty', '0003_counterparty_is_archived'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='counterparty',
|
||||
name='status',
|
||||
field=models.CharField(choices=[('CREDITOR', 'kreditor'), ('DEBITOR', 'debitor')], default='kreditor', max_length=20),
|
||||
),
|
||||
]
|
||||
@@ -20,12 +20,17 @@ class Counterparty(BaseModel):
|
||||
('SUPPLIER', "ta'minotchi"),
|
||||
('WORKER', 'ishchi')
|
||||
)
|
||||
STATUS = (
|
||||
('CREDITOR', 'kreditor'),
|
||||
('DEBITOR', 'debitor')
|
||||
)
|
||||
|
||||
inn = models.CharField(max_length=20, null=True)
|
||||
name = models.CharField(max_length=200)
|
||||
phone = models.CharField(max_length=15, null=True)
|
||||
|
||||
type = models.CharField(max_length=20, choices=TYPE, default='SUPPLIER')
|
||||
status = models.CharField(max_length=20, choices=STATUS, default='kreditor')
|
||||
folder = models.ForeignKey(
|
||||
CounterpartyFolder, on_delete=models.SET_NULL, null=True, blank=True,
|
||||
related_name='counterparties',
|
||||
|
||||
@@ -2,12 +2,13 @@ from django.shortcuts import get_object_or_404
|
||||
|
||||
from rest_framework import generics, views
|
||||
from rest_framework.response import Response
|
||||
from django_filters.rest_framework.backends import DjangoFilterBackend
|
||||
|
||||
from core.apps.accounts.permissions.permissions import HasRolePermission
|
||||
from core.apps.shared.paginations.custom import CustomPageNumberPagination
|
||||
from core.apps.counterparty.models import Counterparty
|
||||
from core.apps.counterparty.serializers import counterparty as serializers
|
||||
|
||||
from core.apps.counterparty.filters.counterparty import CounterpartyFilter
|
||||
|
||||
class CounterpartyListApiView(generics.ListAPIView):
|
||||
serializer_class = serializers.CounterpartyListSerializer
|
||||
@@ -15,6 +16,8 @@ class CounterpartyListApiView(generics.ListAPIView):
|
||||
pagination_class = [HasRolePermission]
|
||||
required_permissions = []
|
||||
pagination_class = CustomPageNumberPagination
|
||||
filter_backends = [DjangoFilterBackend]
|
||||
filterset_class = CounterpartyFilter
|
||||
|
||||
|
||||
class CounterpartyCreateApiView(generics.GenericAPIView):
|
||||
|
||||
Reference in New Issue
Block a user