mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #210 from SchrodingersGat/completed_by
Add 'completed_by' field to Build
This commit is contained in:
commit
598ddaace9
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 datetime import datetime
|
||||||
|
|
||||||
|
from django.contrib.auth.models import User
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
@ -116,13 +117,19 @@ class Build(models.Model):
|
|||||||
|
|
||||||
completion_date = models.DateField(null=True, blank=True)
|
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')
|
URL = models.URLField(blank=True, help_text='Link to external URL')
|
||||||
|
|
||||||
notes = models.TextField(blank=True)
|
notes = models.TextField(blank=True)
|
||||||
""" Notes attached to each build output """
|
""" Notes attached to each build output """
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def cancelBuild(self):
|
def cancelBuild(self, user):
|
||||||
""" Mark the Build as CANCELLED
|
""" Mark the Build as CANCELLED
|
||||||
|
|
||||||
- Delete any pending BuildItem objects (but do not remove items from stock)
|
- Delete any pending BuildItem objects (but do not remove items from stock)
|
||||||
@ -135,6 +142,7 @@ class Build(models.Model):
|
|||||||
|
|
||||||
# Date of 'completion' is the date the build was cancelled
|
# Date of 'completion' is the date the build was cancelled
|
||||||
self.completion_date = datetime.now().date()
|
self.completion_date = datetime.now().date()
|
||||||
|
self.completed_by = user
|
||||||
|
|
||||||
self.status = self.CANCELLED
|
self.status = self.CANCELLED
|
||||||
self.save()
|
self.save()
|
||||||
@ -166,6 +174,8 @@ class Build(models.Model):
|
|||||||
# Mark the date of completion
|
# Mark the date of completion
|
||||||
self.completion_date = datetime.now().date()
|
self.completion_date = datetime.now().date()
|
||||||
|
|
||||||
|
self.completed_by = user
|
||||||
|
|
||||||
# Add stock of the newly created item
|
# Add stock of the newly created item
|
||||||
item = StockItem.objects.create(
|
item = StockItem.objects.create(
|
||||||
part=self.part,
|
part=self.part,
|
||||||
|
@ -66,9 +66,9 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if batch.completion_date %}
|
{% if build.completion_date %}
|
||||||
<tr>
|
<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>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if build.notes %}
|
{% if build.notes %}
|
||||||
|
@ -56,7 +56,7 @@ class BuildCancel(AjaxView):
|
|||||||
|
|
||||||
build = get_object_or_404(Build, pk=self.kwargs['pk'])
|
build = get_object_or_404(Build, pk=self.kwargs['pk'])
|
||||||
|
|
||||||
build.cancelBuild()
|
build.cancelBuild(request.user)
|
||||||
|
|
||||||
return self.renderJsonResponse(request, None)
|
return self.renderJsonResponse(request, None)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user