mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 21:15:41 +00:00
Merge pull request #2931 from SchrodingersGat/more-api-functionality
Converting more forms to the API
This commit is contained in:
@ -95,24 +95,6 @@ class EditPartParameterTemplateForm(HelperForm):
|
||||
]
|
||||
|
||||
|
||||
class EditCategoryForm(HelperForm):
|
||||
""" Form for editing a PartCategory object """
|
||||
|
||||
field_prefix = {
|
||||
'default_keywords': 'fa-key',
|
||||
}
|
||||
|
||||
class Meta:
|
||||
model = PartCategory
|
||||
fields = [
|
||||
'parent',
|
||||
'name',
|
||||
'description',
|
||||
'default_location',
|
||||
'default_keywords',
|
||||
]
|
||||
|
||||
|
||||
class EditCategoryParameterTemplateForm(HelperForm):
|
||||
""" Form for editing a PartCategoryParameterTemplate object """
|
||||
|
||||
|
@ -491,7 +491,7 @@ class Part(MPTTModel):
|
||||
def __str__(self):
|
||||
return f"{self.full_name} - {self.description}"
|
||||
|
||||
def get_parts_in_bom(self):
|
||||
def get_parts_in_bom(self, **kwargs):
|
||||
"""
|
||||
Return a list of all parts in the BOM for this part.
|
||||
Takes into account substitutes, variant parts, and inherited BOM items
|
||||
@ -499,27 +499,22 @@ class Part(MPTTModel):
|
||||
|
||||
parts = set()
|
||||
|
||||
for bom_item in self.get_bom_items():
|
||||
for bom_item in self.get_bom_items(**kwargs):
|
||||
for part in bom_item.get_valid_parts_for_allocation():
|
||||
parts.add(part)
|
||||
|
||||
return parts
|
||||
|
||||
def check_if_part_in_bom(self, other_part):
|
||||
def check_if_part_in_bom(self, other_part, **kwargs):
|
||||
"""
|
||||
Check if the other_part is in the BOM for this part.
|
||||
Check if the other_part is in the BOM for *this* part.
|
||||
|
||||
Note:
|
||||
- Accounts for substitute parts
|
||||
- Accounts for variant BOMs
|
||||
"""
|
||||
|
||||
for bom_item in self.get_bom_items():
|
||||
if other_part in bom_item.get_valid_parts_for_allocation():
|
||||
return True
|
||||
|
||||
# No matches found
|
||||
return False
|
||||
return other_part in self.get_parts_in_bom(**kwargs)
|
||||
|
||||
def check_add_to_bom(self, parent, raise_error=False, recursive=True):
|
||||
"""
|
||||
|
@ -43,7 +43,7 @@ class BomItemTest(TestCase):
|
||||
|
||||
self.assertIn(self.orphan, parts)
|
||||
|
||||
# TODO: Tests for multi-level BOMs
|
||||
self.assertTrue(self.bob.check_if_part_in_bom(self.orphan))
|
||||
|
||||
def test_used_in(self):
|
||||
self.assertEqual(self.bob.used_in_count, 1)
|
||||
|
@ -1001,45 +1001,6 @@ class CategoryDetail(InvenTreeRoleMixin, DetailView):
|
||||
return context
|
||||
|
||||
|
||||
class CategoryEdit(AjaxUpdateView):
|
||||
"""
|
||||
Update view to edit a PartCategory
|
||||
"""
|
||||
|
||||
model = PartCategory
|
||||
form_class = part_forms.EditCategoryForm
|
||||
ajax_template_name = 'modal_form.html'
|
||||
ajax_form_title = _('Edit Part Category')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(CategoryEdit, self).get_context_data(**kwargs).copy()
|
||||
|
||||
try:
|
||||
context['category'] = self.get_object()
|
||||
except:
|
||||
pass
|
||||
|
||||
return context
|
||||
|
||||
def get_form(self):
|
||||
""" Customize form data for PartCategory editing.
|
||||
|
||||
Limit the choices for 'parent' field to those which make sense
|
||||
"""
|
||||
|
||||
form = super(AjaxUpdateView, self).get_form()
|
||||
|
||||
category = self.get_object()
|
||||
|
||||
# Remove any invalid choices for the parent category part
|
||||
parent_choices = PartCategory.objects.all()
|
||||
parent_choices = parent_choices.exclude(id__in=category.getUniqueChildren())
|
||||
|
||||
form.fields['parent'].queryset = parent_choices
|
||||
|
||||
return form
|
||||
|
||||
|
||||
class CategoryDelete(AjaxDeleteView):
|
||||
"""
|
||||
Delete view to delete a PartCategory
|
||||
|
Reference in New Issue
Block a user