fix - permission search by name & some view(serializer) of transaction
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
from apps.warehouse.exceptions import (
|
||||
InventoryEntryWeightException,
|
||||
TotalInventorySaleException
|
||||
)
|
||||
from django.db import models
|
||||
from rest_framework import serializers
|
||||
|
||||
from apps.product.exceptions import QuotaExpiredTimeException
|
||||
from apps.warehouse import models as warehouse_models
|
||||
from apps.authorization.models import UserRelations
|
||||
from rest_framework import serializers
|
||||
from django.db import models
|
||||
from apps.warehouse.exceptions import (
|
||||
InventoryEntryWeightException
|
||||
)
|
||||
|
||||
|
||||
class InventoryEntrySerializer(serializers.ModelSerializer):
|
||||
@@ -91,29 +90,10 @@ class InventoryQuotaSaleTransactionSerializer(serializers.ModelSerializer):
|
||||
inventory_entry = attrs['inventory_entry']
|
||||
distribution = attrs['quota_distribution']
|
||||
|
||||
total_sale_weight = inventory_entry.inventory_sales.aggregate(
|
||||
total=models.Sum('weight')
|
||||
)['total'] or 0
|
||||
|
||||
if total_sale_weight + attrs['weight'] > distribution.warehouse_balance:
|
||||
raise TotalInventorySaleException()
|
||||
|
||||
return attrs
|
||||
|
||||
def create(self, validated_data):
|
||||
""" Custom create & set some parameters like seller & buyer """
|
||||
|
||||
distribution = validated_data['quota_distribution']
|
||||
seller_organization = distribution.assigned_organization
|
||||
|
||||
user = self.context['request'].user
|
||||
buyer_user = user
|
||||
seller_user = validated_data['inventory_entry'].created_by
|
||||
|
||||
return warehouse_models.InventoryQuotaSaleTransaction.objects.create(
|
||||
seller_organization=seller_organization,
|
||||
seller_user=seller_user,
|
||||
buyer_user=buyer_user,
|
||||
**validated_data
|
||||
)
|
||||
|
||||
class InventoryQuotaSaleItemSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = warehouse_models.InventoryQuotaSaleItem
|
||||
fields = '__all__'
|
||||
|
||||
Reference in New Issue
Block a user