diff --git a/InvenTree/stock/admin.py b/InvenTree/stock/admin.py index e233908ec7..a9cbcc9de7 100644 --- a/InvenTree/stock/admin.py +++ b/InvenTree/stock/admin.py @@ -8,7 +8,7 @@ from import_export.resources import ModelResource from import_export.fields import Field import import_export.widgets as widgets -from .models import StockLocation, StockItem +from .models import StockLocation, StockItem, StockItemAttachment from .models import StockItemTracking from build.models import Build @@ -108,6 +108,12 @@ class StockItemAdmin(ImportExportModelAdmin): list_display = ('part', 'quantity', 'location', 'status', 'updated') +class StockAttachmentAdmin(admin.ModelAdmin): + + list_display = ('stock_item', 'attachment', 'comment') + + + class StockTrackingAdmin(ImportExportModelAdmin): list_display = ('item', 'date', 'title') @@ -115,3 +121,4 @@ class StockTrackingAdmin(ImportExportModelAdmin): admin.site.register(StockLocation, LocationAdmin) admin.site.register(StockItem, StockItemAdmin) admin.site.register(StockItemTracking, StockTrackingAdmin) +admin.site.register(StockItemAttachment, StockAttachmentAdmin) diff --git a/InvenTree/stock/migrations/0036_stockitemattachment.py b/InvenTree/stock/migrations/0036_stockitemattachment.py new file mode 100644 index 0000000000..946f6251b0 --- /dev/null +++ b/InvenTree/stock/migrations/0036_stockitemattachment.py @@ -0,0 +1,27 @@ +# Generated by Django 3.0.5 on 2020-05-06 23:36 + +import InvenTree.models +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('stock', '0035_auto_20200502_2308'), + ] + + operations = [ + migrations.CreateModel( + name='StockItemAttachment', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('attachment', models.FileField(help_text='Select file to attach', upload_to=InvenTree.models.rename_attachment)), + ('comment', models.CharField(help_text='File comment', max_length=100)), + ('stock_item', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attachments', to='stock.StockItem')), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index f514eea3da..6ab8ec07ee 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -27,7 +27,7 @@ from datetime import datetime from InvenTree import helpers from InvenTree.status_codes import StockStatus -from InvenTree.models import InvenTreeTree +from InvenTree.models import InvenTreeTree, InvenTreeAttachment from InvenTree.fields import InvenTreeURLField from part import models as PartModels @@ -935,6 +935,21 @@ def before_delete_stock_item(sender, instance, using, **kwargs): StockItem.objects.rebuild() +class StockItemAttachment(InvenTreeAttachment): + """ + Model for storing file attachments against a StockItem object. + """ + + def getSubdir(self): + return os.path.join("stock_files", str(self.stock_item.id)) + + stock_item = models.ForeignKey( + StockItem, + on_delete=models.CASCADE, + related_name='attachments' + ) + + class StockItemTracking(models.Model): """ Stock tracking entry - breacrumb for keeping track of automated stock transactions