rancher service & quota usage service

This commit is contained in:
2025-09-28 10:36:58 +03:30
parent 973d1319da
commit e9caad0dbf
4 changed files with 91 additions and 49 deletions

View File

@@ -1,8 +1,13 @@
from decimal import Decimal
from apps.herd.models import Rancher
from apps.livestock.models import LiveStock
from apps.warehouse.models import InventoryEntry
from apps.warehouse.models import (
InventoryEntry,
InventoryQuotaSaleItem
)
from django.db.models import Sum
from apps.product.models import Quota, QuotaDistribution
from apps.herd.services.rancher_service import RancherService
from django.db.models import Count, Q
import typing
@@ -89,11 +94,13 @@ def rancher_quota_weight(rancher, inventory_entry: InventoryEntry = None, distri
# incentive plan quantity by this livestock type
rancher_plan_weight = rancher_plans.first().allowed_quantity * item.quantity_kg
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)
return {
"total_weight": total_weight,
"remaining_weight": 20,
"remaining_weight": total_weight - rancher_remaining_usage,
"by_type": [{
"name": key,
"name_fa": value['name_fa'],