Add "enabled" field to Label class

- Only list labels which are enabled
- Allows labels to be hidden / disabled without being deleted
This commit is contained in:
Oliver Walters 2020-08-23 09:07:15 +10:00
parent de86418ede
commit 8f1af0f5f9
4 changed files with 27 additions and 2 deletions

View File

@ -8,7 +8,7 @@ from .models import StockItemLabel
class StockItemLabelAdmin(admin.ModelAdmin):
list_display = ('name', 'description', 'label')
list_display = ('name', 'description', 'label', 'filters', 'enabled')
admin.site.register(StockItemLabel, StockItemLabelAdmin)

View File

@ -0,0 +1,18 @@
# Generated by Django 3.0.7 on 2020-08-22 23:04
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('label', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='stockitemlabel',
name='enabled',
field=models.BooleanField(default=True, help_text='Label template is enabled', verbose_name='Enabled'),
),
]

View File

@ -70,6 +70,12 @@ class LabelTemplate(models.Model):
validators=[validateFilterString]
)
enabled = models.BooleanField(
default=True,
help_text=_('Label template is enabled'),
verbose_name=_('Enabled')
)
def get_record_data(self, items):
"""
Return a list of dict objects, one for each item.

View File

@ -310,7 +310,8 @@ class StockItemSelectLabels(AjaxView):
labels = []
for label in StockItemLabel.objects.all():
# Construct a list of StockItemLabel objects which are enabled, and the filters match the selected StockItem
for label in StockItemLabel.objects.filter(enabled=True):
if label.matches_stock_item(item):
labels.append(label)