mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Allow duplication of subtitute parts when copying a BOM
This commit is contained in:
parent
f585ee6db7
commit
5dc543618e
@ -1906,6 +1906,9 @@ class Part(MPTTModel):
|
|||||||
|
|
||||||
include_inherited = kwargs.get('include_inherited', False)
|
include_inherited = kwargs.get('include_inherited', False)
|
||||||
|
|
||||||
|
# Should substitute parts be duplicated?
|
||||||
|
copy_substitutes = kwargs.get('copy_substitutes', True)
|
||||||
|
|
||||||
# Copy existing BOM items from another part
|
# Copy existing BOM items from another part
|
||||||
# Note: Inherited BOM Items will *not* be duplicated!!
|
# Note: Inherited BOM Items will *not* be duplicated!!
|
||||||
for bom_item in other.get_bom_items(include_inherited=include_inherited).all():
|
for bom_item in other.get_bom_items(include_inherited=include_inherited).all():
|
||||||
@ -1928,11 +1931,22 @@ class Part(MPTTModel):
|
|||||||
if not bom_item.sub_part.check_add_to_bom(self, raise_error=raise_error):
|
if not bom_item.sub_part.check_add_to_bom(self, raise_error=raise_error):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# Obtain a list of direct substitute parts against this BomItem
|
||||||
|
substitutes = BomItemSubstitute.objects.filter(bom_item=bom_item)
|
||||||
|
|
||||||
# Construct a new BOM item
|
# Construct a new BOM item
|
||||||
bom_item.part = self
|
bom_item.part = self
|
||||||
bom_item.pk = None
|
bom_item.pk = None
|
||||||
|
|
||||||
bom_item.save()
|
bom_item.save()
|
||||||
|
bom_item.refresh_from_db()
|
||||||
|
|
||||||
|
if copy_substitutes:
|
||||||
|
for sub in substitutes:
|
||||||
|
# Duplicate the substitute (and point to the *new* BomItem object)
|
||||||
|
sub.pk = None
|
||||||
|
sub.bom_item = bom_item
|
||||||
|
sub.save()
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def copy_parameters_from(self, other, **kwargs):
|
def copy_parameters_from(self, other, **kwargs):
|
||||||
|
@ -656,6 +656,9 @@ class PartCopyBOMSerializer(serializers.Serializer):
|
|||||||
fields = [
|
fields = [
|
||||||
'part',
|
'part',
|
||||||
'remove_existing',
|
'remove_existing',
|
||||||
|
'copy_substitutes',
|
||||||
|
'include_inherited',
|
||||||
|
'skip_invalid',
|
||||||
]
|
]
|
||||||
|
|
||||||
part = serializers.PrimaryKeyRelatedField(
|
part = serializers.PrimaryKeyRelatedField(
|
||||||
@ -692,6 +695,12 @@ class PartCopyBOMSerializer(serializers.Serializer):
|
|||||||
default=False,
|
default=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
copy_substitutes = serializers.BooleanField(
|
||||||
|
label=_('Copy Substitute Parts'),
|
||||||
|
help_text=_('Copy substitute parts when duplicate BOM items'),
|
||||||
|
default=True,
|
||||||
|
)
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
"""
|
"""
|
||||||
Actually duplicate the BOM
|
Actually duplicate the BOM
|
||||||
@ -706,6 +715,7 @@ class PartCopyBOMSerializer(serializers.Serializer):
|
|||||||
clear=data.get('remove_existing', True),
|
clear=data.get('remove_existing', True),
|
||||||
skip_invalid=data.get('skip_invalid', False),
|
skip_invalid=data.get('skip_invalid', False),
|
||||||
include_inherited=data.get('include_inherited', False),
|
include_inherited=data.get('include_inherited', False),
|
||||||
|
copy_substitutes=data.get('copy_substitutes', True),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -474,6 +474,7 @@ function duplicateBom(part_id, options={}) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
include_inherited: {},
|
include_inherited: {},
|
||||||
|
copy_substitutes: {},
|
||||||
remove_existing: {},
|
remove_existing: {},
|
||||||
skip_invalid: {},
|
skip_invalid: {},
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user