mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add 'completed_by' field to Build
- On Complete() or Cancel() user field is filled in
This commit is contained in:
parent
a70ec0b179
commit
019d5aa4ba
21
InvenTree/build/migrations/0009_build_completed_by.py
Normal file
21
InvenTree/build/migrations/0009_build_completed_by.py
Normal file
@ -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),
|
||||
),
|
||||
]
|
@ -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,
|
||||
|
@ -66,9 +66,9 @@
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if batch.completion_date %}
|
||||
{% if build.completion_date %}
|
||||
<tr>
|
||||
<td>Completed</td><td>{{ build.creation_date }}</td>
|
||||
<td>Completed</td><td>{{ build.completion_date }}{% if build.completed_by %}<span class='badge'>{{ build.completed_by }}</span>{% endif %}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if build.notes %}
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user