From 7c11d917de3249601c6475365a94311cf7a00739 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 1 May 2019 09:40:49 +1000 Subject: [PATCH] Bug fixes - Part creation form was setting a field as HiddenInput() rather than its widget - Added 'comment' file to FileAttachment model --- InvenTree/part/admin.py | 2 +- .../migrations/0014_partattachment_comment.py | 18 ++++++++++++++++++ InvenTree/part/models.py | 7 ++++++- InvenTree/part/views.py | 2 +- 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 InvenTree/part/migrations/0014_partattachment_comment.py diff --git a/InvenTree/part/admin.py b/InvenTree/part/admin.py index 4e63bf65e0..56bf290739 100644 --- a/InvenTree/part/admin.py +++ b/InvenTree/part/admin.py @@ -19,7 +19,7 @@ class PartCategoryAdmin(ImportExportModelAdmin): class PartAttachmentAdmin(admin.ModelAdmin): - list_display = ('part', 'attachment') + list_display = ('part', 'attachment', 'comment') class BomItemAdmin(ImportExportModelAdmin): diff --git a/InvenTree/part/migrations/0014_partattachment_comment.py b/InvenTree/part/migrations/0014_partattachment_comment.py new file mode 100644 index 0000000000..a51f588a59 --- /dev/null +++ b/InvenTree/part/migrations/0014_partattachment_comment.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2 on 2019-04-30 23:34 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('part', '0013_auto_20190429_2229'), + ] + + operations = [ + migrations.AddField( + model_name='partattachment', + name='comment', + field=models.CharField(blank=True, help_text='Attachment description', max_length=100), + ), + ] diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 635ad9fa97..19682929cf 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -366,6 +366,8 @@ class PartAttachment(models.Model): attachment = models.FileField(upload_to=attach_file, null=True, blank=True) + comment = models.CharField(max_length=100, blank=True, help_text="Attachment description") + @property def basename(self): return os.path.basename(self.attachment.name) @@ -405,8 +407,11 @@ class BomItem(models.Model): - A part cannot refer to a part which refers to it """ + if self.part is None or self.sub_part is None: + # Field validation will catch these None values + pass # A part cannot refer to itself in its BOM - if self.part == self.sub_part: + elif self.part == self.sub_part: raise ValidationError({'sub_part': _('Part cannot be added to its own Bill of Materials')}) # Test for simple recursion diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index 6e3eed583a..7ea8e5efbf 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -98,7 +98,7 @@ class PartCreate(AjaxCreateView): form = super(AjaxCreateView, self).get_form() # Hide the default_supplier field (there are no matching supplier parts yet!) - form.fields['default_supplier'] = HiddenInput() + form.fields['default_supplier'].widget = HiddenInput() return form