rancher quota statistics including livestock allocations & incentive plan assignments

This commit is contained in:
2025-08-30 16:09:37 +03:30
parent 8015d9a954
commit 9d9d4d3b80
4 changed files with 75 additions and 17 deletions

View File

@@ -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)