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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user