From d9f73ae05bf8b44ab0b5d7f3752feb8f332fdbcb Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 7 Mar 2022 12:27:00 +1100 Subject: [PATCH] Clip integer versions of serial numbers to specified range --- InvenTree/InvenTree/models.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/InvenTree/InvenTree/models.py b/InvenTree/InvenTree/models.py index 0fe3136871..1296ba8978 100644 --- a/InvenTree/InvenTree/models.py +++ b/InvenTree/InvenTree/models.py @@ -133,7 +133,7 @@ class ReferenceIndexingMixin(models.Model): reference_int = models.BigIntegerField(default=0) -def extract_int(reference): +def extract_int(reference, clip=0x7fffffff): # Default value if we cannot convert to an integer ref_int = 0 @@ -146,6 +146,15 @@ def extract_int(reference): ref_int = int(ref) except: ref_int = 0 + + # Ensure that the returned values are within the range that can be stored in an IntegerField + # Note: This will result in large values being "clipped" + if clip is not None: + if ref_int > clip: + ref_int = clip + elif ref_int < clip: + ref_int = clip + return ref_int