diff --git a/apps/herd/services/rancher_dashboard_service.py b/apps/herd/services/rancher_dashboard_service.py index ae440d0..6a13745 100644 --- a/apps/herd/services/rancher_dashboard_service.py +++ b/apps/herd/services/rancher_dashboard_service.py @@ -2,6 +2,8 @@ from django.db.models import Sum, Count, Q from django.db.models.functions import Coalesce from apps.herd.models import Rancher, Herd +from apps.herd.services.services import rancher_quota_weight +from apps.product.models import OrganizationQuotaStats from apps.warehouse.models import InventoryQuotaSaleItem @@ -76,13 +78,21 @@ class RancherDashboardService: get rancher dashboard by quota usage """ + # get rancher transaction items transaction_sale_items = InventoryQuotaSaleItem.objects.select_related( 'transaction', 'quota_stat' ).filter( transaction__rancher=rancher, - transaction__transaction_status='success', - ).values('quota_stat') + # transaction__transaction_status='success', + ).distinct('quota_stat').values_list('quota_stat') - print(list(set(transaction_sale_items))) + # get organization quota stats of transaction item + quota_stat = OrganizationQuotaStats.objects.filter(id__in=transaction_sale_items) - return {} + rancher_data_by_quota_usage = [] + for stat in quota_stat: + rancher_quota_data = rancher_quota_weight(rancher=rancher, quota=stat.quota, quota_stat=stat) + rancher_quota_data.update({'product': stat.quota.product.name}) + rancher_data_by_quota_usage.append(rancher_quota_data) + + return rancher_data_by_quota_usage