From 89b6f69c46e61e3ea70793f096fcb4e2f83f20a0 Mon Sep 17 00:00:00 2001 From: labhvam5 <88420539+labhvam5@users.noreply.github.com> Date: Wed, 10 Aug 2022 14:00:08 +0530 Subject: [PATCH] adding active flag to ExpenseAttributesMappingView and MappingStatsView (#62) --- fyle_accounting_mappings/views.py | 42 +++++++++++++++++++++++-------- setup.py | 2 +- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/fyle_accounting_mappings/views.py b/fyle_accounting_mappings/views.py index 1ddaf53..23cf32d 100644 --- a/fyle_accounting_mappings/views.py +++ b/fyle_accounting_mappings/views.py @@ -182,9 +182,16 @@ def get(self, request, *args, **kwargs): assert_valid(source_type is not None, 'query param source_type not found') assert_valid(destination_type is not None, 'query param destination_type not found') - total_attributes_count = ExpenseAttribute.objects.filter( - attribute_type=source_type, workspace_id=self.kwargs['workspace_id'] - ).count() + filters = { + 'attribute_type' : source_type, + 'workspace_id': self.kwargs['workspace_id'] + } + + if (source_type == 'PROJECT' and destination_type == 'CUSTOMER') or\ + (source_type == 'CATEGORY'): + filters['active'] = True + + total_attributes_count = ExpenseAttribute.objects.filter(**filters).count() if source_type == 'EMPLOYEE': filters = {} @@ -198,9 +205,16 @@ def get(self, request, *args, **kwargs): **filters, workspace_id=self.kwargs['workspace_id'] ).count() else: - mapped_attributes_count = Mapping.objects.filter( - source_type=source_type, destination_type=destination_type, workspace_id=self.kwargs['workspace_id'] - ).count() + filters = { + 'source_type' : source_type, + 'destination_type' : destination_type, + 'workspace_id': self.kwargs['workspace_id'] + } + if (source_type == 'PROJECT' and destination_type == 'CUSTOMER') or\ + (source_type == 'CATEGORY'): + filters['source__active'] = True + + mapped_attributes_count = Mapping.objects.filter(**filters).count() return Response( data={ @@ -240,21 +254,27 @@ def get_queryset(self): else: mapped = None + filters = { + 'workspace_id' : self.kwargs['workspace_id'], + 'attribute_type': source_type, + } + + if (source_type == 'PROJECT' and destination_type == 'CUSTOMER') or\ + (source_type == 'CATEGORY'): + filters['active'] = True + if mapped: param = Q(mapping__destination_type=destination_type) elif mapped is False: param = ~Q(mapping__destination_type=destination_type) else: return ExpenseAttribute.objects.filter( - reduce(operator.or_, (Q(value__istartswith=x) for x in mapping_source_alphabets)), - workspace_id=self.kwargs['workspace_id'], attribute_type=source_type, + reduce(operator.or_, (Q(value__istartswith=x) for x in mapping_source_alphabets)), **filters ).order_by('value').all() return ExpenseAttribute.objects.filter( reduce(operator.or_, (Q(value__istartswith=x) for x in mapping_source_alphabets)), - param, - workspace_id=self.kwargs['workspace_id'], attribute_type=source_type, - ).order_by('value').all() + param, **filters).order_by('value').all() class EmployeeAttributesMappingView(ListAPIView): diff --git a/setup.py b/setup.py index fe52e06..204aedc 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setuptools.setup( name='fyle-accounting-mappings', - version='1.17.0', + version='1.18.0', author='Shwetabh Kumar', author_email='shwetabh.kumar@fyle.in', description='Django application to store the fyle accounting mappings in a generic manner',