2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-15 01:11:27 +00:00

Adds API endpoint for installing stock items into other stock items

- Requires more filtering for the Part API
- Adds more BOM related functionality for Part model
- Removes old server-side form
This commit is contained in:
Oliver
2022-02-17 17:03:17 +11:00
parent 023037e766
commit 0604e1a127
12 changed files with 209 additions and 254 deletions

View File

@ -483,6 +483,36 @@ class Part(MPTTModel):
def __str__(self):
return f"{self.full_name} - {self.description}"
def get_parts_in_bom(self):
"""
Return a list of all parts in the BOM for this part.
Takes into account substitutes, variant parts, and inherited BOM items
"""
parts = set()
for bom_item in self.get_bom_items():
for part in bom_item.get_valid_parts_for_allocation():
parts.add(part)
return parts
def check_if_part_in_bom(self, other_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
def check_add_to_bom(self, parent, raise_error=False, recursive=True):
"""
Check if this Part can be added to the BOM of another part.