mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-04 14:28:48 +00:00
Raise validation error if the manufacturer part does not point to the correct part
This commit is contained in:
parent
6620d34f25
commit
7117c33379
@ -9,6 +9,8 @@ import os
|
|||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.core.validators import MinValueValidator
|
from django.core.validators import MinValueValidator
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import Sum, Q, UniqueConstraint
|
from django.db.models import Sum, Q, UniqueConstraint
|
||||||
|
|
||||||
@ -479,6 +481,18 @@ class SupplierPart(models.Model):
|
|||||||
# This model was moved from the 'Part' app
|
# This model was moved from the 'Part' app
|
||||||
db_table = 'part_supplierpart'
|
db_table = 'part_supplierpart'
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
|
||||||
|
super().clean()
|
||||||
|
|
||||||
|
# Ensure that the linked manufacturer_part points to the same part!
|
||||||
|
if self.manufacturer_part and self.part:
|
||||||
|
|
||||||
|
if not self.manufacturer_part.part == self.part:
|
||||||
|
raise ValidationError({
|
||||||
|
'manufacturer_part': _("Linked manufacturer part must reference the same base part"),
|
||||||
|
})
|
||||||
|
|
||||||
part = models.ForeignKey('part.Part', on_delete=models.CASCADE,
|
part = models.ForeignKey('part.Part', on_delete=models.CASCADE,
|
||||||
related_name='supplier_parts',
|
related_name='supplier_parts',
|
||||||
verbose_name=_('Base Part'),
|
verbose_name=_('Base Part'),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user