fix inventory edit weight bug - fix inventory document - set new validations for distribution
This commit is contained in:
@@ -402,7 +402,7 @@ class Quota(BaseModel):
|
||||
now = datetime.now()
|
||||
persian_date = jdatetime.datetime.fromgregorian(datetime=now)
|
||||
|
||||
return persian_date.month in self.month_choices
|
||||
return persian_date.month in self.sale_license
|
||||
|
||||
def save(self, calculate_final_price=None, *args, **kwargs):
|
||||
if not self.quota_id:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from rest_framework import serializers
|
||||
from apps.product import models as product_models
|
||||
from rest_framework.exceptions import APIException
|
||||
from apps.product.web.api.v1.serializers.quota_serializers import QuotaSerializer
|
||||
from django.db import models
|
||||
from apps.product.exceptions import (
|
||||
@@ -55,6 +56,19 @@ class QuotaDistributionSerializer(serializers.ModelSerializer):
|
||||
if total + amount > quota.quota_weight:
|
||||
raise QuotaWeightException()
|
||||
|
||||
# total warehouse inventory entry
|
||||
total_entry = self.instance.inventory_entry.aggregate(
|
||||
total=models.Sum('weight')
|
||||
)['total'] or 0
|
||||
|
||||
# if inventory entry weight is bigger than distribute weight in edit distribution
|
||||
if total_entry > self.instance.weight:
|
||||
raise APIException("وزن وارد شده کمتر از وزن ورودی به انبار است", code=403) # noqa
|
||||
|
||||
# if weight is more than distribution remaining weight
|
||||
if self.instance.weight > self.instance.remaining_weight:
|
||||
raise APIException("وزن وارد شده بیشتر از وزن باقیمانده است", code=403) # noqa
|
||||
|
||||
return data
|
||||
|
||||
def to_representation(self, instance):
|
||||
|
||||
@@ -70,7 +70,6 @@ class InventoryEntryViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
|
||||
@transaction.atomic
|
||||
def update(self, request, pk=None, *args, **kwargs):
|
||||
""" edit inventory """
|
||||
|
||||
inventory = self.get_object()
|
||||
serializer = self.serializer_class(data=request.data, instance=inventory, partial=True)
|
||||
if serializer.is_valid():
|
||||
|
||||
@@ -42,8 +42,12 @@ class InventoryEntrySerializer(serializers.ModelSerializer):
|
||||
total=models.Sum('weight')
|
||||
)['total'] or 0
|
||||
|
||||
if total_entered + attrs['weight'] > distribution.weight:
|
||||
raise InventoryEntryWeightException()
|
||||
if self.instance.weight is 0:
|
||||
if total_entered + attrs['weight'] > distribution.weight:
|
||||
raise InventoryEntryWeightException()
|
||||
elif self.instance.weight is not 0:
|
||||
if total_entered - self.instance.weight + attrs['weight'] > distribution.weight:
|
||||
raise InventoryEntryWeightException()
|
||||
|
||||
return attrs
|
||||
|
||||
|
||||
Reference in New Issue
Block a user