mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add regex validator to build order reference field
This commit is contained in:
parent
06040f94ee
commit
a5639c380f
@ -52,6 +52,48 @@ def validate_part_ipn(value):
|
||||
raise ValidationError(_('IPN must match regex pattern') + " '{pat}'".format(pat=pattern))
|
||||
|
||||
|
||||
def validate_build_order_reference(value):
|
||||
"""
|
||||
Validate the 'reference' field of a BuildOrder
|
||||
"""
|
||||
|
||||
pattern = common.models.InvenTreeSetting.get_setting('buildorder_reference_regex')
|
||||
|
||||
if pattern:
|
||||
match = re.search(pattern, value)
|
||||
|
||||
if match is None:
|
||||
raise ValidationError(_('Reference must match pattern') + f" '{pattern}'")
|
||||
|
||||
|
||||
def validate_purchase_order_reference(value):
|
||||
"""
|
||||
Validate the 'reference' field of a PurchaseOrder
|
||||
"""
|
||||
|
||||
pattern = common.models.InvenTreeSetting.get_setting('purchaseorder_reference_regex')
|
||||
|
||||
if pattern:
|
||||
match = re.search(pattern, value)
|
||||
|
||||
if match is None:
|
||||
raise ValidationError(_('Reference must match pattern') + f" '{pattern}'")
|
||||
|
||||
|
||||
def validate_sales_order_reference(value):
|
||||
"""
|
||||
Validate the 'reference' field of a SalesOrder
|
||||
"""
|
||||
|
||||
pattern = common.models.InvenTreeSetting.get_setting('salesorder_reference_regex')
|
||||
|
||||
if pattern:
|
||||
match = re.search(pattern, value)
|
||||
|
||||
if match is None:
|
||||
raise ValidationError(_('Reference must match pattern') + f" '{pattern}'")
|
||||
|
||||
|
||||
def validate_tree_name(value):
|
||||
""" Prevent illegal characters in tree item names """
|
||||
|
||||
|
23
InvenTree/build/migrations/0019_auto_20201019_1302.py
Normal file
23
InvenTree/build/migrations/0019_auto_20201019_1302.py
Normal file
@ -0,0 +1,23 @@
|
||||
# Generated by Django 3.0.7 on 2020-10-19 13:02
|
||||
|
||||
import InvenTree.validators
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('build', '0018_build_reference'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='build',
|
||||
options={'verbose_name': 'Build Order', 'verbose_name_plural': 'Build Orders'},
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='build',
|
||||
name='reference',
|
||||
field=models.CharField(help_text='Build Order Reference', max_length=64, unique=True, validators=[InvenTree.validators.validate_build_order_reference], verbose_name='Reference'),
|
||||
),
|
||||
]
|
@ -23,6 +23,8 @@ from mptt.models import MPTTModel, TreeForeignKey
|
||||
|
||||
from InvenTree.status_codes import BuildStatus
|
||||
from InvenTree.helpers import increment
|
||||
from InvenTree.validators import validate_build_order_reference
|
||||
|
||||
import InvenTree.fields
|
||||
|
||||
from stock import models as StockModels
|
||||
@ -81,6 +83,9 @@ class Build(MPTTModel):
|
||||
blank=False,
|
||||
help_text=_('Build Order Reference'),
|
||||
verbose_name=_('Reference'),
|
||||
validators=[
|
||||
validate_build_order_reference
|
||||
]
|
||||
)
|
||||
|
||||
title = models.CharField(
|
||||
|
Loading…
Reference in New Issue
Block a user