diff --git a/InvenTree/InvenTree/models.py b/InvenTree/InvenTree/models.py index d2a5c5daa6..103d571fd1 100644 --- a/InvenTree/InvenTree/models.py +++ b/InvenTree/InvenTree/models.py @@ -7,6 +7,7 @@ from __future__ import unicode_literals import os from django.db import models +from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType from django.utils.translation import gettext_lazy as _ @@ -55,6 +56,13 @@ class InvenTreeAttachment(models.Model): comment = models.CharField(max_length=100, help_text=_('File comment')) + user = models.ForeignKey( + User, + on_delete=models.SET_NULL, + blank=True, null=True, + help_text=_('User'), + ) + @property def basename(self): return os.path.basename(self.attachment.name) diff --git a/InvenTree/order/migrations/0033_auto_20200512_1033.py b/InvenTree/order/migrations/0033_auto_20200512_1033.py new file mode 100644 index 0000000000..2c3abbb0d0 --- /dev/null +++ b/InvenTree/order/migrations/0033_auto_20200512_1033.py @@ -0,0 +1,26 @@ +# Generated by Django 3.0.5 on 2020-05-12 10:33 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('order', '0032_auto_20200427_0044'), + ] + + operations = [ + migrations.AddField( + model_name='purchaseorderattachment', + name='user', + field=models.ForeignKey(blank=True, help_text='User', null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL), + ), + migrations.AddField( + model_name='salesorderattachment', + name='user', + field=models.ForeignKey(blank=True, help_text='User', null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/InvenTree/part/migrations/0036_partattachment_user.py b/InvenTree/part/migrations/0036_partattachment_user.py new file mode 100644 index 0000000000..d59bc7ffb2 --- /dev/null +++ b/InvenTree/part/migrations/0036_partattachment_user.py @@ -0,0 +1,21 @@ +# Generated by Django 3.0.5 on 2020-05-12 10:33 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('part', '0035_auto_20200406_0045'), + ] + + operations = [ + migrations.AddField( + model_name='partattachment', + name='user', + field=models.ForeignKey(blank=True, help_text='User', null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/InvenTree/stock/migrations/0037_stockitemattachment_user.py b/InvenTree/stock/migrations/0037_stockitemattachment_user.py new file mode 100644 index 0000000000..b0f87df81a --- /dev/null +++ b/InvenTree/stock/migrations/0037_stockitemattachment_user.py @@ -0,0 +1,21 @@ +# Generated by Django 3.0.5 on 2020-05-12 10:33 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('stock', '0036_stockitemattachment'), + ] + + operations = [ + migrations.AddField( + model_name='stockitemattachment', + name='user', + field=models.ForeignKey(blank=True, help_text='User', null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/InvenTree/stock/serializers.py b/InvenTree/stock/serializers.py index 69cb726f73..622f93e620 100644 --- a/InvenTree/stock/serializers.py +++ b/InvenTree/stock/serializers.py @@ -193,6 +193,16 @@ class LocationSerializer(InvenTreeModelSerializer): class StockItemAttachmentSerializer(InvenTreeModelSerializer): """ Serializer for StockItemAttachment model """ + def __init_(self, *args, **kwargs): + user_detail = kwargs.pop('user_detail', False) + + super().__init__(*args, **kwargs) + + if user_detail is not True: + self.fields.pop('user_detail') + + user_detail = UserSerializerBrief(source='user', read_only=True) + class Meta: model = StockItemAttachment @@ -200,7 +210,9 @@ class StockItemAttachmentSerializer(InvenTreeModelSerializer): 'pk', 'stock_item', 'attachment', - 'comment' + 'comment', + 'user', + 'user_detail', ] diff --git a/InvenTree/stock/templates/stock/item_attachments.html b/InvenTree/stock/templates/stock/item_attachments.html index 6aeff554d0..d8210a5c65 100644 --- a/InvenTree/stock/templates/stock/item_attachments.html +++ b/InvenTree/stock/templates/stock/item_attachments.html @@ -22,6 +22,7 @@