change incentive plans total weight quota with rancher incentive plan - change id to rancher plan and add incentive plan id

This commit is contained in:
2025-09-25 12:16:49 +03:30
parent 10ff4de7ed
commit 8571ef0c68
6 changed files with 102 additions and 33 deletions

View File

@@ -1,5 +1,4 @@
from apps.authentication.models import OrganizationType, Organization
# from apps.warehouse.models import InventoryQuotaSaleItem
from django.contrib.postgres.fields import ArrayField
from simple_history.models import HistoricalRecords
from apps.authorization.models import UserRelations
@@ -9,7 +8,6 @@ from apps.herd.models import Rancher
from datetime import datetime
from django.db import models
import jdatetime
# import datetime
class LivestockGroup(models.TextChoices):
@@ -470,29 +468,45 @@ class QuotaStats(BaseModel):
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 QuotaUsage(BaseModel):
distribution = models.ForeignKey(
"QuotaDistribution",
on_delete=models.CASCADE,
related_name='usages',
null=True
)
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
)
incentive_plan = models.ForeignKey(
IncentivePlan,
null=True,
blank=True,
on_delete=models.SET_NULL
)
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)
usage_type_choices = (
('base', 'BASE'),
('incentive', 'INCENTIVE'),
)
usage_type = models.CharField(max_length=150, choices=usage_type_choices, null=True)
def __str__(self):
return f'rancher: {self.rancher.ranching_farm} - plan: {self.incentive_plan.name}'
def save(self, *args, **kwargs):
return super(QuotaUsage, self).save(*args, **kwargs)
class QuotaIncentiveAssignment(BaseModel):