2
0
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:
Oliver 2021-08-10 10:58:11 +10:00
parent 6620d34f25
commit 7117c33379

View File

@ -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'),