From 2181c82a313b8d9963b674de20fdd8eeb9432720 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 28 Apr 2019 22:29:15 +1000 Subject: [PATCH 1/7] Add 'attachments' tab for Part --- .../part/templates/part/attachments.html | 21 +++++++++++++++++++ InvenTree/part/templates/part/tabs.html | 3 +++ InvenTree/part/urls.py | 1 + 3 files changed, 25 insertions(+) create mode 100644 InvenTree/part/templates/part/attachments.html diff --git a/InvenTree/part/templates/part/attachments.html b/InvenTree/part/templates/part/attachments.html new file mode 100644 index 0000000000..04041dd7b4 --- /dev/null +++ b/InvenTree/part/templates/part/attachments.html @@ -0,0 +1,21 @@ +{% extends "part/part_base.html" %} +{% load static %} + +{% block details %} + +{% include 'part/tabs.html' with tab='attachments' %} + +

Attachments

+ +
+
+ + +
+ +{% endblock %} + +{% block js_ready %} +{{ block.super }} + +{% endblock %} \ No newline at end of file diff --git a/InvenTree/part/templates/part/tabs.html b/InvenTree/part/templates/part/tabs.html index aa9d798bb7..5aee846ebd 100644 --- a/InvenTree/part/templates/part/tabs.html +++ b/InvenTree/part/templates/part/tabs.html @@ -31,4 +31,7 @@ {% endif %} {% endif %} + + Attachments {% if part.attachments.all|length > 0 %}{{ part.attachments.all|length }}{% endif %} + \ No newline at end of file diff --git a/InvenTree/part/urls.py b/InvenTree/part/urls.py index 96c830f556..2218b7b8a1 100644 --- a/InvenTree/part/urls.py +++ b/InvenTree/part/urls.py @@ -24,6 +24,7 @@ part_detail_urls = [ url(r'^delete/?', views.PartDelete.as_view(), name='part-delete'), url(r'^track/?', views.PartDetail.as_view(template_name='part/track.html'), name='part-track'), url(r'^bom-export/?', views.BomDownload.as_view(), name='bom-export'), + url(r'^attachments/?', views.PartDetail.as_view(template_name='part/attachments.html'), name='part-attachments'), url(r'^bom/?', views.PartDetail.as_view(template_name='part/bom.html'), name='part-bom'), url(r'^build/?', views.PartDetail.as_view(template_name='part/build.html'), name='part-build'), url(r'^stock/?', views.PartDetail.as_view(template_name='part/stock.html'), name='part-stock'), From ad6f4e19b123d02a36146bde280f13abdffb05fe Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 28 Apr 2019 22:40:17 +1000 Subject: [PATCH 2/7] Add 'comment' field to part attachment model --- .../migrations/0012_partattachment_comment.py | 18 ++++++++++++++++++ InvenTree/part/models.py | 15 +++------------ 2 files changed, 21 insertions(+), 12 deletions(-) create mode 100644 InvenTree/part/migrations/0012_partattachment_comment.py diff --git a/InvenTree/part/migrations/0012_partattachment_comment.py b/InvenTree/part/migrations/0012_partattachment_comment.py new file mode 100644 index 0000000000..a1a0057d1b --- /dev/null +++ b/InvenTree/part/migrations/0012_partattachment_comment.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2 on 2019-04-28 12:31 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('part', '0011_auto_20190428_0841'), + ] + + operations = [ + migrations.AddField( + model_name='partattachment', + name='comment', + field=models.CharField(blank=True, help_text='File comment', max_length=100), + ), + ] diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 19682929cf..ab83b584cd 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -125,7 +125,7 @@ class Part(models.Model): IPN = models.CharField(max_length=100, blank=True, help_text='Internal Part Number') # Provide a URL for an external link - URL = models.URLField(blank=True, help_text='Link to external URL') + URL = models.URLField(blank=True, help_text='Link to extenal URL') # Part category - all parts must be assigned to a category category = models.ForeignKey(PartCategory, related_name='parts', @@ -307,12 +307,6 @@ class Part(models.Model): def used_in_count(self): return self.used_in.count() - def required_parts(self): - parts = [] - for bom in self.bom_items.all(): - parts.append(bom.sub_part) - return parts - @property def supplier_count(self): # Return the number of supplier parts available for this part @@ -366,7 +360,7 @@ 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") + comment = models.CharField(max_length=100, blank=True, help_text='File comment') @property def basename(self): @@ -407,11 +401,8 @@ 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 - elif self.part == self.sub_part: + if self.part == self.sub_part: raise ValidationError({'sub_part': _('Part cannot be added to its own Bill of Materials')}) # Test for simple recursion From 9614ac2958ab9c3a0d044d835ab528b70d9c1093 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 28 Apr 2019 22:40:30 +1000 Subject: [PATCH 3/7] Move attachments list to attachments tab --- InvenTree/part/templates/part/attachments.html | 10 ++++++++++ InvenTree/part/templates/part/part_base.html | 7 ------- InvenTree/part/templates/part/tabs.html | 17 ++++++++++------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/InvenTree/part/templates/part/attachments.html b/InvenTree/part/templates/part/attachments.html index 04041dd7b4..b6339c23c7 100644 --- a/InvenTree/part/templates/part/attachments.html +++ b/InvenTree/part/templates/part/attachments.html @@ -11,6 +11,16 @@ + + + + +{% for attachment in part.attachments.all %} + + + + +{% endfor %}
FileComment
{{ attachment.basename }}{{ attachment.comment }}
{% endblock %} diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index 79be275307..a1b4ddc2d1 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -66,13 +66,6 @@ {% endif %} - -

Attachments

- diff --git a/InvenTree/part/templates/part/tabs.html b/InvenTree/part/templates/part/tabs.html index 5aee846ebd..2bcf894b2a 100644 --- a/InvenTree/part/templates/part/tabs.html +++ b/InvenTree/part/templates/part/tabs.html @@ -1,6 +1,15 @@