2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-19 05:25:42 +00:00

Adds API endpoint for "auto allocating" stock items against a build order.

- If stock exists in multiple locations, and the user "does not care" where to take from, simply iterate through and take
This commit is contained in:
Oliver
2022-03-04 15:26:00 +11:00
parent 004ced8030
commit 434f563a41
6 changed files with 214 additions and 5 deletions

View File

@ -2651,7 +2651,7 @@ class BomItem(models.Model, DataImportMixin):
def get_api_url():
return reverse('api-bom-list')
def get_valid_parts_for_allocation(self):
def get_valid_parts_for_allocation(self, allow_variants=True, allow_substitutes=True):
"""
Return a list of valid parts which can be allocated against this BomItem:
@ -2666,13 +2666,14 @@ class BomItem(models.Model, DataImportMixin):
parts.add(self.sub_part)
# Variant parts (if allowed)
if self.allow_variants:
if allow_variants and self.allow_variants:
for variant in self.sub_part.get_descendants(include_self=False):
parts.add(variant)
# Substitute parts
for sub in self.substitutes.all():
parts.add(sub.part)
if allow_substitutes:
for sub in self.substitutes.all():
parts.add(sub.part)
return parts