mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-02 21:38:48 +00:00
Fix 'symbol' field for CustomUnit (#7557)
* Fix 'symbol' field for CustomUnit - Do not require 'symbol' to be unique * Run check as part of validate_unique
This commit is contained in:
parent
62790cddc0
commit
7f43040049
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.12 on 2024-07-04 10:32
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('common', '0026_auto_20240608_1238'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='customunit',
|
||||||
|
name='symbol',
|
||||||
|
field=models.CharField(blank=True, help_text='Optional unit symbol', max_length=10, verbose_name='Symbol'),
|
||||||
|
),
|
||||||
|
]
|
@ -14,7 +14,7 @@ from datetime import timedelta, timezone
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from secrets import compare_digest
|
from secrets import compare_digest
|
||||||
from typing import Any, Callable, TypedDict, Union
|
from typing import Any, Callable, Collection, TypedDict, Union
|
||||||
|
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.conf import settings as django_settings
|
from django.conf import settings as django_settings
|
||||||
@ -3042,6 +3042,18 @@ class CustomUnit(models.Model):
|
|||||||
|
|
||||||
return fmt
|
return fmt
|
||||||
|
|
||||||
|
def validate_unique(self, exclude=None) -> None:
|
||||||
|
"""Ensure that the custom unit is unique."""
|
||||||
|
super().validate_unique(exclude)
|
||||||
|
|
||||||
|
if self.symbol:
|
||||||
|
if (
|
||||||
|
CustomUnit.objects.filter(symbol=self.symbol)
|
||||||
|
.exclude(pk=self.pk)
|
||||||
|
.exists()
|
||||||
|
):
|
||||||
|
raise ValidationError({'symbol': _('Unit symbol must be unique')})
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
"""Validate that the provided custom unit is indeed valid."""
|
"""Validate that the provided custom unit is indeed valid."""
|
||||||
super().clean()
|
super().clean()
|
||||||
@ -3083,7 +3095,6 @@ class CustomUnit(models.Model):
|
|||||||
max_length=10,
|
max_length=10,
|
||||||
verbose_name=_('Symbol'),
|
verbose_name=_('Symbol'),
|
||||||
help_text=_('Optional unit symbol'),
|
help_text=_('Optional unit symbol'),
|
||||||
unique=True,
|
|
||||||
blank=True,
|
blank=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user