diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index e46eb80bf6..c1559d5bf8 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -383,9 +383,7 @@ class AjaxCreateView(AjaxMixin, CreateView): if valid: # Save the object to the database - self.save(self.form) - - self.object = self.get_object() + self.object = self.save(self.form) # Return the PK of the newly-created object data['pk'] = self.object.pk diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index 1cb79b57a1..cd3191fadb 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -322,7 +322,8 @@ class Build(MPTTModel): # No issues! return True - def completeBuild(self, user): + @transaction.atomic + def complete_build(self, user): """ Mark this build as complete """ @@ -335,6 +336,11 @@ class Build(MPTTModel): self.status = BuildStatus.COMPLETE self.save() + # Ensure that there are no longer any BuildItem objects + # which point to thie Build Order + self.allocated_stock.all().delete() + + @transaction.atomic def cancelBuild(self, user): """ Mark the Build as CANCELLED diff --git a/InvenTree/build/templates/build/allocate.html b/InvenTree/build/templates/build/allocate.html index ee5fb10d89..29903c0b70 100644 --- a/InvenTree/build/templates/build/allocate.html +++ b/InvenTree/build/templates/build/allocate.html @@ -15,6 +15,11 @@ InvenTree | Allocate Parts