diff --git a/InvenTree/build/migrations/0009_build_completed_by.py b/InvenTree/build/migrations/0009_build_completed_by.py new file mode 100644 index 0000000000..dc6c05a3f7 --- /dev/null +++ b/InvenTree/build/migrations/0009_build_completed_by.py @@ -0,0 +1,21 @@ +# Generated by Django 2.2 on 2019-05-02 21:26 + +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), + ('build', '0008_auto_20190501_2344'), + ] + + operations = [ + migrations.AddField( + model_name='build', + name='completed_by', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='builds_completed', to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index 0e0068fdaf..164e5b1aee 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -7,6 +7,7 @@ from __future__ import unicode_literals from datetime import datetime +from django.contrib.auth.models import User from django.utils.translation import ugettext as _ from django.core.exceptions import ValidationError @@ -115,6 +116,13 @@ class Build(models.Model): creation_date = models.DateField(auto_now=True, editable=False) completion_date = models.DateField(null=True, blank=True) + + completed_by = models.ForeignKey(User, + on_delete=models.SET_NULL, + blank=True, null=True, + related_name='builds_completed' + ) + URL = models.URLField(blank=True, help_text='Link to external URL') @@ -122,7 +130,7 @@ class Build(models.Model): """ Notes attached to each build output """ @transaction.atomic - def cancelBuild(self): + def cancelBuild(self, user): """ Mark the Build as CANCELLED - Delete any pending BuildItem objects (but do not remove items from stock) @@ -133,8 +141,10 @@ class Build(models.Model): for item in self.allocated_stock.all(): item.delete() + # Date of 'completion' is the date the build was cancelled self.completion_date = datetime.now().date() + self.completed_by = user self.status = self.CANCELLED self.save() @@ -166,6 +176,8 @@ class Build(models.Model): # Mark the date of completion self.completion_date = datetime.now().date() + self.completed_by = user + # Add stock of the newly created item item = StockItem.objects.create( part=self.part, diff --git a/InvenTree/build/templates/build/detail.html b/InvenTree/build/templates/build/detail.html index 1960ed4ef5..96fad2caa5 100644 --- a/InvenTree/build/templates/build/detail.html +++ b/InvenTree/build/templates/build/detail.html @@ -66,9 +66,9 @@ {% endif %} -{% if batch.completion_date %} +{% if build.completion_date %} - Completed{{ build.creation_date }} + Completed{{ build.completion_date }}{% if build.completed_by %}{{ build.completed_by }}{% endif %} {% endif %} {% if build.notes %} diff --git a/InvenTree/build/views.py b/InvenTree/build/views.py index 6d74d2b19b..3892f28843 100644 --- a/InvenTree/build/views.py +++ b/InvenTree/build/views.py @@ -56,7 +56,7 @@ class BuildCancel(AjaxView): build = get_object_or_404(Build, pk=self.kwargs['pk']) - build.cancelBuild() + build.cancelBuild(request.user) return self.renderJsonResponse(request, None)