|
@@ -160,9 +160,7 @@ class InvoiceDataView(APIView):
|
|
|
|
|
|
def get(self, request):
|
|
|
tenant = request.user.employee.tenant
|
|
|
- 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'))
|
|
|
+ pay = Pay.objects.filter(invoice__isnull=True,tenant=tenant,status__in=[Pay.PAY,Pay.PAY]).aggregate(amount=Sum('amount'))
|
|
|
data = {
|
|
|
'invoice_name': "",
|
|
|
'tax_no': "",
|
|
@@ -177,8 +175,8 @@ class InvoiceDataView(APIView):
|
|
|
}
|
|
|
try:
|
|
|
if not pay['amount']:
|
|
|
- return CustomError('未开具发票!')
|
|
|
- print(111111,)
|
|
|
+ raise CustomError('暂无发票可申请!')
|
|
|
+
|
|
|
invoice = Invoice.objects.filter(tenant=tenant).order_by('-id').first()
|
|
|
|
|
|
if invoice:
|
|
@@ -195,7 +193,9 @@ class InvoiceDataView(APIView):
|
|
|
'consignee_address': invoice.company_address,
|
|
|
}
|
|
|
else:
|
|
|
- data['invoice_sum']=pay['amount']
|
|
|
+ data['invoice_sum'] = pay['amount']
|
|
|
+ except CustomError as e:
|
|
|
+ return response_error(str(e))
|
|
|
except Exception as e:
|
|
|
return response_error(str(e))
|
|
|
return response_ok(data)
|
|
@@ -208,4 +208,4 @@ class InvoiceViewSet(CustomModelViewSet):
|
|
|
def filter_queryset(self, queryset):
|
|
|
queryset = queryset.filter(tenant=self.request.user.employee.tenant)
|
|
|
f = InvoiceFilter(self.request.GET, queryset=queryset)
|
|
|
- return f.qs
|
|
|
+ return f.qs
|