forked from erp-dev/erp
feat: balance api
This commit is contained in:
4
api_v1/views/business/balance/__init__.py
Normal file
4
api_v1/views/business/balance/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
"""
|
||||
余额相关 API 视图。
|
||||
"""
|
||||
|
||||
36
api_v1/views/business/balance/views.py
Normal file
36
api_v1/views/business/balance/views.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from decimal import Decimal
|
||||
|
||||
from rest_framework import views
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
|
||||
from basic_info import models as basic_models
|
||||
from business import services as business_services
|
||||
from api_v1.views.stock_change_views.mixins import StockChangeViewMixin
|
||||
|
||||
|
||||
class CustomerBalanceView(StockChangeViewMixin, views.APIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def get(self, request, customer_id: int):
|
||||
if not self.check_employee_permission(request):
|
||||
return self.permission_error_response('无权限访问')
|
||||
|
||||
merchant = request.user.employee.merchant
|
||||
try:
|
||||
customer = basic_models.Customer.objects.get(id=customer_id, merchant=merchant)
|
||||
except basic_models.Customer.DoesNotExist:
|
||||
return self.not_found_response('客户不存在')
|
||||
|
||||
balance: Decimal = business_services.BalanceService.get_customer_balance(
|
||||
merchant=merchant,
|
||||
customer=customer,
|
||||
)
|
||||
return Response(
|
||||
{
|
||||
'customer': customer.id,
|
||||
'customer_name': customer.name,
|
||||
'balance': str(balance),
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user