diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index 924c55b54d..b3ac4e0381 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -153,6 +153,13 @@ class InvenTreeSetting(models.Model): 'validator': bool, }, + 'PART_VIRTUAL': { + 'name': _('Virtual'), + 'description': _('Parts are virtual by default'), + 'default': False, + 'validator': bool, + }, + 'BUILDORDER_REFERENCE_PREFIX': { 'name': _('Build Order Reference Prefix'), 'description': _('Prefix value for build order reference'), diff --git a/InvenTree/part/forms.py b/InvenTree/part/forms.py index 458667f3fe..072e1da8c3 100644 --- a/InvenTree/part/forms.py +++ b/InvenTree/part/forms.py @@ -236,6 +236,7 @@ class EditPartForm(HelperForm): 'trackable', 'purchaseable', 'salable', + 'virtual', ] diff --git a/InvenTree/part/migrations/0061_auto_20210103_2306.py b/InvenTree/part/migrations/0061_auto_20210103_2313.py similarity index 85% rename from InvenTree/part/migrations/0061_auto_20210103_2306.py rename to InvenTree/part/migrations/0061_auto_20210103_2313.py index fa1f8c04c6..ca0c2a277f 100644 --- a/InvenTree/part/migrations/0061_auto_20210103_2306.py +++ b/InvenTree/part/migrations/0061_auto_20210103_2313.py @@ -1,9 +1,10 @@ -# Generated by Django 3.0.7 on 2021-01-03 12:06 +# Generated by Django 3.0.7 on 2021-01-03 12:13 import InvenTree.fields import InvenTree.validators from django.db import migrations, models import django.db.models.deletion +import markdownx.models import mptt.fields import part.settings @@ -61,6 +62,11 @@ class Migration(migrations.Migration): name='name', field=models.CharField(help_text='Part name', max_length=100, validators=[InvenTree.validators.validate_part_name], verbose_name='Name'), ), + migrations.AlterField( + model_name='part', + name='notes', + field=markdownx.models.MarkdownxField(blank=True, help_text='Part notes - supports Markdown formatting', null=True, verbose_name='Notes'), + ), migrations.AlterField( model_name='part', name='revision', @@ -71,4 +77,9 @@ class Migration(migrations.Migration): name='variant_of', field=models.ForeignKey(blank=True, help_text='Is this part a variant of another part?', limit_choices_to={'active': True, 'is_template': True}, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='variants', to='part.Part', verbose_name='Variant Of'), ), + migrations.AlterField( + model_name='part', + name='virtual', + field=models.BooleanField(default=part.settings.part_virtual_default, help_text='Is this a virtual part, such as a software product or license?', verbose_name='Virtual'), + ), ] diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 900e0e5a98..fdd80e71b6 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -802,11 +802,15 @@ class Part(MPTTModel): help_text=_('Is this part active?')) virtual = models.BooleanField( - default=False, + default=part_settings.part_virtual_default, verbose_name=_('Virtual'), help_text=_('Is this a virtual part, such as a software product or license?')) - notes = MarkdownxField(blank=True, null=True, help_text=_('Part notes - supports Markdown formatting')) + notes = MarkdownxField( + blank=True, null=True, + verbose_name=_('Notes'), + help_text=_('Part notes - supports Markdown formatting') + ) bom_checksum = models.CharField(max_length=128, blank=True, help_text=_('Stored BOM checksum')) diff --git a/InvenTree/part/settings.py b/InvenTree/part/settings.py index 1705f96a80..801b4dd2ec 100644 --- a/InvenTree/part/settings.py +++ b/InvenTree/part/settings.py @@ -24,6 +24,14 @@ def part_template_default(): return InvenTreeSetting.get_setting('PART_TEMPLATE') +def part_virtual_default(): + """ + Returns the default value for the 'is_virtual' field of Part object + """ + + return InvenTreeSetting.get_setting('PART_VIRTUAL') + + def part_component_default(): """ Returns the default value for the 'component' field of a Part object diff --git a/InvenTree/templates/InvenTree/settings/part.html b/InvenTree/templates/InvenTree/settings/part.html index 415449a559..fe46911dae 100644 --- a/InvenTree/templates/InvenTree/settings/part.html +++ b/InvenTree/templates/InvenTree/settings/part.html @@ -25,6 +25,7 @@ {% include "InvenTree/settings/setting.html" with key="PART_TRACKABLE" icon="fa-directions" %} {% include "InvenTree/settings/setting.html" with key="PART_PURCHASEABLE" icon="fa-shopping-cart" %} {% include "InvenTree/settings/setting.html" with key="PART_SALABLE" icon="fa-dollar-sign" %} + {% include "InvenTree/settings/setting.html" with key="PART_VIRTUAL" icon="fa-ghost" %}