change list of rancher inventory entries to rancher distributions for one item be as sale in pos device

This commit is contained in:
2025-09-06 12:04:41 +03:30
parent 272e9ed2c8
commit 18a7955e3a
5 changed files with 151 additions and 50 deletions

View File

@@ -2,7 +2,7 @@ from decimal import Decimal
from apps.herd.models import Rancher
from apps.livestock.models import LiveStock
from apps.warehouse.models import InventoryEntry
from apps.product.models import Quota
from apps.product.models import Quota, QuotaDistribution
from django.db.models import Count, Q
import typing
@@ -26,10 +26,11 @@ def get_rancher_statistics(rancher: Rancher = None) -> typing.Any:
return stats
def rancher_quota_weight(rancher, inventory_entry: InventoryEntry):
def rancher_quota_weight(rancher, inventory_entry: InventoryEntry = None, distribution: QuotaDistribution = None):
"""
:param rancher: Rancher instance
:param inventory_entry: InventoryEntry instance
:param distribution: QuotaDistribution instance
:return: dict {total, by_type}
"""
@@ -41,7 +42,13 @@ def rancher_quota_weight(rancher, inventory_entry: InventoryEntry):
"اسب": "horse_count"
}
quota: Quota = inventory_entry.distribution.quota
if inventory_entry:
quota: Quota = inventory_entry.distribution.quota
elif distribution:
quota: Quota = distribution.quota
else:
quota: Quota = Quota()
# list of quota live stock allocations
allocations = list(quota.livestock_allocations.all().select_related('livestock_type'))
# list of quota incentive plans