mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Improve edit form for BuildItem
- Hide the build field - Limit the choices for StockItem (don't let user change the allocation!)
This commit is contained in:
parent
a4aec425be
commit
09b7846310
@ -260,13 +260,13 @@ class BuildItem(models.Model):
|
||||
|
||||
if self.stock_item is not None and self.stock_item.part is not None:
|
||||
if self.stock_item.part not in self.build.part.required_parts():
|
||||
errors['stock_item'] = _("Selected stock item not found in BOM for part '{p}'".format(p=str(self.build.part)))
|
||||
errors['stock_item'] = [_("Selected stock item not found in BOM for part '{p}'".format(p=self.build.part.name))]
|
||||
|
||||
if self.stock_item is not None and self.quantity > self.stock_item.quantity:
|
||||
errors['quantity'] = _("Allocated quantity ({n}) must not exceed available quantity ({q})".format(
|
||||
errors['quantity'] = [_("Allocated quantity ({n}) must not exceed available quantity ({q})".format(
|
||||
n=self.quantity,
|
||||
q=self.stock_item.quantity
|
||||
))
|
||||
))]
|
||||
|
||||
if len(errors) > 0:
|
||||
raise ValidationError(errors)
|
||||
|
@ -13,7 +13,7 @@ from django.forms import HiddenInput
|
||||
from part.models import Part
|
||||
from .models import Build, BuildItem
|
||||
from .forms import EditBuildForm, EditBuildItemForm, CompleteBuildForm
|
||||
from stock.models import StockLocation
|
||||
from stock.models import StockLocation, StockItem
|
||||
|
||||
from InvenTree.views import AjaxView, AjaxUpdateView, AjaxCreateView, AjaxDeleteView
|
||||
|
||||
@ -328,3 +328,25 @@ class BuildItemEdit(AjaxUpdateView):
|
||||
return {
|
||||
'info': 'Updated Build Item',
|
||||
}
|
||||
|
||||
def get_form(self):
|
||||
""" Create form for editing a BuildItem.
|
||||
|
||||
- Limit the StockItem options to items that match the part
|
||||
"""
|
||||
|
||||
build_item = self.get_object()
|
||||
|
||||
form = super(BuildItemEdit, self).get_form()
|
||||
|
||||
query = StockItem.objects.all()
|
||||
|
||||
if build_item.stock_item:
|
||||
part_id = build_item.stock_item.part.id
|
||||
query = query.filter(part=part_id)
|
||||
|
||||
form.fields['stock_item'].queryset = query
|
||||
|
||||
form.fields['build'].widget = HiddenInput()
|
||||
|
||||
return form
|
||||
|
Loading…
Reference in New Issue
Block a user