mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 04:55:44 +00:00
Unallocate stock against a particular line item
This commit is contained in:
@ -81,6 +81,11 @@ class UnallocateBuildForm(HelperForm):
|
||||
widget=forms.HiddenInput()
|
||||
)
|
||||
|
||||
part_id = forms.IntegerField(
|
||||
required=False,
|
||||
widget=forms.HiddenInput(),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = Build
|
||||
fields = [
|
||||
|
@ -363,7 +363,7 @@ class Build(MPTTModel):
|
||||
return allocations
|
||||
|
||||
@transaction.atomic
|
||||
def unallocateStock(self, output=None):
|
||||
def unallocateStock(self, output=None, part=None):
|
||||
"""
|
||||
Deletes all stock allocations for this build.
|
||||
|
||||
@ -377,6 +377,9 @@ class Build(MPTTModel):
|
||||
if output:
|
||||
allocations = allocations.filter(install_into=output.pk)
|
||||
|
||||
if part:
|
||||
allocations = allocations.filter(stock_item__part=part)
|
||||
|
||||
# Remove all the allocations
|
||||
allocations.delete()
|
||||
|
||||
|
@ -218,6 +218,12 @@ class BuildUnallocate(AjaxUpdateView):
|
||||
if output:
|
||||
initials['output_id'] = output
|
||||
|
||||
# Pointing to a particular part?
|
||||
part = self.get_param('part')
|
||||
|
||||
if part:
|
||||
initials['part_id'] = part
|
||||
|
||||
return initials
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
@ -234,13 +240,20 @@ class BuildUnallocate(AjaxUpdateView):
|
||||
except (ValueError, StockItem.DoesNotExist):
|
||||
output = None
|
||||
|
||||
part_id = request.POST.get('part_id', None)
|
||||
|
||||
try:
|
||||
part = Part.objects.get(pk=part_id)
|
||||
except (ValueError, Part.DoesNotExist):
|
||||
part = None
|
||||
|
||||
valid = False
|
||||
|
||||
if confirm is False:
|
||||
form.errors['confirm'] = [_('Confirm unallocation of build stock')]
|
||||
form.non_field_errors = [_('Check the confirmation box')]
|
||||
else:
|
||||
build.unallocateStock(output=output)
|
||||
build.unallocateStock(output=output, part=part)
|
||||
valid = True
|
||||
|
||||
data = {
|
||||
|
Reference in New Issue
Block a user