Merge remote-tracking branch 'origin' into development

This commit is contained in:
2025-11-16 16:29:07 +03:30
4 changed files with 34 additions and 5 deletions

View File

@@ -129,7 +129,7 @@ class Rancher(BaseModel):
)
without_herd = models.BooleanField(default=False)
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)

View File

@@ -4,10 +4,11 @@ from django.db.models import Sum, functions, Value
class RancherService:
@staticmethod
def get_total_used_weight(rancher, sale_item):
def get_total_used_weight(rancher, sale_item, distribution):
return sale_item.objects.filter(
transaction__rancher=rancher,
transaction__transaction_status='success'
transaction__transaction_status='success',
quota_distribution=distribution,
).aggregate(
total_weight=functions.Coalesce(Sum('weight'), Value(0))
)['total_weight']

View File

@@ -152,7 +152,7 @@ def rancher_quota_weight(
total_weight += rancher_plan_weight
print(total_weight)
# 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:
remaining_weight = 0