fix - national code search in transaction
This commit is contained in:
@@ -7,7 +7,7 @@ ENV_NAME=DEV
|
|||||||
# Database secrets
|
# Database secrets
|
||||||
DB_HOST=31.7.78.133
|
DB_HOST=31.7.78.133
|
||||||
DB_PORT=14352
|
DB_PORT=14352
|
||||||
DB_NAME=Production
|
DB_NAME=Development
|
||||||
DB_USERNAME=postgres
|
DB_USERNAME=postgres
|
||||||
DB_PASSWORD=pfLIVXupbDetvFMt2gUvxLXUL9b4HIOHaPcKXsBEZ1i8zl0iLUjmhUfXlGfJKcTV
|
DB_PASSWORD=pfLIVXupbDetvFMt2gUvxLXUL9b4HIOHaPcKXsBEZ1i8zl0iLUjmhUfXlGfJKcTV
|
||||||
|
|
||||||
|
|||||||
47
apps/herd/services/rancher_dashboard_service.py
Normal file
47
apps/herd/services/rancher_dashboard_service.py
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
from django.db import models
|
||||||
|
from django.db.models import Count, Sum
|
||||||
|
|
||||||
|
from apps.herd.models import Rancher, Herd
|
||||||
|
from apps.livestock.models import LiveStock
|
||||||
|
|
||||||
|
|
||||||
|
class FarmerDashboardService:
|
||||||
|
""" Dashboard aggregation service for Rancher """
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_basic_info(rancher: Rancher):
|
||||||
|
return {
|
||||||
|
"id": rancher.id,
|
||||||
|
"name": f"{rancher.first_name} {rancher.last_name}",
|
||||||
|
"mobile": rancher.mobile,
|
||||||
|
"national_code": rancher.national_code,
|
||||||
|
"province": rancher.province.name if rancher.province else None,
|
||||||
|
"city": rancher.city.name if rancher.city else None,
|
||||||
|
}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_herd_counts(rancher_id):
|
||||||
|
return Herd.objects.filter(rancher_id=rancher_id).aggregate(
|
||||||
|
total_herds=Count('id'),
|
||||||
|
total_heavy=Sum('heavy_livestock_number'),
|
||||||
|
total_light=Sum('light_livestock_number'),
|
||||||
|
)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_livestock_counts(rancher_id):
|
||||||
|
return LiveStock.objects.filter(herd__rancher_id=rancher_id, archive=False).aggregate(
|
||||||
|
total=Count('id'),
|
||||||
|
heavy=Count('id', filter=models.Q(weight_type='H')),
|
||||||
|
light=Count('id', filter=models.Q(weight_type='L')),
|
||||||
|
)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_livestock_by_type(rancher_id):
|
||||||
|
return (
|
||||||
|
LiveStock.objects.filter(herd__rancher_id=rancher_id, archive=False)
|
||||||
|
.values("type__name")
|
||||||
|
.annotate(count=Count("id"))
|
||||||
|
)
|
||||||
|
|
||||||
|
# @staticmethod
|
||||||
|
# def get_dashboard(rancher_id):
|
||||||
@@ -176,6 +176,7 @@ class InventoryQuotaSaleTransactionViewSet(
|
|||||||
'quota_distribution__distribution_id', 'weight', 'delivery_address', 'transaction_price',
|
'quota_distribution__distribution_id', 'weight', 'delivery_address', 'transaction_price',
|
||||||
'price_paid', 'price_type', 'product_type', 'transactions_number', 'transaction_status',
|
'price_paid', 'price_type', 'product_type', 'transactions_number', 'transaction_status',
|
||||||
'transaction_status_code', 'ref_num', 'terminal', 'payer_cart', 'transaction_date',
|
'transaction_status_code', 'ref_num', 'terminal', 'payer_cart', 'transaction_date',
|
||||||
|
'transaction__rancher__national_code'
|
||||||
]
|
]
|
||||||
|
|
||||||
def list(self, request, *args, **kwargs):
|
def list(self, request, *args, **kwargs):
|
||||||
|
|||||||
Reference in New Issue
Block a user