Browse Source

优化首页结算代码

linhaohong 1 year ago
parent
commit
b86558748b
1 changed files with 5 additions and 10 deletions
  1. 5 10
      AdminController/CloudServiceManage/AgentCustomerController.py

+ 5 - 10
AdminController/CloudServiceManage/AgentCustomerController.py

@@ -730,7 +730,6 @@ class AgentCustomerView(View):
             agent_device_qs = AgentDevice.objects.filter()
         else:
             ac_id = agent_customer_info.id
-            print(ac_id)
             agent_device_orders_qs = AgentDeviceOrder.objects.filter(ac_id=ac_id, is_del=False)
             agent_device_qs = AgentDevice.objects.filter(ac_id=ac_id)
 
@@ -741,15 +740,11 @@ class AgentCustomerView(View):
 
         try:
             # 计算AgentDeviceOrderInstallment表 结算金额
-            partial_settled_profit = 0
-            for agent_device_order in agent_device_orders_qs:
-                ado_id = agent_device_order.id
-                settled_profit = \
-                    AgentDeviceOrderInstallment.objects.filter(ado_id=ado_id, status=2).aggregate(Sum('amount'))[
-                        'amount__sum'] or 0
-                partial_settled_profit = partial_settled_profit + settled_profit
-
-            print(partial_settled_profit)
+            partial_settled_profit = AgentDeviceOrderInstallment.objects.filter(
+                ado_id__in=agent_device_orders_qs.filter(status=1).values_list('id', flat=True),
+                status=2
+            ).aggregate(total=Sum('amount'))['total'] or 0
+
             # 总利润
             total_profit_all = \
                 agent_device_orders_qs.filter(status__in=[1, 2], is_del=False).aggregate(