import - rancher dashboard by quota
This commit is contained in:
@@ -5,6 +5,7 @@ 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
|
||||
from apps.warehouse.services.services import can_buy_from_inventory
|
||||
|
||||
|
||||
class RancherDashboardService:
|
||||
@@ -78,19 +79,17 @@ 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',
|
||||
).distinct('quota_stat').values_list('quota_stat')
|
||||
|
||||
# get organization quota stats of transaction item
|
||||
quota_stat = OrganizationQuotaStats.objects.filter(id__in=transaction_sale_items)
|
||||
quota_stat = OrganizationQuotaStats.objects.filter(stat_type='quota', quota__is_closed=False)
|
||||
|
||||
available_stats = [
|
||||
stat for stat in quota_stat if (
|
||||
can_buy_from_inventory(rancher, quota_stat=stat) and rancher is not None
|
||||
)
|
||||
]
|
||||
|
||||
rancher_data_by_quota_usage = []
|
||||
for stat in quota_stat:
|
||||
for stat in available_stats:
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user