diff --git a/InvenTree/build/forms.py b/InvenTree/build/forms.py
index de56ca34f7..57c31ff1db 100644
--- a/InvenTree/build/forms.py
+++ b/InvenTree/build/forms.py
@@ -27,6 +27,18 @@ class EditBuildForm(HelperForm):
]
+class ConfirmBuildForm(HelperForm):
+ """ Form for auto-allocation of stock to a build """
+
+ confirm = forms.BooleanField(required=False, help_text='Confirm')
+
+ class Meta:
+ model = Build
+ fields = [
+ 'confirm'
+ ]
+
+
class CompleteBuildForm(HelperForm):
""" Form for marking a Build as complete """
diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py
index fedcb76403..0b658dee1a 100644
--- a/InvenTree/build/models.py
+++ b/InvenTree/build/models.py
@@ -127,10 +127,10 @@ class Build(models.Model):
- If there are multiple StockItems available, ignore (leave up to the user)
Returns:
- A dict object containing the StockItem objects to be allocated (and the quantities)
+ A list object containing the StockItem objects to be allocated (and the quantities)
"""
- allocations = {}
+ allocations = []
for item in self.part.bom_items.all():
@@ -151,19 +151,37 @@ class Build(models.Model):
# Are there any parts available?
if stock_item.quantity > 0:
+
# Only take as many as are available
if stock_item.quantity < q_required:
q_required = stock_item.quantity
- # Add the item to the allocations list
- allocations[stock_item] = q_required
+ allocation = {
+ 'stock_item': stock_item,
+ 'quantity': q_required,
+ }
+
+ allocations.append(allocation)
return allocations
+ @transaction.atomic
+ def unallocateStock(self):
+ """ Deletes all stock allocations for this build. """
+
+ BuildItem.objects.filter(build=self.id).delete()
+
@transaction.atomic
def autoAllocate(self):
""" Run auto-allocation routine to allocate StockItems to this Build.
+ Returns a list of dict objects with keys like:
+
+ {
+ 'stock_item': item,
+ 'quantity': quantity,
+ }
+
See: getAutoAllocations()
"""
@@ -173,8 +191,8 @@ class Build(models.Model):
# Create a new allocation
build_item = BuildItem(
build=self,
- stock_item=item,
- quantity=allocations[item])
+ stock_item=item['stock_item'],
+ quantity=item['quantity'])
build_item.save()
diff --git a/InvenTree/build/templates/build/allocate.html b/InvenTree/build/templates/build/allocate.html
index 1aa5338551..15061a18b4 100644
--- a/InvenTree/build/templates/build/allocate.html
+++ b/InvenTree/build/templates/build/allocate.html
@@ -18,7 +18,8 @@ InvenTree | Allocate Parts
+
+{% else %}
+No stock could be selected for automatic build allocation.
+{% endif %}
+
+{% endblock %}
\ No newline at end of file
diff --git a/InvenTree/build/templates/build/complete.html b/InvenTree/build/templates/build/complete.html
index 506f766c44..5e9338d656 100644
--- a/InvenTree/build/templates/build/complete.html
+++ b/InvenTree/build/templates/build/complete.html
@@ -7,18 +7,42 @@ Are you sure you want to mark this build as complete?
{% if taking %}
The following items will be removed from stock:
-
+
+
+
+
+
Part
+
Quantity
+
Location
+
{% for item in taking %}
-
{{ item.quantity }} x {{ item.stock_item.part.name }} from {{ item.stock_item.location }}