Merge remote-tracking branch 'origin' into development

This commit is contained in:
2025-11-11 12:36:11 +03:30
3 changed files with 35 additions and 8 deletions

View File

@@ -14,9 +14,9 @@ from apps.warehouse.models import (
)
LIVESTOCK_GROPES = {
'I': 'industrial', # صنعتی
'V': 'rural', # روستایی
'N': 'nomadic' # عشایری
'industrial': 'I', # صنعتی
'rural': 'V', # روستایی
'nomadic': 'N' # عشایری
}
@@ -54,6 +54,30 @@ def get_rancher_statistics(rancher: Rancher = None) -> typing.Any:
return [{'name': key, 'value': value} for key, value in stats.items()], stats
def get_rancher_statistic_by_herd(rancher: Rancher = None) -> typing.Any:
""" get statistics of a rancher by his herds """ # noqa
herds = rancher.herd.all()
if herds.exists():
stats = herds.aggregate(
herd_count=Count("id", distinct=True),
light_count=Sum('light_livestock_number'),
heavy_count=Sum('heavy_livestock_number'),
sheep=Sum('light_livestock_number'), # noqa
cow=Sum('heavy_livestock_number'),
)
else:
stats = {
'herd_count': 0,
'light_count': 0,
'heavy_count': 0,
'sheep': 0,
'cow': 0,
}
return [{'name': key, 'value': value} for key, value in stats.items()], stats
def rancher_quota_weight(
rancher: Rancher,
inventory_entry: InventoryEntry = None,
@@ -85,8 +109,11 @@ def rancher_quota_weight(
allocations = list(quota.livestock_allocations.all().select_related('livestock_type'))
# list of quota incentive plans
incentive_plans = list(quota.incentive_assignments.all().select_related('livestock_type'))
# list of rancher herds
herds = rancher.herd.all()
herd_livestock_gropes = [herd.activity for herd in herds]
livestock_counts_list, livestock_counts_dict = get_rancher_statistics(rancher)
livestock_counts_list, livestock_counts_dict = get_rancher_statistic_by_herd(rancher)
total_weight = 0
merged = {}
@@ -94,7 +121,7 @@ def rancher_quota_weight(
# calculate quota base weight by livestock type & base total weight
for item in allocations: # noqa
if item.livestock_type:
if rancher.activity and LIVESTOCK_GROPES[rancher.activity] == item.livestock_group:
if LIVESTOCK_GROPES[item.livestock_group] in herd_livestock_gropes:
animal_type_fa = item.livestock_type.name
animal_type_en = item.livestock_type.en_name
per_head = item.quantity_kg

View File

@@ -8,6 +8,7 @@ from rest_framework.response import Response
from apps.core.mixins.search_mixin import DynamicSearchMixin
from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin
from apps.core.models import Wage
from apps.pos_device import models as pos_models
from apps.pos_device.mixins.pos_device_mixin import POSDeviceMixin
from apps.product import models as product_models
@@ -106,7 +107,7 @@ class POSFreeProductsViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSear
request.data.update({
'organization': organization.id,
'device': device.id,
'company_fee': product_models.Broker.objects.get(organization=organization).company_fee,
'company_fee': Wage.get(key='MNPC'), # noqa
})
serializer = product_serializers.POSFreeProductSerializer(data=request.data, context={'device': device})

View File

@@ -147,8 +147,7 @@ class InventoryQuotaSaleTransactionViewSet(BaseViewSet, SoftDeleteMixin, Dynamic
list of transactions
filter by: search, all, my_transactions
"""
print("ssss")
queryset = self.filter_query(self.get_queryset(visibility_by_org_scope=True))
queryset = self.filter_query(self.get_queryset(visibility_by_org_scope=True).order_by('-create_date'))
# paginate & response
page = self.paginate_queryset(queryset)