fix - import stat type in orgquotastat
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.0 on 2025-11-17 07:32
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('herd', '0019_alter_rancher_union_code_alter_rancher_union_name'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='rancher',
|
||||||
|
name='ignore_purchase_limit',
|
||||||
|
field=models.BooleanField(default=True, help_text='if its true rancher has not buy limitations'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.0 on 2025-11-17 07:32
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('product', '0094_organizationquotastats_remaining_amount_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='organizationquotastats',
|
||||||
|
name='stat_type',
|
||||||
|
field=models.CharField(choices=[('distribution', 'DISTRIBUTION'), ('quota', 'QUOTA')], default='distribution', max_length=150),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -817,6 +817,10 @@ class OrganizationQuotaStats(BaseModel):
|
|||||||
total_distributed = models.PositiveBigIntegerField(default=0)
|
total_distributed = models.PositiveBigIntegerField(default=0)
|
||||||
sold_amount = models.PositiveBigIntegerField(default=0)
|
sold_amount = models.PositiveBigIntegerField(default=0)
|
||||||
remaining_amount = models.PositiveBigIntegerField(default=0) # total - sold
|
remaining_amount = models.PositiveBigIntegerField(default=0) # total - sold
|
||||||
|
stat_type = models.CharField(max_length=150, choices=(
|
||||||
|
('distribution', 'DISTRIBUTION'),
|
||||||
|
('quota', 'QUOTA'),
|
||||||
|
), default='distribution')
|
||||||
|
|
||||||
def update_amount(self, main_quota=None):
|
def update_amount(self, main_quota=None):
|
||||||
""" calculate total/sold/remaining """
|
""" calculate total/sold/remaining """
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ class QuotaStatsService:
|
|||||||
# ================ origin ================
|
# ================ origin ================
|
||||||
assigner_stat, _ = OrganizationQuotaStats.objects.get_or_create(
|
assigner_stat, _ = OrganizationQuotaStats.objects.get_or_create(
|
||||||
organization=assigner,
|
organization=assigner,
|
||||||
quota=quota
|
quota=quota,
|
||||||
|
stat_type='distribution'
|
||||||
)
|
)
|
||||||
|
|
||||||
assigner_stat.remaining_amount -= distribution.weight
|
assigner_stat.remaining_amount -= distribution.weight
|
||||||
@@ -24,7 +25,8 @@ class QuotaStatsService:
|
|||||||
# ============== destination ================
|
# ============== destination ================
|
||||||
assigned_stat, _ = OrganizationQuotaStats.objects.get_or_create(
|
assigned_stat, _ = OrganizationQuotaStats.objects.get_or_create(
|
||||||
organization=assigned,
|
organization=assigned,
|
||||||
quota=quota
|
quota=quota,
|
||||||
|
stat_type='distribution'
|
||||||
)
|
)
|
||||||
|
|
||||||
assigned_stat.total_amount += distribution.weight
|
assigned_stat.total_amount += distribution.weight
|
||||||
@@ -51,15 +53,16 @@ class QuotaStatsService:
|
|||||||
organization=assigned,
|
organization=assigned,
|
||||||
quota=quota
|
quota=quota
|
||||||
)
|
)
|
||||||
# if diff > 0 it is added to destination
|
if assigner_stat.stat_type == 'distribution':
|
||||||
assigner_stat.remaining_amount -= diff
|
# if diff > 0 it is added to destination
|
||||||
assigner_stat.total_distributed += diff
|
assigner_stat.remaining_amount -= diff
|
||||||
assigner_stat.save()
|
print("distributed : ", assigner_stat.total_distributed)
|
||||||
|
assigner_stat.total_distributed += diff
|
||||||
|
print(assigner_stat.total_distributed, diff)
|
||||||
|
assigner_stat.save()
|
||||||
|
|
||||||
assigned_stat.total_amount += diff
|
assigned_stat.total_amount += diff
|
||||||
assigned_stat.remaining_amount += diff
|
assigned_stat.remaining_amount += diff
|
||||||
print(assigned_stat.id)
|
|
||||||
|
|
||||||
assigned_stat.save()
|
assigned_stat.save()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@@ -309,6 +309,7 @@ def organization_quota_stats(sender, instance: Quota, created: bool, **kwargs):
|
|||||||
org_quota_stat, created = OrganizationQuotaStats.objects.get_or_create(
|
org_quota_stat, created = OrganizationQuotaStats.objects.get_or_create(
|
||||||
quota=instance,
|
quota=instance,
|
||||||
organization=instance.registerer_organization,
|
organization=instance.registerer_organization,
|
||||||
|
stat_type='quota'
|
||||||
)
|
)
|
||||||
org_quota_stat.total_amount = instance.quota_weight
|
org_quota_stat.total_amount = instance.quota_weight
|
||||||
org_quota_stat.total_distributed = instance.quota_distributed
|
org_quota_stat.total_distributed = instance.quota_distributed
|
||||||
|
|||||||
Reference in New Issue
Block a user