2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-06 05:30:56 +00:00

Move "build unallocate" functionality to the API

- Much much simpler now!
- Filtering is against bom_item, not part
- Fixes a bug with the new (reasonably complex) substitution framework
This commit is contained in:
Oliver
2021-10-14 10:32:43 +11:00
parent 1cbce5dfbf
commit 7dfffcd5d3
10 changed files with 161 additions and 201 deletions

View File

@ -587,9 +587,13 @@ class Build(MPTTModel):
self.save()
@transaction.atomic
def unallocateOutput(self, output, part=None):
def unallocateStock(self, bom_item=None, output=None):
"""
Unallocate all stock which are allocated against the provided "output" (StockItem)
Unallocate stock from this Build
arguments:
- bom_item: Specify a particular BomItem to unallocate stock against
- output: Specify a particular StockItem (output) to unallocate stock against
"""
allocations = BuildItem.objects.filter(
@ -597,34 +601,8 @@ class Build(MPTTModel):
install_into=output
)
if part:
allocations = allocations.filter(stock_item__part=part)
allocations.delete()
@transaction.atomic
def unallocateUntracked(self, part=None):
"""
Unallocate all "untracked" stock
"""
allocations = BuildItem.objects.filter(
build=self,
install_into=None
)
if part:
allocations = allocations.filter(stock_item__part=part)
allocations.delete()
@transaction.atomic
def unallocateAll(self):
"""
Deletes all stock allocations for this build.
"""
allocations = BuildItem.objects.filter(build=self)
if bom_item:
allocations = allocations.filter(bom_item=bom_item)
allocations.delete()