quotas information by product - change broker & attribute sale unit
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
# Generated by Django 5.0 on 2025-07-08 10:32
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('product', '0036_historicalquotadistribution'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='attribute',
|
||||||
|
name='type',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='broker',
|
||||||
|
name='calculation_strategy',
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='saleunit',
|
||||||
|
name='unit',
|
||||||
|
field=models.CharField(max_length=250, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
# Generated by Django 5.0 on 2025-07-08 10:37
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('product', '0037_remove_attribute_type_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='attribute',
|
||||||
|
name='type',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='attributes', to='product.saleunit'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='broker',
|
||||||
|
name='calculation_strategy',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='brokers', to='product.saleunit'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -144,15 +144,11 @@ class Attribute(BaseModel):
|
|||||||
null=True
|
null=True
|
||||||
)
|
)
|
||||||
name = models.CharField(max_length=100, default='empty')
|
name = models.CharField(max_length=100, default='empty')
|
||||||
type_choices = (
|
type = models.ForeignKey(
|
||||||
('K', 'Per Kilo'),
|
'SaleUnit',
|
||||||
('', ''),
|
on_delete=models.CASCADE,
|
||||||
)
|
related_name="attributes",
|
||||||
type = models.CharField(
|
null=True
|
||||||
max_length=10,
|
|
||||||
choices=type_choices,
|
|
||||||
default='empty',
|
|
||||||
help_text='type of attribute like: calculate product by kilogram'
|
|
||||||
)
|
)
|
||||||
|
|
||||||
is_global = models.BooleanField(default=False)
|
is_global = models.BooleanField(default=False)
|
||||||
@@ -194,10 +190,6 @@ class AttributeValue(BaseModel):
|
|||||||
class Broker(BaseModel):
|
class Broker(BaseModel):
|
||||||
""" Broker for product """
|
""" Broker for product """
|
||||||
|
|
||||||
CALCULATION_CHOICES = (
|
|
||||||
('K', 'Per Kilo'),
|
|
||||||
('', ''),
|
|
||||||
)
|
|
||||||
BROKER_TYPES = (
|
BROKER_TYPES = (
|
||||||
('public', 'PUBLIC'),
|
('public', 'PUBLIC'),
|
||||||
('exclusive', 'EXCLUSIVE')
|
('exclusive', 'EXCLUSIVE')
|
||||||
@@ -215,10 +207,11 @@ class Broker(BaseModel):
|
|||||||
related_name='product_organization',
|
related_name='product_organization',
|
||||||
null=True
|
null=True
|
||||||
)
|
)
|
||||||
calculation_strategy = models.CharField(
|
calculation_strategy = models.ForeignKey(
|
||||||
max_length=3,
|
'SaleUnit',
|
||||||
choices=CALCULATION_CHOICES,
|
on_delete=models.CASCADE,
|
||||||
default='empty'
|
related_name='brokers',
|
||||||
|
null=True
|
||||||
)
|
)
|
||||||
broker_type = models.CharField(choices=BROKER_TYPES, max_length=20, null=True)
|
broker_type = models.CharField(choices=BROKER_TYPES, max_length=20, null=True)
|
||||||
required = models.BooleanField(default=False)
|
required = models.BooleanField(default=False)
|
||||||
@@ -239,12 +232,7 @@ class SaleUnit(BaseModel):
|
|||||||
related_name='sale_unit',
|
related_name='sale_unit',
|
||||||
null=True
|
null=True
|
||||||
)
|
)
|
||||||
unit_choices = (
|
unit = models.CharField(max_length=250, null=True)
|
||||||
('10P', '10KG Package'),
|
|
||||||
('50P', '50KG Package'),
|
|
||||||
('', ''),
|
|
||||||
)
|
|
||||||
unit = models.CharField(max_length=10, choices=unit_choices, null=True)
|
|
||||||
variation_coefficient = models.IntegerField(default=0)
|
variation_coefficient = models.IntegerField(default=0)
|
||||||
required = models.BooleanField(default=False)
|
required = models.BooleanField(default=False)
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from apps.warehouse.models import InventoryEntry
|
|||||||
|
|
||||||
|
|
||||||
def get_products_in_warehouse(organization_id):
|
def get_products_in_warehouse(organization_id):
|
||||||
""" get lis of products from organization warehouse """
|
""" get list of products from organization warehouse """
|
||||||
|
|
||||||
entries = InventoryEntry.objects.select_related(
|
entries = InventoryEntry.objects.select_related(
|
||||||
'distribution__quota__product'
|
'distribution__quota__product'
|
||||||
|
|||||||
@@ -103,6 +103,27 @@ class ProductViewSet(viewsets.ModelViewSet):
|
|||||||
|
|
||||||
return Response(product_data, status=status.HTTP_200_OK)
|
return Response(product_data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
@action(
|
||||||
|
methods=['get'],
|
||||||
|
detail=True,
|
||||||
|
url_path='quotas_information',
|
||||||
|
url_name='quotas_information',
|
||||||
|
name='quotas_information'
|
||||||
|
)
|
||||||
|
@transaction.atomic
|
||||||
|
def quotas_information_by_product(self, request, pk=None):
|
||||||
|
""" get quotas information of a product """
|
||||||
|
|
||||||
|
quotas = product_models.Quota.objects.select_related('product').filter(
|
||||||
|
product_id=pk, is_closed=False
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
quota_serializer = product_serializers.QuotaSerializer(quotas, many=True).data
|
||||||
|
return Response(quota_serializer, status=status.HTTP_200_OK)
|
||||||
|
except APIException as e:
|
||||||
|
raise APIException(detail="data error", code=400)
|
||||||
|
|
||||||
@action(
|
@action(
|
||||||
methods=['put'],
|
methods=['put'],
|
||||||
detail=True,
|
detail=True,
|
||||||
@@ -136,7 +157,7 @@ class ProductViewSet(viewsets.ModelViewSet):
|
|||||||
|
|
||||||
|
|
||||||
class AttributeViewSet(viewsets.ModelViewSet):
|
class AttributeViewSet(viewsets.ModelViewSet):
|
||||||
""" attributes of reference product """
|
""" attributes of reference product """ #
|
||||||
|
|
||||||
queryset = product_models.Attribute.objects.all()
|
queryset = product_models.Attribute.objects.all()
|
||||||
serializer_class = product_serializers.AttributeSerializer
|
serializer_class = product_serializers.AttributeSerializer
|
||||||
|
|||||||
@@ -44,6 +44,12 @@ class AttributeSerializer(serializers.ModelSerializer):
|
|||||||
'id': instance.product.id,
|
'id': instance.product.id,
|
||||||
'name': instance.product.name
|
'name': instance.product.name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if instance.type:
|
||||||
|
representation['type'] = {
|
||||||
|
'id': instance.type.id,
|
||||||
|
'unit': instance.type.unit
|
||||||
|
}
|
||||||
return representation
|
return representation
|
||||||
|
|
||||||
|
|
||||||
@@ -70,6 +76,7 @@ class BrokerSerializer(serializers.ModelSerializer):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = product_models.Broker
|
model = product_models.Broker
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
depth = 0
|
||||||
|
|
||||||
def to_representation(self, instance):
|
def to_representation(self, instance):
|
||||||
representation = super().to_representation(instance)
|
representation = super().to_representation(instance)
|
||||||
@@ -83,6 +90,12 @@ class BrokerSerializer(serializers.ModelSerializer):
|
|||||||
instance.product
|
instance.product
|
||||||
).data
|
).data
|
||||||
|
|
||||||
|
if instance.calculation_strategy:
|
||||||
|
representation['calculation_strategy'] = {
|
||||||
|
'id': instance.calculation_strategy.id,
|
||||||
|
'unit': instance.calculation_strategy.unit
|
||||||
|
}
|
||||||
|
|
||||||
return representation
|
return representation
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user