From 10ff4de7ed37063bfc7d5417a26d3ccee40bb9fa Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Wed, 24 Sep 2025 15:00:10 +0330 Subject: [PATCH] add incentive plan id to rancher distribution info --- apps/product/models.py | 40 +++++++++++++++++++++++++------ apps/product/services/services.py | 1 + 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/apps/product/models.py b/apps/product/models.py index be67750..ae84f8c 100644 --- a/apps/product/models.py +++ b/apps/product/models.py @@ -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.warehouse.models import InventoryQuotaSaleItem 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.core.models import BaseModel from apps.herd.models import Rancher from datetime import datetime +from django.db import models import jdatetime +# import datetime class LivestockGroup(models.TextChoices): @@ -334,10 +335,10 @@ class IncentivePlanRancher(BaseModel): ) 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) @@ -469,6 +470,31 @@ 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 QuotaIncentiveAssignment(BaseModel): """ assign incentive plan to quota """ diff --git a/apps/product/services/services.py b/apps/product/services/services.py index d6832f6..4c7cdd9 100644 --- a/apps/product/services/services.py +++ b/apps/product/services/services.py @@ -47,6 +47,7 @@ def quota_incentive_plans_info(quota: Quota, rancher: Rancher) -> typing.Any: ).filter(rancher=rancher, livestock_type=plan.livestock_type) incentive_plans_data = { + 'id': plan.incentive_plan.id, 'name': plan.incentive_plan.name, 'livestock_type': plan.livestock_type.name if plan.livestock_type else "", 'livestock_type_en': plan.livestock_type.en_name if plan.livestock_type else "",