From da0326afef57cc164384c9644918f95db0575a60 Mon Sep 17 00:00:00 2001 From: Hrishabh Tiwari <74908943+Hrishabh17@users.noreply.github.com> Date: Mon, 22 Jul 2024 22:07:06 +0530 Subject: [PATCH] add support to search for code in mappings page (#113) * add support to search for code in mappings page * add name to the url --- fyle_accounting_mappings/helpers.py | 20 ++++++++++++++++++++ fyle_accounting_mappings/urls.py | 2 +- fyle_accounting_mappings/views.py | 6 ++++-- setup.py | 2 +- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/fyle_accounting_mappings/helpers.py b/fyle_accounting_mappings/helpers.py index 9f7326c..024fd08 100644 --- a/fyle_accounting_mappings/helpers.py +++ b/fyle_accounting_mappings/helpers.py @@ -301,3 +301,23 @@ def filter_mapping_source_alphabets(self, queryset, name, value): class Meta: model = ExpenseAttribute fields = ['mapping_source_alphabets', 'value'] + + +class DestinationAttributeFilter(django_filters.FilterSet): + value = django_filters.CharFilter(method='filter_value') + + class Meta: + model = DestinationAttribute + fields = { + 'attribute_type': ['exact', 'in'], + 'display_name': ['exact', 'in'], + 'value': ['icontains'], + 'code': ['icontains'], + } + + def filter_value(self, queryset, name, value): + if value: + return queryset.filter( + Q(value__icontains=value) | Q(code__icontains=value) + ) + return queryset diff --git a/fyle_accounting_mappings/urls.py b/fyle_accounting_mappings/urls.py index f8cb73e..97d3a5a 100644 --- a/fyle_accounting_mappings/urls.py +++ b/fyle_accounting_mappings/urls.py @@ -45,5 +45,5 @@ path('expense_fields/', ExpenseFieldView.as_view()), path('destination_attributes/', DestinationAttributesView.as_view()), path('fyle_fields/', FyleFieldsView.as_view()), - path('paginated_destination_attributes/', PaginatedDestinationAttributesView.as_view()), + path('paginated_destination_attributes/', PaginatedDestinationAttributesView.as_view(), name='paginated_destination_attributes_view'), ] diff --git a/fyle_accounting_mappings/views.py b/fyle_accounting_mappings/views.py index 669223c..9ea321a 100644 --- a/fyle_accounting_mappings/views.py +++ b/fyle_accounting_mappings/views.py @@ -17,7 +17,7 @@ EmployeeAttributeMappingSerializer, ExpenseFieldSerializer, CategoryAttributeMappingSerializer, \ FyleFieldsSerializer -from .helpers import ExpenseAttributeFilter +from .helpers import ExpenseAttributeFilter, DestinationAttributeFilter logger = logging.getLogger(__name__) @@ -346,6 +346,7 @@ def get_queryset(self): final_filter = final_filter & param return ExpenseAttribute.objects.filter(final_filter).order_by('value') + class EmployeeAttributesMappingView(ListAPIView): serializer_class = EmployeeAttributeMappingSerializer @@ -428,6 +429,7 @@ class FyleFieldsView(ListAPIView): def get_queryset(self): return FyleFieldsSerializer().format_fyle_fields(self.kwargs["workspace_id"]) + class PaginatedDestinationAttributesView(LookupFieldMixin, ListAPIView): """ Paginated Destination Attributes view @@ -435,4 +437,4 @@ class PaginatedDestinationAttributesView(LookupFieldMixin, ListAPIView): queryset = DestinationAttribute.objects.filter(active=True).order_by('value') serializer_class = DestinationAttributeSerializer filter_backends = (DjangoFilterBackend,) - filterset_fields = {'attribute_type': {'exact', 'in'}, 'display_name': {'exact', 'in'}, 'value': {'icontains'}} + filterset_class = DestinationAttributeFilter diff --git a/setup.py b/setup.py index 400ecbf..d39f30f 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setuptools.setup( name='fyle-accounting-mappings', - version='1.34.0', + version='1.34.1', author='Shwetabh Kumar', author_email='shwetabh.kumar@fyle.in', description='Django application to store the fyle accounting mappings in a generic manner',