change incentive plans total weight quota with rancher incentive plan - change id to rancher plan and add incentive plan id
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from apps.core.models import BaseModel
|
||||
from apps.authentication import models as auth_models
|
||||
from apps.core.models import BaseModel
|
||||
|
||||
from django.db import models
|
||||
|
||||
|
||||
@@ -136,5 +137,4 @@ class Rancher(BaseModel):
|
||||
return f'rancher: {self.first_name} {self.last_name}'
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
return super(Rancher, self).save(*args, **kwargs)
|
||||
|
||||
return super(Rancher, self).save(*args, **kwargs)
|
||||
@@ -58,7 +58,8 @@ def rancher_quota_weight(rancher, inventory_entry: InventoryEntry = None, distri
|
||||
total_weight = 0
|
||||
merged = {}
|
||||
|
||||
for item in allocations + incentive_plans: # noqa
|
||||
# calculate quota base weight by livestock type & base total weight
|
||||
for item in allocations: # noqa
|
||||
if item.livestock_type:
|
||||
animal_type_fa = item.livestock_type.name
|
||||
animal_type_en = item.livestock_type.en_name
|
||||
@@ -77,6 +78,19 @@ def rancher_quota_weight(rancher, inventory_entry: InventoryEntry = None, distri
|
||||
else:
|
||||
merged[animal_type_en]['weight'] += weight
|
||||
|
||||
# calculate rancher incentive plans weight by livestock type & add it to total_weight
|
||||
for item in incentive_plans:
|
||||
rancher_plans = item.incentive_plan.rancher_plans.select_related(
|
||||
'rancher',
|
||||
'livestock_type'
|
||||
).filter(rancher=rancher, livestock_type=item.livestock_type)
|
||||
if rancher_plans:
|
||||
# multiple count of rancher livestock on incentive plan &
|
||||
# incentive plan quantity by this livestock type
|
||||
rancher_plan_weight = rancher_plans.first().allowed_quantity * item.quantity_kg
|
||||
total_weight += rancher_plan_weight
|
||||
print(total_weight)
|
||||
|
||||
return {
|
||||
"total_weight": total_weight,
|
||||
"remaining_weight": 20,
|
||||
|
||||
Reference in New Issue
Block a user