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,
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 5.0 on 2025-09-22 11:59
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('livestock', '0013_livestock_archive'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='livestockusetype',
|
||||
name='en_name',
|
||||
field=models.CharField(max_length=50, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='livestockusetype',
|
||||
name='name',
|
||||
field=models.CharField(max_length=50, null=True),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 5.0 on 2025-09-22 12:00
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('livestock', '0014_livestockusetype_en_name_alter_livestockusetype_name'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='livestocktype',
|
||||
name='en_name',
|
||||
field=models.CharField(max_length=50, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='livestocktype',
|
||||
name='name',
|
||||
field=models.CharField(max_length=50, null=True),
|
||||
),
|
||||
]
|
||||
@@ -17,7 +17,8 @@ class LiveStockSpecies(BaseModel): # noqa
|
||||
|
||||
class LiveStockType(BaseModel): # noqa
|
||||
""" types like sheep, cow, camel, etc """
|
||||
name = models.CharField(max_length=50)
|
||||
name = models.CharField(max_length=50, null=True)
|
||||
en_name = models.CharField(max_length=50, null=True)
|
||||
weight_types = (
|
||||
('L', 'Light'),
|
||||
('H', 'Heavy')
|
||||
@@ -37,7 +38,8 @@ class LiveStockType(BaseModel): # noqa
|
||||
|
||||
class LiveStockUseType(BaseModel):
|
||||
""" use types like Beef, Milky, etc """
|
||||
name = models.CharField(max_length=50)
|
||||
name = models.CharField(max_length=50, null=True)
|
||||
en_name = models.CharField(max_length=50, null=True)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.name}'
|
||||
|
||||
Reference in New Issue
Block a user