fix validation

This commit is contained in:
Matthias 2021-12-02 01:03:30 +01:00
parent fc6f1b4acc
commit b8cdcab10d
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076
2 changed files with 21 additions and 16 deletions

View File

@ -72,6 +72,12 @@ class ReferenceIndexingMixin(models.Model):
reference = getattr(self, 'reference', '')
self.reference_int = extract_int(reference)
reference_int = models.BigIntegerField(default=0)
def extract_int(reference):
# Default value if we cannot convert to an integer
ref_int = 0
@ -84,10 +90,7 @@ class ReferenceIndexingMixin(models.Model):
ref_int = int(ref)
except:
ref_int = 0
self.reference_int = ref_int
reference_int = models.BigIntegerField(default=0)
return ref_int
class InvenTreeAttachment(models.Model):

View File

@ -28,6 +28,8 @@ from rest_framework.fields import empty
from rest_framework.exceptions import ValidationError
from rest_framework.serializers import DecimalField
from .models import extract_int
class InvenTreeMoneySerializer(MoneyField):
"""
@ -246,9 +248,9 @@ class ReferenceIndexingSerializerMixin():
for the BigIntegerField
"""
def validate_reference(self, value):
if int(value) < -models.BigIntegerField.MAX_BIGINT:
if extract_int(value) < -models.BigIntegerField.MAX_BIGINT:
raise serializers.ValidationError('reference is to to small')
if int(value) > models.BigIntegerField.MAX_BIGINT:
if extract_int(value) > models.BigIntegerField.MAX_BIGINT:
raise serializers.ValidationError('reference is to to big')
return value