2025-09-28 10:36:58 +03:30
|
|
|
from django.db.models import Sum, functions, Value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RancherService:
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
2025-11-26 15:50:35 +03:30
|
|
|
def get_total_used_weight(rancher, sale_item, quota_stat):
|
2025-09-28 10:36:58 +03:30
|
|
|
return sale_item.objects.filter(
|
|
|
|
|
transaction__rancher=rancher,
|
2025-11-12 17:25:27 +03:30
|
|
|
transaction__transaction_status='success',
|
2025-11-26 15:50:35 +03:30
|
|
|
quota_stat=quota_stat,
|
2025-09-28 10:36:58 +03:30
|
|
|
).aggregate(
|
|
|
|
|
total_weight=functions.Coalesce(Sum('weight'), Value(0))
|
|
|
|
|
)['total_weight']
|