diff --git a/apps/herd/services/services.py b/apps/herd/services/services.py index c66e61a..9230e00 100644 --- a/apps/herd/services/services.py +++ b/apps/herd/services/services.py @@ -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, diff --git a/apps/livestock/migrations/0014_livestockusetype_en_name_alter_livestockusetype_name.py b/apps/livestock/migrations/0014_livestockusetype_en_name_alter_livestockusetype_name.py new file mode 100644 index 0000000..97ae348 --- /dev/null +++ b/apps/livestock/migrations/0014_livestockusetype_en_name_alter_livestockusetype_name.py @@ -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), + ), + ] diff --git a/apps/livestock/migrations/0015_livestocktype_en_name_alter_livestocktype_name.py b/apps/livestock/migrations/0015_livestocktype_en_name_alter_livestocktype_name.py new file mode 100644 index 0000000..5e021b8 --- /dev/null +++ b/apps/livestock/migrations/0015_livestocktype_en_name_alter_livestocktype_name.py @@ -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), + ), + ] diff --git a/apps/livestock/models.py b/apps/livestock/models.py index b649009..a8e6a1b 100644 --- a/apps/livestock/models.py +++ b/apps/livestock/models.py @@ -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}'