2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-29 12:06:44 +00:00

Correctly allow "inherited" BOM items to be allocated to a build order

- Some back-end logic was not running correctly
This commit is contained in:
Oliver 2021-12-11 01:05:19 +11:00
parent 2b27fab771
commit d573668f81
2 changed files with 16 additions and 7 deletions

View File

@ -1150,7 +1150,7 @@ class BuildItem(models.Model):
bom_item_valid = False bom_item_valid = False
if self.bom_item: if self.bom_item and self.build:
""" """
A BomItem object has already been assigned. This is valid if: A BomItem object has already been assigned. This is valid if:
@ -1162,8 +1162,11 @@ class BuildItem(models.Model):
iii) The Part referenced by the StockItem is a valid substitute for the BomItem iii) The Part referenced by the StockItem is a valid substitute for the BomItem
""" """
if self.build and self.build.part == self.bom_item.part: if self.build.part == self.bom_item.part:
bom_item_valid = self.bom_item.is_stock_item_valid(self.stock_item)
elif self.bom_item.inherited:
if self.build.part in self.bom_item.part.get_descendants(include_self=False):
bom_item_valid = self.bom_item.is_stock_item_valid(self.stock_item) bom_item_valid = self.bom_item.is_stock_item_valid(self.stock_item)
# If the existing BomItem is *not* valid, try to find a match # If the existing BomItem is *not* valid, try to find a match

View File

@ -309,13 +309,19 @@ class BuildAllocationItemSerializer(serializers.Serializer):
) )
def validate_bom_item(self, bom_item): def validate_bom_item(self, bom_item):
"""
# TODO: Fix this validation - allow for variants and substitutes! Check if the parts match!
"""
build = self.context['build'] build = self.context['build']
# BomItem must point to the same 'part' as the parent build # BomItem should point to the same 'part' as the parent build
if build.part != bom_item.part: if build.part != bom_item.part:
# If not, it may be marked as "inherited" from a parent part
if bom_item.inherited and build.part in bom_item.part.get_descendants(include_self=False):
pass
else:
raise ValidationError(_("bom_item.part must point to the same part as the build order")) raise ValidationError(_("bom_item.part must point to the same part as the build order"))
return bom_item return bom_item