diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index eb168ad547..6ddee71682 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -316,13 +316,13 @@ class AjaxCreateView(AjaxMixin, CreateView): - Handles form validation via AJAX POST requests """ - def pre_save(self, **kwargs): + def pre_save(self, form, request, **kwargs): """ Hook for doing something before the form is validated """ pass - def post_save(self, new_object, **kwargs): + def post_save(self, new_object, request, **kwargs): """ Hook for doing something with the created object after it is saved """ @@ -354,9 +354,9 @@ class AjaxCreateView(AjaxMixin, CreateView): if self.form.is_valid(): - self.pre_save() + self.pre_save(self.form, request) self.object = self.form.save() - self.post_save(self.object) + self.post_save(self.object, request) # Return the PK of the newly-created object data['pk'] = self.object.pk diff --git a/InvenTree/build/migrations/0024_auto_20201020_1144.py b/InvenTree/build/migrations/0024_auto_20201020_1144.py new file mode 100644 index 0000000000..2d7c649cd5 --- /dev/null +++ b/InvenTree/build/migrations/0024_auto_20201020_1144.py @@ -0,0 +1,20 @@ +# Generated by Django 3.0.7 on 2020-10-20 11:44 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('part', '0051_bomitem_optional'), + ('build', '0023_auto_20201020_1009'), + ] + + operations = [ + migrations.AlterField( + model_name='build', + name='part', + field=models.ForeignKey(help_text='Select part to build', limit_choices_to={'active': True, 'assembly': True, 'virtual': False}, on_delete=django.db.models.deletion.CASCADE, related_name='builds', to='part.Part', verbose_name='Part'), + ), + ] diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index ca4bb586fe..3ee6aad426 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -111,7 +111,6 @@ class Build(MPTTModel): on_delete=models.CASCADE, related_name='builds', limit_choices_to={ - 'is_template': False, 'assembly': True, 'active': True, 'virtual': False, @@ -226,6 +225,24 @@ class Build(MPTTModel): return new_ref + def createInitialStockItem(self, user): + """ + Create an initial output StockItem to be completed by this build. + """ + + output = StockModels.StockItem.objects.create( + part=self.part, # Link to the parent part + location=None, # No location (yet) until it is completed + quantity=self.quantity, + batch='', # The 'batch' code is not set until the item is completed + build=self, # Point back to this build + is_building=True, # Mark this StockItem as building + ) + + output.save() + + # TODO - Add a transaction note to the new StockItem + @transaction.atomic def cancelBuild(self, user): """ Mark the Build as CANCELLED diff --git a/InvenTree/build/templates/build/detail.html b/InvenTree/build/templates/build/detail.html index 6abbc69bc5..7d4c21aa5b 100644 --- a/InvenTree/build/templates/build/detail.html +++ b/InvenTree/build/templates/build/detail.html @@ -33,7 +33,20 @@ {% if build.take_from %} {{ build.take_from }} {% else %} - {% trans "Stock can be taken from any available location." %} + {% trans "Stock can be taken from any available location." %} + {% endif %} + + +