mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Limit available choicse in form
- Only allow selection of StockItem which matches the correct part
This commit is contained in:
parent
0208c6efe6
commit
db5521f02e
@ -132,6 +132,11 @@ class BuildItem(models.Model):
|
||||
quantity: Number of units allocated
|
||||
"""
|
||||
|
||||
def get_absolute_url(self):
|
||||
# TODO - Fix!
|
||||
return '/build/item/{pk}/'.format(pk=self.id)
|
||||
#return reverse('build-detail', kwargs={'pk': self.id})
|
||||
|
||||
class Meta:
|
||||
unique_together = [
|
||||
('build', 'stock_item'),
|
||||
|
@ -8,6 +8,7 @@ from __future__ import unicode_literals
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
from django.views.generic import DetailView, ListView
|
||||
from django.forms import HiddenInput
|
||||
|
||||
from part.models import Part
|
||||
from .models import Build, BuildItem
|
||||
@ -137,6 +138,30 @@ class BuildItemCreate(AjaxCreateView):
|
||||
ajax_template_name = 'modal_form.html'
|
||||
ajax_form_title = 'Allocate new Part'
|
||||
|
||||
def get_form(self):
|
||||
""" Create Form for making / editing new Part object """
|
||||
|
||||
form = super(AjaxCreateView, self).get_form()
|
||||
|
||||
# If the Build object is specified, hide the input field.
|
||||
# We do not want the users to be able to move a BuildItem to a different build
|
||||
if form['build'].value() is not None:
|
||||
form.fields['build'].widget = HiddenInput()
|
||||
|
||||
# If the sub_part is supplied, limit to matching stock items
|
||||
part_id = self.get_param('part')
|
||||
|
||||
if part_id:
|
||||
try:
|
||||
part = Part.objects.get(pk=part_id)
|
||||
query = form.fields['stock_item'].queryset
|
||||
query = query.filter(part=part_id)
|
||||
form.fields['stock_item'].queryset = query
|
||||
except Part.DoesNotExist:
|
||||
pass
|
||||
|
||||
return form
|
||||
|
||||
def get_initial(self):
|
||||
""" Provide initial data for BomItem. Look for the folllowing in the GET data:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user