Merge remote-tracking branch 'origin' into development
This commit is contained in:
@@ -129,7 +129,7 @@ class Rancher(BaseModel):
|
|||||||
)
|
)
|
||||||
without_herd = models.BooleanField(default=False)
|
without_herd = models.BooleanField(default=False)
|
||||||
ignore_purchase_limit = models.BooleanField(
|
ignore_purchase_limit = models.BooleanField(
|
||||||
default=False, help_text="if its true rancher has not buy limitations"
|
default=True, help_text="if its true rancher has not buy limitations"
|
||||||
)
|
)
|
||||||
dhi_state = models.BooleanField(default=False)
|
dhi_state = models.BooleanField(default=False)
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,11 @@ from django.db.models import Sum, functions, Value
|
|||||||
class RancherService:
|
class RancherService:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_total_used_weight(rancher, sale_item):
|
def get_total_used_weight(rancher, sale_item, distribution):
|
||||||
return sale_item.objects.filter(
|
return sale_item.objects.filter(
|
||||||
transaction__rancher=rancher,
|
transaction__rancher=rancher,
|
||||||
transaction__transaction_status='success'
|
transaction__transaction_status='success',
|
||||||
|
quota_distribution=distribution,
|
||||||
).aggregate(
|
).aggregate(
|
||||||
total_weight=functions.Coalesce(Sum('weight'), Value(0))
|
total_weight=functions.Coalesce(Sum('weight'), Value(0))
|
||||||
)['total_weight']
|
)['total_weight']
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ def rancher_quota_weight(
|
|||||||
total_weight += rancher_plan_weight
|
total_weight += rancher_plan_weight
|
||||||
print(total_weight)
|
print(total_weight)
|
||||||
# get rancher remaining usage of quota for purchase
|
# get rancher remaining usage of quota for purchase
|
||||||
rancher_remaining_usage = RancherService.get_total_used_weight(rancher, InventoryQuotaSaleItem)
|
rancher_remaining_usage = RancherService.get_total_used_weight(rancher, InventoryQuotaSaleItem, distribution)
|
||||||
|
|
||||||
if total_weight - rancher_remaining_usage < 0:
|
if total_weight - rancher_remaining_usage < 0:
|
||||||
remaining_weight = 0
|
remaining_weight = 0
|
||||||
|
|||||||
@@ -145,8 +145,36 @@ class InventoryQuotaSaleTransactionViewSet(BaseViewSet, SoftDeleteMixin, Dynamic
|
|||||||
"""
|
"""
|
||||||
list of transactions
|
list of transactions
|
||||||
filter by: search, all, my_transactions
|
filter by: search, all, my_transactions
|
||||||
|
filter by: transaction status
|
||||||
"""
|
"""
|
||||||
queryset = self.filter_query(self.get_queryset(visibility_by_org_scope=True).order_by('-create_date'))
|
if 'status' in request.GET.keys():
|
||||||
|
status_param = self.request.query_params.get('status') # noqa
|
||||||
|
|
||||||
|
if status_param == 'waiting':
|
||||||
|
queryset = self.get_queryset(
|
||||||
|
visibility_by_org_scope=True
|
||||||
|
).filter(transaction_status='waiting').order_by('-create_date')
|
||||||
|
|
||||||
|
elif status_param == 'success':
|
||||||
|
queryset = self.get_queryset(
|
||||||
|
visibility_by_org_scope=True
|
||||||
|
).filter(transaction_status='success').order_by('-create_date')
|
||||||
|
|
||||||
|
elif status_param == 'failed':
|
||||||
|
queryset = self.get_queryset(
|
||||||
|
visibility_by_org_scope=True
|
||||||
|
).filter(transaction_status='failed').order_by('-create_date')
|
||||||
|
|
||||||
|
else:
|
||||||
|
queryset = self.get_queryset(
|
||||||
|
visibility_by_org_scope=True
|
||||||
|
).order_by('-create_date')
|
||||||
|
else:
|
||||||
|
queryset = self.get_queryset(
|
||||||
|
visibility_by_org_scope=True
|
||||||
|
).order_by('-create_date')
|
||||||
|
|
||||||
|
queryset = self.filter_query(queryset)
|
||||||
|
|
||||||
# paginate & response
|
# paginate & response
|
||||||
page = self.paginate_queryset(queryset)
|
page = self.paginate_queryset(queryset)
|
||||||
|
|||||||
Reference in New Issue
Block a user