rancher incentive plan

This commit is contained in:
2025-09-23 15:46:05 +03:30
parent 607a59a900
commit 73111950b4
5 changed files with 92 additions and 9 deletions

View File

@@ -6,6 +6,7 @@ from apps.authorization.models import UserRelations
from apps.authentication.models import OrganizationType, Organization
from django.contrib.postgres.fields import ArrayField
from apps.livestock.models import LiveStockType
from apps.herd.models import Rancher
from datetime import datetime
import jdatetime
@@ -312,6 +313,35 @@ class IncentivePlan(BaseModel):
return super(IncentivePlan, self).save(*args, **kwargs)
class IncentivePlanRancher(BaseModel):
plan = models.ForeignKey(
IncentivePlan,
on_delete=models.CASCADE,
related_name='rancher_plans',
null=True
)
rancher = models.ForeignKey(
Rancher,
on_delete=models.CASCADE,
related_name='plans',
null=True
)
livestock_type = models.ForeignKey(
LiveStockType,
on_delete=models.CASCADE,
related_name='rancher_plans',
null=True
)
allowed_quantity = models.PositiveBigIntegerField(default=0)
used_quantity = models.PositiveBigIntegerField(default=0)
def __str__(self):
return f'{self.plan.name}-{self.rancher.first_name}-{self.livestock_type.name}'
def save(self, *args, **kwargs):
return super(IncentivePlanRancher, self).save(*args, **kwargs)
class Quota(BaseModel):
""" quota for product with some conditions """
@@ -428,7 +458,7 @@ class QuotaStats(BaseModel):
def __str__(self):
return f'Quota: {self.quota.quota_id} stats'
def save(self, *args, **kwargs):
return super(QuotaStats, self).save(*args, **kwargs)