rancher quota statistics including livestock allocations & incentive plan assignments
This commit is contained in:
@@ -457,10 +457,31 @@ class QuotaIncentiveAssignment(BaseModel):
|
||||
)
|
||||
quantity_kg = models.PositiveBigIntegerField(default=0)
|
||||
|
||||
def calculate_heavy_value(self):
|
||||
""" calculate total livestock heavy value of incentive plans """
|
||||
heavy_weight = QuotaIncentiveAssignment.objects.filter(
|
||||
quota=self.quota, livestock_type__weight_type='H'
|
||||
).aggregate(total=models.Sum('quantity_kg'))['total'] or 0
|
||||
|
||||
self.heavy_value = heavy_weight
|
||||
self.save()
|
||||
|
||||
def calculate_light_value(self):
|
||||
""" calculate total livestock light value of incentive plans """
|
||||
|
||||
heavy_weight = QuotaIncentiveAssignment.objects.filter(
|
||||
quota=self.quota, livestock_type__weight_type='L'
|
||||
).aggregate(total=models.Sum('quantity_kg'))['total'] or 0
|
||||
|
||||
self.heavy_value = heavy_weight
|
||||
self.save()
|
||||
|
||||
def __str__(self):
|
||||
return f"Quota ({self.quota.id}) for {self.incentive_plan.name}"
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.calculate_heavy_value()
|
||||
self.calculate_heavy_value()
|
||||
return super(QuotaIncentiveAssignment, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
|
||||
@@ -41,7 +41,10 @@ def quota_incentive_plans_info(quota: Quota) -> typing.Any:
|
||||
incentive_plans_list = [{
|
||||
'name': plan.incentive_plan.name,
|
||||
'heavy_value': plan.heavy_value,
|
||||
'light_value': plan.light_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]
|
||||
|
||||
return incentive_plans_list
|
||||
|
||||
Reference in New Issue
Block a user