some changes in inventory serializer - creted date & distribution data

This commit is contained in:
2025-07-29 07:58:32 +03:30
parent e96da0ecc4
commit 63898533a3
5 changed files with 86 additions and 15 deletions

View File

@@ -14,6 +14,8 @@ class InventoryEntrySerializer(serializers.ModelSerializer):
model = warehouse_models.InventoryEntry
fields = [
"id",
"create_date",
"modify_date",
"distribution",
"weight",
"lading_number",
@@ -22,17 +24,6 @@ class InventoryEntrySerializer(serializers.ModelSerializer):
"notes",
]
def create(self, validated_data):
""" Custom create & set organization """
distribution = validated_data['distribution']
organization = distribution.assigned_organization
return warehouse_models.InventoryEntry.objects.create(
organization=organization,
**validated_data
)
def validate(self, attrs):
"""
check if inventory entries weight is not more than
@@ -58,6 +49,8 @@ class InventoryEntrySerializer(serializers.ModelSerializer):
def to_representation(self, instance):
representation = super().to_representation(instance)
representation['document'] = instance.document
if instance.distribution:
representation['distribution'] = instance.distribution.distribution_id
return representation