create rancher incentive plan structure - add pos device main sheba
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from apps.product.models import Quota, QuotaLivestockAllocation
|
||||
from apps.warehouse.models import InventoryEntry
|
||||
from apps.herd.models import Rancher
|
||||
import typing
|
||||
|
||||
|
||||
@@ -32,20 +33,31 @@ def quota_live_stock_allocation_info(quota: Quota) -> typing.Any:
|
||||
return allocations_list
|
||||
|
||||
|
||||
def quota_incentive_plans_info(quota: Quota) -> typing.Any:
|
||||
def quota_incentive_plans_info(quota: Quota, rancher: Rancher) -> typing.Any:
|
||||
""" information of quota incentive plans """
|
||||
|
||||
incentive_plans = quota.incentive_assignments.select_related("livestock_type", "incentive_plan")
|
||||
|
||||
if incentive_plans:
|
||||
incentive_plans_list = [{
|
||||
'name': plan.incentive_plan.name,
|
||||
'heavy_value': plan.heavy_value,
|
||||
'light_value': plan.light_value,
|
||||
'livestock_type': plan.livestock_type.name if plan.livestock_type else "",
|
||||
'livestock_weight_type': plan.livestock_type.weight_type if plan.livestock_type else "",
|
||||
'quantity_kg': plan.quantity_kg
|
||||
} for plan in incentive_plans]
|
||||
incentive_plans_list = []
|
||||
for plan in incentive_plans:
|
||||
rancher_plan = plan.incentive_plan.rancher_plans.select_related(
|
||||
'rancher',
|
||||
'livestock_type'
|
||||
).filter(rancher=rancher, livestock_type=plan.livestock_type)
|
||||
|
||||
incentive_plans_data = {
|
||||
'name': plan.incentive_plan.name,
|
||||
'heavy_value': plan.heavy_value,
|
||||
'light_value': plan.light_value,
|
||||
'livestock_type': plan.livestock_type.name if plan.livestock_type else "",
|
||||
'livestock_weight_type': plan.livestock_type.weight_type if plan.livestock_type else "",
|
||||
'quantity_kg': plan.quantity_kg,
|
||||
'rancher_plan_statistic': {
|
||||
f'{rancher_plan.first().livestock_type.en_name}': rancher_plan.first().allowed_quantity
|
||||
} if rancher_plan else {}
|
||||
}
|
||||
incentive_plans_list.append(incentive_plans_data)
|
||||
|
||||
return incentive_plans_list
|
||||
|
||||
|
||||
Reference in New Issue
Block a user