diff --git a/fyle_accounting_mappings/urls.py b/fyle_accounting_mappings/urls.py index 2e49be2..69b52c0 100644 --- a/fyle_accounting_mappings/urls.py +++ b/fyle_accounting_mappings/urls.py @@ -25,7 +25,8 @@ MappingStatsView, ExpenseAttributesMappingView, EmployeeAttributesMappingView, - ExpenseFieldView + ExpenseFieldView, + DestinationAttributesView ) urlpatterns = [ @@ -40,5 +41,5 @@ path('category_attributes/', CategoryAttributesMappingView.as_view()), path('employee_attributes/', EmployeeAttributesMappingView.as_view()), path('expense_fields/', ExpenseFieldView.as_view()), - + path('destination_attributes/', DestinationAttributesView.as_view()), ] diff --git a/fyle_accounting_mappings/utils.py b/fyle_accounting_mappings/utils.py index fe00760..c34d901 100644 --- a/fyle_accounting_mappings/utils.py +++ b/fyle_accounting_mappings/utils.py @@ -13,3 +13,13 @@ def assert_valid(condition: bool, message: str) -> Response or None: raise ValidationError(detail={ 'message': message }) + +class LookupFieldMixin: + lookup_field = 'workspace_id' + + def filter_queryset(self, queryset): + if self.lookup_field in self.kwargs: + lookup_value = self.kwargs[self.lookup_field] + filter_kwargs = {self.lookup_field: lookup_value} + queryset = queryset.filter(**filter_kwargs) + return super().filter_queryset(queryset) diff --git a/fyle_accounting_mappings/views.py b/fyle_accounting_mappings/views.py index ef8c90b..2653116 100644 --- a/fyle_accounting_mappings/views.py +++ b/fyle_accounting_mappings/views.py @@ -3,11 +3,13 @@ from functools import reduce from typing import Dict, List -from rest_framework.generics import ListCreateAPIView, ListAPIView, DestroyAPIView, RetrieveAPIView +from django_filters.rest_framework import DjangoFilterBackend +from rest_framework.generics import ListCreateAPIView, ListAPIView, DestroyAPIView from rest_framework.response import Response from rest_framework.views import status from django.db.models import Count, Q +from .utils import LookupFieldMixin from .exceptions import BulkError from .utils import assert_valid from .models import MappingSetting, Mapping, ExpenseAttribute, DestinationAttribute, EmployeeMapping, \ @@ -436,3 +438,16 @@ def get_queryset(self): return ExpenseField.objects.filter( workspace_id=self.kwargs['workspace_id'] ).all() + + +class DestinationAttributesView(LookupFieldMixin, ListAPIView): + """ + Destination Attributes view + """ + + queryset = DestinationAttribute.objects.all() + serializer_class = DestinationAttributeSerializer + pagination_class = None + filter_backends = (DjangoFilterBackend,) + filterset_fields = {'attribute_type': {'exact', 'in'}, 'display_name': {'exact', 'in'}, 'active': {'exact'}} + ordering_fields = ('value',) diff --git a/requirements.txt b/requirements.txt index a7a1e32..9c35138 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,7 @@ chardet==3.0.4 charset-normalizer==2.0.8 Django==3.1.14 django-rest-framework==0.1.0 +django-filter==21.1 djangorestframework==3.11.2 idna==2.8 isort==4.3.21 diff --git a/setup.py b/setup.py index 970c508..9cf28d7 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setuptools.setup( name='fyle-accounting-mappings', - version='1.27.3', + version='1.28.0', author='Shwetabh Kumar', author_email='shwetabh.kumar@fyle.in', description='Django application to store the fyle accounting mappings in a generic manner',