Add numerical validation step for BomItem

This commit is contained in:
Oliver 2021-07-10 13:48:44 +10:00
parent f6d5bd4ed8
commit bf2774eb21

View File

@ -30,7 +30,7 @@ from mptt.models import TreeForeignKey, MPTTModel
from stdimage.models import StdImageField
from decimal import Decimal
from decimal import Decimal, InvalidOperation
from datetime import datetime
from rapidfuzz import fuzz
import hashlib
@ -2418,6 +2418,15 @@ class BomItem(models.Model):
- 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:
# Check for circular BOM references
if self.sub_part: