from django.shortcuts import render

from rest_framework.viewsets import ModelViewSet
from .models import Bill,Chargeitem
from utils.queryset import get_child_queryset2
from .serializers import BillSerializer,ChargeitemSerializer
from apps.system.permission_data import RbacFilterSet
from apps.system.mixins import CreateUpdateCustomMixin, OptimizationMixin
# Create your views here.

class BillViewSet(CreateUpdateCustomMixin, OptimizationMixin, ModelViewSet):
    perms_map = {'get': '*', 'post': 'Bill_create',
                 'put': 'Bill_update', 'delete': 'Bill_delete'}
    queryset = Bill.objects
    serializer_class = BillSerializer
    search_fields = ['feecode']
    ordering = ['-create_time']
    filterset_fields = ['number']
    ordering = ['-create_time']
    def paginate_queryset(self, queryset):
       
        if ((not self.request.query_params.get('page', None)) and (self.request.query_params.get('number', None))) or (self.paginator is None):
            return None
        return self.paginator.paginate_queryset(queryset, self.request, view=self)
class ChargeitemViewSet(CreateUpdateCustomMixin, OptimizationMixin, ModelViewSet):
    perms_map = {'get': '*', 'post': 'chargeitem_create',
                 'put': 'chargeitem_update', 'delete': 'chargeitem_delete'}
    queryset = Chargeitem.objects
    serializer_class = ChargeitemSerializer
    search_fields = ['itemkind']
    filterset_fields = ['bills']
    ordering = ['-create_time']
    def paginate_queryset(self, queryset):
       
        if ((not self.request.query_params.get('page', None)) and (self.request.query_params.get('bills', None))) or (self.paginator is None):
            return None
        return self.paginator.paginate_queryset(queryset, self.request, view=self)