change map structure of rancher quota weight satistics
This commit is contained in:
@@ -16,11 +16,11 @@ def get_rancher_statistics(rancher: Rancher = None) -> typing.Any:
|
||||
herd_count=Count("herd", distinct=True),
|
||||
light_count=Count('id', filter=Q(weight_type='L')),
|
||||
heavy_count=Count('id', filter=Q(weight_type='H')),
|
||||
sheep_count=Count('id', filter=Q(type__name='گوسفند')), # noqa
|
||||
goat_count=Count('id', filter=Q(type__name='بز')),
|
||||
cow_count=Count('id', filter=Q(type__name='گاو')),
|
||||
camel_count=Count('id', filter=Q(type__name='شتر')),
|
||||
horse_count=Count('id', filter=Q(type__name='بز')),
|
||||
sheep=Count('id', filter=Q(type__name='گوسفند')), # noqa
|
||||
goat=Count('id', filter=Q(type__name='بز')),
|
||||
cow=Count('id', filter=Q(type__name='گاو')),
|
||||
camel=Count('id', filter=Q(type__name='شتر')),
|
||||
horse=Count('id', filter=Q(type__name='بز')),
|
||||
)
|
||||
return [{'name': key, 'value': value} for key, value in stats.items()], stats
|
||||
|
||||
@@ -34,11 +34,11 @@ def rancher_quota_weight(rancher, inventory_entry: InventoryEntry = None, distri
|
||||
"""
|
||||
|
||||
live_stock_meta = {
|
||||
"گوسفند": "sheep_count", # noqa
|
||||
"بز": "goat_count",
|
||||
"گاو": "cow_count",
|
||||
"شتر": "camel_count",
|
||||
"اسب": "horse_count"
|
||||
"گوسفند": "sheep", # noqa
|
||||
"بز": "goat",
|
||||
"گاو": "cow",
|
||||
"شتر": "camel",
|
||||
"اسب": "horse"
|
||||
}
|
||||
|
||||
if inventory_entry:
|
||||
@@ -60,20 +60,21 @@ def rancher_quota_weight(rancher, inventory_entry: InventoryEntry = None, distri
|
||||
|
||||
for item in allocations + incentive_plans: # noqa
|
||||
if item.livestock_type:
|
||||
animal_type = item.livestock_type.name
|
||||
animal_type_fa = item.livestock_type.name
|
||||
animal_type_en = item.livestock_type.en_name
|
||||
per_head = item.quantity_kg
|
||||
count = livestock_counts_dict.get(live_stock_meta.get(animal_type), 0)
|
||||
count = livestock_counts_dict.get(live_stock_meta.get(animal_type_fa), 0)
|
||||
|
||||
weight = per_head * count
|
||||
total_weight += weight
|
||||
|
||||
if animal_type not in merged:
|
||||
merged[animal_type] = {
|
||||
if animal_type_en not in merged:
|
||||
merged[animal_type_en] = {
|
||||
"weight": weight,
|
||||
"type": item.livestock_type.weight_type
|
||||
}
|
||||
else:
|
||||
merged[animal_type]['weight'] += weight
|
||||
merged[animal_type_en]['weight'] += weight
|
||||
|
||||
return {
|
||||
"total_weight": total_weight,
|
||||
|
||||
Reference in New Issue
Block a user