2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-26 16:50:56 +00:00

Implement global settings for assembly and template values of Part model

This commit is contained in:
Oliver Walters
2021-01-03 23:06:51 +11:00
parent 9fa37a9156
commit 6c7b648133
5 changed files with 160 additions and 27 deletions

@ -640,36 +640,69 @@ class Part(MPTTModel):
parent_part.clean()
parent_part.save()
name = models.CharField(max_length=100, blank=False,
help_text=_('Part name'),
validators=[validators.validate_part_name]
)
name = models.CharField(
max_length=100, blank=False,
help_text=_('Part name'),
verbose_name=_('Name'),
validators=[validators.validate_part_name]
)
is_template = models.BooleanField(default=False, help_text=_('Is this part a template part?'))
is_template = models.BooleanField(
default=part_settings.part_template_default,
verbose_name=_('Is Template'),
help_text=_('Is this part a template part?')
)
variant_of = models.ForeignKey('part.Part', related_name='variants',
null=True, blank=True,
limit_choices_to={
'is_template': True,
'active': True,
},
on_delete=models.SET_NULL,
help_text=_('Is this part a variant of another part?'))
variant_of = models.ForeignKey(
'part.Part', related_name='variants',
null=True, blank=True,
limit_choices_to={
'is_template': True,
'active': True,
},
on_delete=models.SET_NULL,
help_text=_('Is this part a variant of another part?'),
verbose_name=_('Variant Of'),
)
description = models.CharField(max_length=250, blank=False, help_text=_('Part description'))
description = models.CharField(
max_length=250, blank=False,
verbose_name=_('Description'),
help_text=_('Part description')
)
keywords = models.CharField(max_length=250, blank=True, null=True, help_text=_('Part keywords to improve visibility in search results'))
keywords = models.CharField(
max_length=250, blank=True, null=True,
verbose_name=_('Keywords'),
help_text=_('Part keywords to improve visibility in search results')
)
category = TreeForeignKey(PartCategory, related_name='parts',
null=True, blank=True,
on_delete=models.DO_NOTHING,
help_text=_('Part category'))
category = TreeForeignKey(
PartCategory, related_name='parts',
null=True, blank=True,
on_delete=models.DO_NOTHING,
verbose_name=_('Category'),
help_text=_('Part category')
)
IPN = models.CharField(max_length=100, blank=True, null=True, help_text=_('Internal Part Number'), validators=[validators.validate_part_ipn])
IPN = models.CharField(
max_length=100, blank=True, null=True,
verbose_name=_('IPN'),
help_text=_('Internal Part Number'),
validators=[validators.validate_part_ipn]
)
revision = models.CharField(max_length=100, blank=True, null=True, help_text=_('Part revision or version number'))
revision = models.CharField(
max_length=100, blank=True, null=True,
help_text=_('Part revision or version number'),
verbose_name=_('Revision'),
)
link = InvenTreeURLField(blank=True, null=True, help_text=_('Link to external URL'))
link = InvenTreeURLField(
blank=True, null=True,
verbose_name=_('Link'),
help_text=_('Link to external URL')
)
image = StdImageField(
upload_to=rename_part_image,
@ -679,10 +712,13 @@ class Part(MPTTModel):
delete_orphans=True,
)
default_location = TreeForeignKey('stock.StockLocation', on_delete=models.SET_NULL,
blank=True, null=True,
help_text=_('Where is this item normally stored?'),
related_name='default_parts')
default_location = TreeForeignKey('stock.StockLocation',
on_delete=models.SET_NULL,
blank=True, null=True,
help_text=_('Where is this item normally stored?'),
related_name='default_parts',
verbose_name=_('Default Location'),
)
def get_default_location(self):
""" Get the default location for a Part (may be None).
@ -733,7 +769,7 @@ class Part(MPTTModel):
units = models.CharField(max_length=20, default="", blank=True, null=True, help_text=_('Stock keeping units for this part'))
assembly = models.BooleanField(
default=False,
default=part_settings.part_assembly_default,
verbose_name=_('Assembly'),
help_text=_('Can this part be built from other parts?')
)