Merge branch 'main' of https://github.com/MNPC-IR/Rasaddam_Backend
This commit is contained in:
@@ -7,7 +7,7 @@ from openpyxl import Workbook
|
||||
from rest_framework import viewsets, filters
|
||||
from rest_framework.decorators import action
|
||||
|
||||
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
||||
from apps.core.mixins.search_mixin import ExcelDynamicSearchMixin
|
||||
from apps.product import models as product_models
|
||||
from apps.product.web.api.v1.serializers import quota_distribution_serializers as distribution_serializers
|
||||
from apps.product.web.api.v1.serializers.product_serializers import IncentivePlanSerializer
|
||||
@@ -17,10 +17,18 @@ from common.helper_excel import create_header, excel_description, create_header_
|
||||
from common.helpers import get_organization_by_user
|
||||
|
||||
|
||||
class ProductExcelViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
|
||||
class ProductExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin):
|
||||
queryset = product_models.QuotaDistribution.objects.all()
|
||||
serializer_class = distribution_serializers.QuotaDistributionSerializer
|
||||
filter_backends = [filters.SearchFilter]
|
||||
search_fields = [
|
||||
"registerer_organization__name",
|
||||
"quota_id",
|
||||
"product__name",
|
||||
"sale_type",
|
||||
"sale_unit__unit",
|
||||
"group",
|
||||
]
|
||||
|
||||
# noqa # سهمیه و توزیع
|
||||
@action(
|
||||
@@ -183,14 +191,16 @@ class ProductExcelViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
|
||||
worksheet = workbook.active
|
||||
worksheet.sheet_view.rightToLeft = True
|
||||
worksheet.insert_rows(1)
|
||||
search_fields_incentive_plans = ['plan_type', 'name']
|
||||
|
||||
today = datetime.now().date()
|
||||
user_relations = product_models.UserRelations.objects.filter(user=request.user).first()
|
||||
|
||||
incentive_plans = user_relations.incentive_plans.filter(
|
||||
Q(is_time_unlimited=False) |
|
||||
Q(start_date_limit__lte=today, end_date_limit__gte=today)
|
||||
)
|
||||
|
||||
incentive_plans = self.filter_query(incentive_plans, search_list=search_fields_incentive_plans)
|
||||
ser_data = IncentivePlanSerializer(incentive_plans, many=True).data
|
||||
|
||||
excel_options = [
|
||||
@@ -269,8 +279,7 @@ class ProductExcelViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
|
||||
def detail_quota_excel(self, request):
|
||||
queryset = product_models.Quota.objects.filter(id=request.GET['id'], trash=False)
|
||||
serializer_class = QuotaSerializer
|
||||
filter_backends = [filters.SearchFilter]
|
||||
search_fields = [
|
||||
search_fields_detail_quota = [
|
||||
"registerer_organization__name",
|
||||
"quota_id",
|
||||
"product__name",
|
||||
@@ -278,6 +287,7 @@ class ProductExcelViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
|
||||
"sale_unit__unit",
|
||||
"group",
|
||||
]
|
||||
queryset = self.filter_query(queryset, search_list=search_fields_detail_quota)
|
||||
|
||||
output = BytesIO()
|
||||
workbook = Workbook()
|
||||
@@ -286,7 +296,6 @@ class ProductExcelViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
|
||||
worksheet.insert_rows(1)
|
||||
|
||||
active = request.GET.get('active')
|
||||
queryset = self.filter_query(queryset) # return by search param or all objects
|
||||
|
||||
organization = get_organization_by_user(request.user)
|
||||
queryset = queryset.filter(
|
||||
@@ -525,10 +534,7 @@ class ProductExcelViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
|
||||
name='quota_excel'
|
||||
)
|
||||
def quota_excel(self, request):
|
||||
queryset = product_models.Quota.objects.all()
|
||||
serializer_class = QuotaSerializer
|
||||
filter_backends = [filters.SearchFilter]
|
||||
search_fields = [
|
||||
search_fields_quota = [
|
||||
"registerer_organization__name",
|
||||
"quota_id",
|
||||
"product__name",
|
||||
@@ -537,6 +543,8 @@ class ProductExcelViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
|
||||
"group",
|
||||
]
|
||||
|
||||
queryset = product_models.Quota.objects.all()
|
||||
serializer_class = QuotaSerializer
|
||||
output = BytesIO()
|
||||
workbook = Workbook()
|
||||
worksheet = workbook.active
|
||||
@@ -544,11 +552,10 @@ class ProductExcelViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
|
||||
worksheet.insert_rows(1)
|
||||
|
||||
active = request.GET.get('active')
|
||||
queryset = self.filter_query(queryset) # return by search param or all objects
|
||||
|
||||
organization = get_organization_by_user(request.user)
|
||||
|
||||
if active:
|
||||
if active == 'true':
|
||||
queryset = queryset.filter(
|
||||
Q(registerer_organization=organization),
|
||||
Q(is_closed=False)
|
||||
@@ -562,6 +569,7 @@ class ProductExcelViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
|
||||
).order_by('-modify_date')
|
||||
|
||||
quta_type = 'بایگانی'
|
||||
queryset = self.filter_query(queryset, search_list=search_fields_quota) # return by search param or all objects
|
||||
|
||||
ser_data = serializer_class(queryset, many=True).data
|
||||
excel_options = [
|
||||
|
||||
Reference in New Issue
Block a user