2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-01 19:20:55 +00:00

Merge pull request #1797 from SchrodingersGat/bom-validation-fix

Add numerical validation step for BomItem
This commit is contained in:
Oliver
2021-07-10 14:14:52 +10:00
committed by GitHub

View File

@ -30,7 +30,7 @@ from mptt.models import TreeForeignKey, MPTTModel
from stdimage.models import StdImageField from stdimage.models import StdImageField
from decimal import Decimal from decimal import Decimal, InvalidOperation
from datetime import datetime from datetime import datetime
from rapidfuzz import fuzz from rapidfuzz import fuzz
import hashlib import hashlib
@ -2418,6 +2418,15 @@ class BomItem(models.Model):
- If the "sub_part" is trackable, then the "part" must be trackable too! - If the "sub_part" is trackable, then the "part" must be trackable too!
""" """
super().clean()
try:
self.quantity = Decimal(self.quantity)
except InvalidOperation:
raise ValidationError({
'quantity': _('Must be a valid number')
})
try: try:
# Check for circular BOM references # Check for circular BOM references
if self.sub_part: if self.sub_part: