add remaining weight to quota
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 5.0 on 2025-06-16 07:42
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('authorization', '0018_alter_userrelations_organization'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='page',
|
||||||
|
name='is_active',
|
||||||
|
field=models.BooleanField(default=True),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='permissions',
|
||||||
|
name='is_active',
|
||||||
|
field=models.BooleanField(default=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
18
apps/product/migrations/0028_quota_remaining_weight.py
Normal file
18
apps/product/migrations/0028_quota_remaining_weight.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.0 on 2025-06-16 07:45
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('product', '0027_alter_quotadistribution_assigner_organization'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='quota',
|
||||||
|
name='remaining_weight',
|
||||||
|
field=models.PositiveBigIntegerField(default=0),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -246,7 +246,7 @@ class Quota(BaseModel):
|
|||||||
quota_id = models.PositiveBigIntegerField(null=True, blank=True)
|
quota_id = models.PositiveBigIntegerField(null=True, blank=True)
|
||||||
quota_code = models.CharField(max_length=15, null=True)
|
quota_code = models.CharField(max_length=15, null=True)
|
||||||
quota_weight = models.PositiveIntegerField(default=0)
|
quota_weight = models.PositiveIntegerField(default=0)
|
||||||
remaining_quota_weight = models.PositiveBigIntegerField(default=0)
|
remaining_weight = models.PositiveBigIntegerField(default=0)
|
||||||
quota_distributed = models.PositiveIntegerField(default=0)
|
quota_distributed = models.PositiveIntegerField(default=0)
|
||||||
quota_balance = models.PositiveIntegerField(default=0)
|
quota_balance = models.PositiveIntegerField(default=0)
|
||||||
product = models.ForeignKey(
|
product = models.ForeignKey(
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ from .models import QuotaDistribution, Quota
|
|||||||
|
|
||||||
|
|
||||||
def recalculate_remaining_amount(quota):
|
def recalculate_remaining_amount(quota):
|
||||||
total_distributed = quota.distributions.aggregate(
|
total_distributed = quota.distributions_assigned.aggregate(
|
||||||
total=Sum('amount_kg')
|
total=Sum('weight')
|
||||||
)['total'] or 0
|
)['total'] or 0
|
||||||
|
|
||||||
quota.remaining_amount_kg = quota.total_amount_kg - total_distributed
|
quota.remaining_weight = quota.quota_weight - total_distributed
|
||||||
quota.save(update_fields=["remaining_amount_kg"])
|
quota.save(update_fields=["remaining_weight"])
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=QuotaDistribution)
|
@receiver(post_save, sender=QuotaDistribution)
|
||||||
|
|||||||
Reference in New Issue
Block a user