update my_distributions_excel
This commit is contained in:
@@ -4,9 +4,10 @@ from io import BytesIO
|
|||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from openpyxl import Workbook
|
from openpyxl import Workbook
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets, filters
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
|
|
||||||
|
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
||||||
from apps.product import models as product_models
|
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 import quota_distribution_serializers as distribution_serializers
|
||||||
from apps.product.web.api.v1.serializers.product_serializers import IncentivePlanSerializer
|
from apps.product.web.api.v1.serializers.product_serializers import IncentivePlanSerializer
|
||||||
@@ -15,9 +16,10 @@ from common.helper_excel import create_header, excel_description, create_header_
|
|||||||
from common.helpers import get_organization_by_user
|
from common.helpers import get_organization_by_user
|
||||||
|
|
||||||
|
|
||||||
class ProductExcelViewSet(viewsets.ModelViewSet):
|
class ProductExcelViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
|
||||||
queryset = product_models.QuotaDistribution.objects.all()
|
queryset = product_models.QuotaDistribution.objects.all()
|
||||||
serializer_class = distribution_serializers.QuotaDistributionSerializer
|
serializer_class = distribution_serializers.QuotaDistributionSerializer
|
||||||
|
filter_backends = [filters.SearchFilter]
|
||||||
|
|
||||||
# noqa # سهمیه و توزیع
|
# noqa # سهمیه و توزیع
|
||||||
@action(
|
@action(
|
||||||
@@ -34,9 +36,10 @@ class ProductExcelViewSet(viewsets.ModelViewSet):
|
|||||||
worksheet.sheet_view.rightToLeft = True
|
worksheet.sheet_view.rightToLeft = True
|
||||||
worksheet.insert_rows(1)
|
worksheet.insert_rows(1)
|
||||||
|
|
||||||
product = self.queryset
|
product = self.filter_query(self.queryset) # return by search param or all objects
|
||||||
query = request.query_params
|
|
||||||
organization = get_organization_by_user(request.user)
|
organization = get_organization_by_user(request.user)
|
||||||
|
|
||||||
|
query = self.request.query_params
|
||||||
description_name = ''
|
description_name = ''
|
||||||
|
|
||||||
if query.get('param') == 'assigned':
|
if query.get('param') == 'assigned':
|
||||||
@@ -103,9 +106,9 @@ class ProductExcelViewSet(viewsets.ModelViewSet):
|
|||||||
str(shamsi_date(convert_str_to_date(data['create_date']), in_value=True)) if data.get(
|
str(shamsi_date(convert_str_to_date(data['create_date']), in_value=True)) if data.get(
|
||||||
'create_date') else '',
|
'create_date') else '',
|
||||||
(data[
|
(data[
|
||||||
'assigner_organization'] or {}).get('organization') or '-',
|
'assigner_organization'] or {}).get('organization') or '-',
|
||||||
(data[
|
(data[
|
||||||
'assigned_organization'] or {}).get('organization') or '-',
|
'assigned_organization'] or {}).get('organization') or '-',
|
||||||
data.get('weight') or 0,
|
data.get('weight') or 0,
|
||||||
data.get('distributed') or 0,
|
data.get('distributed') or 0,
|
||||||
data.get('remaining_weight') or 0,
|
data.get('remaining_weight') or 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user