From 72c43d0c2d9b22bd3d73b762cfc5a89ab321ae53 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 25 Apr 2020 23:59:28 +1000 Subject: [PATCH] Bug fix for build completion form --- .../migrations/0015_auto_20200425_1350.py | 26 +++++++++++++++++++ InvenTree/build/models.py | 6 +---- InvenTree/build/templates/build/allocate.html | 11 ++++++++ InvenTree/build/views.py | 8 +++--- InvenTree/part/templates/part/tabs.html | 2 +- 5 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 InvenTree/build/migrations/0015_auto_20200425_1350.py diff --git a/InvenTree/build/migrations/0015_auto_20200425_1350.py b/InvenTree/build/migrations/0015_auto_20200425_1350.py new file mode 100644 index 0000000000..4f57df066e --- /dev/null +++ b/InvenTree/build/migrations/0015_auto_20200425_1350.py @@ -0,0 +1,26 @@ +# Generated by Django 3.0.5 on 2020-04-25 13:50 + +import django.core.validators +from django.db import migrations, models +import django.db.models.deletion +import mptt.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('build', '0014_auto_20200425_1243'), + ] + + operations = [ + migrations.AlterField( + model_name='build', + name='parent', + field=mptt.fields.TreeForeignKey(blank=True, help_text='Parent build to which this build is allocated', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='children', to='build.Build', verbose_name='Parent Build'), + ), + migrations.AlterField( + model_name='builditem', + name='quantity', + field=models.DecimalField(decimal_places=5, default=1, help_text='Stock quantity to allocate to build', max_digits=15, validators=[django.core.validators.MinValueValidator(0)]), + ), + ] diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index 6d5ac73081..0f2084f019 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -329,8 +329,6 @@ class Build(MPTTModel): for item in bom_items: part = item.sub_part - print("Checking:", part) - if not self.isPartFullyAllocated(part): return False @@ -353,8 +351,6 @@ class Build(MPTTModel): except BomItem.DoesNotExist: q = 0 - print("required quantity:", q, "*", self.quantity) - return q * self.quantity def getAllocatedQuantity(self, part): @@ -499,6 +495,6 @@ class BuildItem(models.Model): decimal_places=5, max_digits=15, default=1, - validators=[MinValueValidator(1)], + validators=[MinValueValidator(0)], help_text=_('Stock quantity to allocate to build') ) diff --git a/InvenTree/build/templates/build/allocate.html b/InvenTree/build/templates/build/allocate.html index 725e612947..55ce042087 100644 --- a/InvenTree/build/templates/build/allocate.html +++ b/InvenTree/build/templates/build/allocate.html @@ -70,6 +70,17 @@ InvenTree | Allocate Parts build: {{ build.id }}, quantity: getUnallocated(row), }, + secondary: [ + { + field: 'stock_item', + label: '{% trans "New Stock Item" %}', + title: '{% trans "Create new Stock Item"', + url: '{% url "stock-item-create" %}', + data: { + part: row.sub_part, + }, + }, + ] }); }); diff --git a/InvenTree/build/views.py b/InvenTree/build/views.py index 3db0a7503e..6f651a7628 100644 --- a/InvenTree/build/views.py +++ b/InvenTree/build/views.py @@ -261,13 +261,13 @@ class BuildComplete(AjaxUpdateView): try: location = StockLocation.objects.get(id=loc_id) valid = True - except StockLocation.DoesNotExist: + except (ValueError, StockLocation.DoesNotExist): form.errors['location'] = [_('Invalid location selected')] serials = [] if build.part.trackable: - # A build for a trackable part must specify serial numbers + # A build for a trackable part may optionally specify serial numbers. sn = request.POST.get('serial_numbers', '') @@ -295,7 +295,9 @@ class BuildComplete(AjaxUpdateView): valid = False if valid: - build.completeBuild(location, serials, request.user) + if not build.completeBuild(location, serials, request.user): + form.non_field_errors = [('Build could not be completed')] + valid = False data = { 'form_valid': valid, diff --git a/InvenTree/part/templates/part/tabs.html b/InvenTree/part/templates/part/tabs.html index 4f23e345b6..b612106706 100644 --- a/InvenTree/part/templates/part/tabs.html +++ b/InvenTree/part/templates/part/tabs.html @@ -25,7 +25,7 @@ {% trans "BOM" %}{{ part.bom_count }} - {% trans "Build" %}{{ part.active_builds|length }} + {% trans "Build Orders" %}{{ part.active_builds|length }} {% endif %} {% if part.component or part.used_in_count > 0 %}