From a129c650fe600c8d1d75b5379833ff0407383510 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 31 May 2022 13:33:23 +1000 Subject: [PATCH] Remove unique-together requirement for BomItem model (#3104) * Remove unique-together requirement for BomItem model Ref: https://github.com/inventree/InvenTree/issues/1254 * Update unit test * Remove unused import --- InvenTree/build/test_build.py | 14 ++++++-------- .../0077_alter_bomitem_unique_together.py | 17 +++++++++++++++++ InvenTree/part/models.py | 3 --- 3 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 InvenTree/part/migrations/0077_alter_bomitem_unique_together.py diff --git a/InvenTree/build/test_build.py b/InvenTree/build/test_build.py index e2cda00ec9..d61b2adbaa 100644 --- a/InvenTree/build/test_build.py +++ b/InvenTree/build/test_build.py @@ -3,7 +3,6 @@ from django.test import TestCase from django.core.exceptions import ValidationError -from django.db.utils import IntegrityError from InvenTree import status_codes as status @@ -194,14 +193,13 @@ class BuildTest(BuildTestBase): b.save() def test_duplicate_bom_line(self): - # Try to add a duplicate BOM item - it should fail! + # Try to add a duplicate BOM item - it should be allowed - with self.assertRaises(IntegrityError): - BomItem.objects.create( - part=self.assembly, - sub_part=self.sub_part_1, - quantity=99 - ) + BomItem.objects.create( + part=self.assembly, + sub_part=self.sub_part_1, + quantity=99 + ) def allocate_stock(self, output, allocations): """ diff --git a/InvenTree/part/migrations/0077_alter_bomitem_unique_together.py b/InvenTree/part/migrations/0077_alter_bomitem_unique_together.py new file mode 100644 index 0000000000..e12a402d84 --- /dev/null +++ b/InvenTree/part/migrations/0077_alter_bomitem_unique_together.py @@ -0,0 +1,17 @@ +# Generated by Django 3.2.13 on 2022-05-31 01:42 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('part', '0076_auto_20220516_0819'), + ] + + operations = [ + migrations.AlterUniqueTogether( + name='bomitem', + unique_together=set(), + ), + ] diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 0fa6c738aa..3437437cef 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -2899,9 +2899,6 @@ class BomItem(models.Model, DataImportMixin): class Meta: verbose_name = _("BOM Item") - # Prevent duplication of parent/child rows - unique_together = ('part', 'sub_part') - def __str__(self): return "{n} x {child} to make {parent}".format( parent=self.part.full_name,