mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Dramatic speed improvements for build completion
- Might still need to be a background task at some point..
This commit is contained in:
parent
3f03adba72
commit
152801f06f
@ -597,11 +597,17 @@ class Build(MPTTModel):
|
|||||||
|
|
||||||
for build_item in allocated_items:
|
for build_item in allocated_items:
|
||||||
|
|
||||||
# Complete the allocation of stock for that item
|
# TODO: This is VERY SLOW as each deletion from the database takes ~1 second to complete
|
||||||
build_item.completeAllocation(user)
|
# TODO: Use celery / redis to offload the actual object deletion...
|
||||||
|
# REF: https://www.botreetechnologies.com/blog/implementing-celery-using-django-for-background-task-processing
|
||||||
|
# REF: https://code.tutsplus.com/tutorials/using-celery-with-django-for-background-task-processing--cms-28732
|
||||||
|
|
||||||
# Remove the build item from the database
|
|
||||||
build_item.delete()
|
# Complete the allocation of stock for that item
|
||||||
|
build_item.complete_allocation(user)
|
||||||
|
|
||||||
|
# Delete the BuildItem objects from the database
|
||||||
|
allocated_items.all().delete()
|
||||||
|
|
||||||
# Ensure that the output is updated correctly
|
# Ensure that the output is updated correctly
|
||||||
output.build = self
|
output.build = self
|
||||||
@ -900,7 +906,7 @@ class BuildItem(models.Model):
|
|||||||
raise ValidationError(errors)
|
raise ValidationError(errors)
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def completeAllocation(self, user):
|
def complete_allocation(self, user):
|
||||||
"""
|
"""
|
||||||
Complete the allocation of this BuildItem into the output stock item.
|
Complete the allocation of this BuildItem into the output stock item.
|
||||||
|
|
||||||
@ -910,21 +916,22 @@ class BuildItem(models.Model):
|
|||||||
|
|
||||||
item = self.stock_item
|
item = self.stock_item
|
||||||
|
|
||||||
|
# For a trackable part, special consideration needed!
|
||||||
|
if item.part.trackable:
|
||||||
# Split the allocated stock if there are more available than allocated
|
# Split the allocated stock if there are more available than allocated
|
||||||
if item.quantity > self.quantity:
|
if item.quantity > self.quantity:
|
||||||
item = item.splitStock(self.quantity, None, user)
|
item = item.splitStock(self.quantity, None, user)
|
||||||
|
|
||||||
# Update our own reference to the new item
|
# Make sure we are pointing to the new item
|
||||||
self.stock_item = item
|
self.stock_item = item
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
if item.part.trackable:
|
# Install the stock item into the output
|
||||||
# If the part is trackable, install into the build output
|
|
||||||
item.belongs_to = self.install_into
|
item.belongs_to = self.install_into
|
||||||
item.save()
|
item.save()
|
||||||
else:
|
else:
|
||||||
# Part is *not* trackable, so just delete it
|
# Simply remove the items from stock
|
||||||
item.delete()
|
item.take_stock(self.quantity, user)
|
||||||
|
|
||||||
build = models.ForeignKey(
|
build = models.ForeignKey(
|
||||||
Build,
|
Build,
|
||||||
|
@ -92,7 +92,7 @@ function makeBuildOutputActionButtons(output, buildInfo) {
|
|||||||
data: {
|
data: {
|
||||||
output: outputId,
|
output: outputId,
|
||||||
},
|
},
|
||||||
reload: true,
|
success: reloadTable,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user