fix - set pre sale/free sale in property & add to quota model
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
# Generated by Django 5.0 on 2025-11-11 12:20
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('product', '0085_broker_suggested_broker_price'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='quota',
|
||||
name='free_sale',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='quota',
|
||||
name='free_sale_balance',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='quota',
|
||||
name='pre_sale',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='quota',
|
||||
name='pre_sale_balance',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,29 @@
|
||||
# Generated by Django 5.0 on 2025-11-11 12:29
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('product', '0086_quota_free_sale_quota_free_sale_balance_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='quota',
|
||||
name='free_sale',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='quota',
|
||||
name='free_sale_balance',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='quota',
|
||||
name='pre_sale',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='quota',
|
||||
name='pre_sale_balance',
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,28 @@
|
||||
# Generated by Django 5.0 on 2025-11-11 12:31
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('product', '0087_remove_quota_free_sale_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='quota',
|
||||
name='free_sale_balance',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='quota',
|
||||
name='pre_sale',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='quota',
|
||||
name='pre_sale_balance',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
]
|
||||
18
apps/product/migrations/0089_quota_free_sale.py
Normal file
18
apps/product/migrations/0089_quota_free_sale.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.0 on 2025-11-11 12:39
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('product', '0088_quota_free_sale_balance_quota_pre_sale_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='quota',
|
||||
name='free_sale',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,29 @@
|
||||
# Generated by Django 5.0 on 2025-11-11 12:45
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('product', '0089_quota_free_sale'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='historicalquotadistribution',
|
||||
name='free_sale',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='historicalquotadistribution',
|
||||
name='pre_sale',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='quotadistribution',
|
||||
name='free_sale',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='quotadistribution',
|
||||
name='pre_sale',
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,33 @@
|
||||
# Generated by Django 5.0 on 2025-11-11 12:48
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('product', '0090_remove_historicalquotadistribution_free_sale_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='historicalquotadistribution',
|
||||
name='free_sale',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='historicalquotadistribution',
|
||||
name='pre_sale',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='quotadistribution',
|
||||
name='free_sale',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='quotadistribution',
|
||||
name='pre_sale',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,29 @@
|
||||
# Generated by Django 5.0 on 2025-11-11 12:53
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('product', '0091_historicalquotadistribution_free_sale_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='historicalquotadistribution',
|
||||
name='free_sale',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='historicalquotadistribution',
|
||||
name='pre_sale',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='quotadistribution',
|
||||
name='free_sale',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='quotadistribution',
|
||||
name='pre_sale',
|
||||
),
|
||||
]
|
||||
@@ -406,6 +406,10 @@ class Quota(BaseModel):
|
||||
('all', 'ALL'),
|
||||
)
|
||||
pos_sale_type = models.CharField(choices=pos_sale_type_choices, max_length=25, default='all')
|
||||
pre_sale = models.BooleanField(default=False)
|
||||
pre_sale_balance = models.IntegerField(default=0)
|
||||
free_sale = models.BooleanField(default=False)
|
||||
free_sale_balance = models.IntegerField(default=0)
|
||||
|
||||
def __str__(self):
|
||||
return f"Quota ({self.id}) for {self.product.name}"
|
||||
@@ -732,9 +736,9 @@ class QuotaDistribution(BaseModel):
|
||||
warehouse_balance = models.PositiveBigIntegerField(default=0)
|
||||
been_sold = models.PositiveBigIntegerField(default=0)
|
||||
history = HistoricalRecords()
|
||||
pre_sale = models.BooleanField(default=False)
|
||||
# pre_sale = models.BooleanField(default=False)
|
||||
pre_sale_balance = models.PositiveBigIntegerField(default=0)
|
||||
free_sale = models.BooleanField(default=False)
|
||||
# free_sale = models.BooleanField(default=False)
|
||||
free_sale_balance = models.PositiveBigIntegerField(default=0)
|
||||
|
||||
def generate_distribution_id(self):
|
||||
@@ -767,6 +771,14 @@ class QuotaDistribution(BaseModel):
|
||||
for entry in self.inventory_entry.all():
|
||||
entry.soft_delete()
|
||||
|
||||
@property
|
||||
def free_sale(self):
|
||||
return self.quota.free_sale
|
||||
|
||||
@property
|
||||
def pre_sale(self):
|
||||
return self.quota.pre_sale
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.distribution_id:
|
||||
self.distribution_id = self.generate_distribution_id()
|
||||
|
||||
@@ -77,7 +77,7 @@ class QuotaDistributionSerializer(serializers.ModelSerializer):
|
||||
|
||||
return data
|
||||
|
||||
def to_representation(self, instance):
|
||||
def to_representation(self, instance: product_models.QuotaDistribution):
|
||||
""" Custom output of serializer """
|
||||
|
||||
representation = super().to_representation(instance)
|
||||
@@ -86,6 +86,9 @@ class QuotaDistributionSerializer(serializers.ModelSerializer):
|
||||
rancher = self.context['rancher']
|
||||
device = self.context['device']
|
||||
|
||||
representation['free_sale'] = instance.free_sale
|
||||
representation['pre_sale'] = instance.pre_sale
|
||||
|
||||
if instance.quota:
|
||||
representation['quota'] = {
|
||||
'quota_identity': instance.quota.quota_id,
|
||||
|
||||
@@ -94,7 +94,7 @@ class QuotaDistributionViewSet(viewsets.ModelViewSet, DynamicSearchMixin, POSDev
|
||||
Q(assigned_organization=organization),
|
||||
Q(quota__is_closed=False),
|
||||
(
|
||||
Q(pre_sale=True) | Q(free_sale=True) | Q(warehouse_entry__gt=0)
|
||||
Q(quota__pre_sale=True) | Q(quota__free_sale=True) | Q(warehouse_entry__gt=0)
|
||||
)
|
||||
).order_by('-create_date')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user