From 254a1678ac51bac756eeff062410d03a1d3d6569 Mon Sep 17 00:00:00 2001 From: behruz-dev Date: Wed, 3 Sep 2025 17:50:05 +0500 Subject: [PATCH] add: add counterparty filter for counterparty list api --- core/apps/counterparty/filters/__init__.py | 0 core/apps/counterparty/filters/counterparty.py | 11 +++++++++++ .../migrations/0004_counterparty_status.py | 18 ++++++++++++++++++ core/apps/counterparty/models/conterparty.py | 5 +++++ core/apps/counterparty/views/counterparty.py | 5 ++++- 5 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 core/apps/counterparty/filters/__init__.py create mode 100644 core/apps/counterparty/filters/counterparty.py create mode 100644 core/apps/counterparty/migrations/0004_counterparty_status.py diff --git a/core/apps/counterparty/filters/__init__.py b/core/apps/counterparty/filters/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/apps/counterparty/filters/counterparty.py b/core/apps/counterparty/filters/counterparty.py new file mode 100644 index 0000000..c2f2599 --- /dev/null +++ b/core/apps/counterparty/filters/counterparty.py @@ -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' + ] \ No newline at end of file diff --git a/core/apps/counterparty/migrations/0004_counterparty_status.py b/core/apps/counterparty/migrations/0004_counterparty_status.py new file mode 100644 index 0000000..40c38d0 --- /dev/null +++ b/core/apps/counterparty/migrations/0004_counterparty_status.py @@ -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), + ), + ] diff --git a/core/apps/counterparty/models/conterparty.py b/core/apps/counterparty/models/conterparty.py index cb569e9..4f779be 100644 --- a/core/apps/counterparty/models/conterparty.py +++ b/core/apps/counterparty/models/conterparty.py @@ -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', diff --git a/core/apps/counterparty/views/counterparty.py b/core/apps/counterparty/views/counterparty.py index 6934050..94b53a8 100644 --- a/core/apps/counterparty/views/counterparty.py +++ b/core/apps/counterparty/views/counterparty.py @@ -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):