|
@@ -4,14 +4,16 @@ import datetime
|
|
|
import time
|
|
|
from django.db import transaction
|
|
|
from django.conf import settings
|
|
|
+from django.db.models import Q,Sum
|
|
|
from rest_framework.decorators import action
|
|
|
from rest_framework_jwt.views import ObtainJSONWebToken,VerifyJSONWebToken,RefreshJSONWebToken
|
|
|
from rest_framework.serializers import ValidationError
|
|
|
+
|
|
|
from utils.custom_modelviewset import CustomModelViewSet
|
|
|
from utils import response_error, response_ok
|
|
|
from .serializers import TenantJWTSerializer
|
|
|
from utils.permission import IsTenantUser, IsAdministratorUser
|
|
|
-from .models import Tenant, Pay
|
|
|
+from .models import Tenant, Pay, Invoice
|
|
|
from apps.admin.tenant.serializers import TenantSerializer
|
|
|
from apps.admin.tenant.filters import TenantFilter
|
|
|
from apps.log.models import BizLog
|
|
@@ -19,7 +21,10 @@ from apps.tenant.config.models import Config
|
|
|
from utils.exceptions import CustomError
|
|
|
from apps.base import Formater
|
|
|
from apps.WechatApplet.models import WechatApplet
|
|
|
-from apps.tenant.serializers import PaySerializer
|
|
|
+from apps.tenant.serializers import PaySerializer,InvoiceSerializer
|
|
|
+from apps.tenant.filters import InvoiceFilter
|
|
|
+from rest_framework.views import APIView
|
|
|
+
|
|
|
|
|
|
class TenantLoginView(ObtainJSONWebToken):
|
|
|
serializer_class = TenantJWTSerializer
|
|
@@ -166,3 +171,47 @@ class CompanyViewSet(CustomModelViewSet):
|
|
|
payment = Pay.objects.filter(tenant_id=pk)
|
|
|
data = PaySerializer(payment, many=True).data
|
|
|
return response_ok(data)
|
|
|
+
|
|
|
+class InvoiceViewSet(CustomModelViewSet):
|
|
|
+ permission_classes = [IsTenantUser, ]
|
|
|
+ queryset = Invoice.objects.filter()
|
|
|
+ serializer_class = InvoiceSerializer
|
|
|
+
|
|
|
+ def filter_queryset(self, queryset):
|
|
|
+ queryset = queryset.filter(id=self.request.user.employee.tenant.id)
|
|
|
+ f = InvoiceFilter(self.request.GET, queryset=queryset)
|
|
|
+ print(f)
|
|
|
+ return f.qs
|
|
|
+
|
|
|
+class InvoiceDataView(APIView):
|
|
|
+ permission_classes = [IsTenantUser, ]
|
|
|
+
|
|
|
+ def get(self, request):
|
|
|
+ tenant = request.user.employee.tenant
|
|
|
+ invoice_id = request.GET.get('invoice_id')
|
|
|
+
|
|
|
+ pay = Pay.objects.filter(
|
|
|
+ Q(status=Pay.PAY, invoice_id=None,tenant=tenant) | Q(status=Pay.CONFIRM, invoice_id=None,tenant=tenant))\
|
|
|
+ .aggregate(amount=Sum('amount'))
|
|
|
+ print(22222, pay)
|
|
|
+ invoice = Invoice.objects.filter(invoice_id=invoice_id)
|
|
|
+ print(11111111111,invoice)
|
|
|
+ try:
|
|
|
+ if pay:
|
|
|
+ data = {
|
|
|
+ 'invoice_name': invoice['invoice_name'],
|
|
|
+ 'tax_no': invoice['tax_no'],
|
|
|
+ 'company_address': invoice['company_address'],
|
|
|
+ 'phone_no': invoice['phone_no'],
|
|
|
+ 'deposit_bank': invoice['deposit_bank'],
|
|
|
+ 'bank_account': invoice['bank_account'],
|
|
|
+ 'invoice_sum': pay['amount'],
|
|
|
+ 'consignee': invoice['consignee'],
|
|
|
+ 'consignee_tel': invoice['consignee_tel'],
|
|
|
+ 'consignee_address': invoice['company_address'],
|
|
|
+ }
|
|
|
+ else:
|
|
|
+ return CustomError('未开具发票!')
|
|
|
+ except Exception as e:
|
|
|
+ return response_error(str(e))
|
|
|
+ return response_ok(data)
|