add incentive plan id to rancher distribution info

This commit is contained in:
2025-09-24 15:00:10 +03:30
parent 69daf8d5ef
commit 10ff4de7ed
2 changed files with 34 additions and 7 deletions

View File

@@ -1,14 +1,15 @@
import datetime
from simple_history.models import HistoricalRecords
from django.db import models
from apps.core.models import BaseModel
from apps.authorization.models import UserRelations
from apps.authentication.models import OrganizationType, Organization from apps.authentication.models import OrganizationType, Organization
# from apps.warehouse.models import InventoryQuotaSaleItem
from django.contrib.postgres.fields import ArrayField from django.contrib.postgres.fields import ArrayField
from simple_history.models import HistoricalRecords
from apps.authorization.models import UserRelations
from apps.livestock.models import LiveStockType from apps.livestock.models import LiveStockType
from apps.core.models import BaseModel
from apps.herd.models import Rancher from apps.herd.models import Rancher
from datetime import datetime from datetime import datetime
from django.db import models
import jdatetime import jdatetime
# import datetime
class LivestockGroup(models.TextChoices): class LivestockGroup(models.TextChoices):
@@ -334,10 +335,10 @@ class IncentivePlanRancher(BaseModel):
) )
allowed_quantity = models.PositiveBigIntegerField(default=0) allowed_quantity = models.PositiveBigIntegerField(default=0)
used_quantity = models.PositiveBigIntegerField(default=0) used_quantity = models.PositiveBigIntegerField(default=0)
def __str__(self): def __str__(self):
return f'{self.plan.name}-{self.rancher.first_name}-{self.livestock_type.name}' return f'{self.plan.name}-{self.rancher.first_name}-{self.livestock_type.name}'
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
return super(IncentivePlanRancher, self).save(*args, **kwargs) return super(IncentivePlanRancher, self).save(*args, **kwargs)
@@ -469,6 +470,31 @@ class QuotaStats(BaseModel):
return super(QuotaStats, self).save(*args, **kwargs) return super(QuotaStats, self).save(*args, **kwargs)
# class RancherQuotaUsage(BaseModel):
# # transaction = models.ForeignKey("InventoryQuotaSaleTransaction", on_delete=models.CASCADE)
# rancher = models.ForeignKey(
# Rancher,
# on_delete=models.CASCADE,
# related_name='usages',
# null=True
# )
# livestock_type = models.ForeignKey(
# "LiveStockType",
# on_delete=models.CASCADE,
# related_name='usages',
# null=True
# )
# count = models.PositiveIntegerField() # چند رأس دام از این نوع
# base_quota_used = models.DecimalField(max_digits=12, decimal_places=2, default=0)
# incentive_quota_used = models.DecimalField(max_digits=12, decimal_places=2, default=0)
# incentive_plan = models.ForeignKey(
# "IncentivePlan",
# null=True,
# blank=True,
# on_delete=models.SET_NULL
# )
class QuotaIncentiveAssignment(BaseModel): class QuotaIncentiveAssignment(BaseModel):
""" assign incentive plan to quota """ """ assign incentive plan to quota """

View File

@@ -47,6 +47,7 @@ def quota_incentive_plans_info(quota: Quota, rancher: Rancher) -> typing.Any:
).filter(rancher=rancher, livestock_type=plan.livestock_type) ).filter(rancher=rancher, livestock_type=plan.livestock_type)
incentive_plans_data = { incentive_plans_data = {
'id': plan.incentive_plan.id,
'name': plan.incentive_plan.name, 'name': plan.incentive_plan.name,
'livestock_type': plan.livestock_type.name if plan.livestock_type else "", 'livestock_type': plan.livestock_type.name if plan.livestock_type else "",
'livestock_type_en': plan.livestock_type.en_name if plan.livestock_type else "", 'livestock_type_en': plan.livestock_type.en_name if plan.livestock_type else "",