mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add model for StockLocation label
This commit is contained in:
parent
80c7ee6dab
commit
f0fa092c66
@ -3,12 +3,13 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from .models import StockItemLabel
|
from .models import StockItemLabel, StockLocationLabel
|
||||||
|
|
||||||
|
|
||||||
class StockItemLabelAdmin(admin.ModelAdmin):
|
class LabelAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
list_display = ('name', 'description', 'label', 'filters', 'enabled')
|
list_display = ('name', 'description', 'label', 'filters', 'enabled')
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(StockItemLabel, StockItemLabelAdmin)
|
admin.site.register(StockItemLabel, LabelAdmin)
|
||||||
|
admin.site.register(StockLocationLabel, LabelAdmin)
|
||||||
|
30
InvenTree/label/migrations/0003_stocklocationlabel.py
Normal file
30
InvenTree/label/migrations/0003_stocklocationlabel.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# Generated by Django 3.0.7 on 2021-01-08 12:06
|
||||||
|
|
||||||
|
import InvenTree.helpers
|
||||||
|
import django.core.validators
|
||||||
|
from django.db import migrations, models
|
||||||
|
import label.models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('label', '0002_stockitemlabel_enabled'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='StockLocationLabel',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(help_text='Label name', max_length=100, unique=True)),
|
||||||
|
('description', models.CharField(blank=True, help_text='Label description', max_length=250, null=True)),
|
||||||
|
('label', models.FileField(help_text='Label template file', upload_to=label.models.rename_label, validators=[django.core.validators.FileExtensionValidator(allowed_extensions=['html'])])),
|
||||||
|
('filters', models.CharField(blank=True, help_text='Query filters (comma-separated list of key=value pairs', max_length=250, validators=[InvenTree.helpers.validateFilterString])),
|
||||||
|
('enabled', models.BooleanField(default=True, help_text='Label template is enabled', verbose_name='Enabled')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'abstract': False,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
@ -17,7 +17,7 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
|
|
||||||
from InvenTree.helpers import validateFilterString, normalize
|
from InvenTree.helpers import validateFilterString, normalize
|
||||||
|
|
||||||
from stock.models import StockItem
|
from stock.models import StockItem, StockLocation
|
||||||
|
|
||||||
|
|
||||||
def rename_label(instance, filename):
|
def rename_label(instance, filename):
|
||||||
@ -157,3 +157,39 @@ class StockItemLabel(LabelTemplate):
|
|||||||
})
|
})
|
||||||
|
|
||||||
return records
|
return records
|
||||||
|
|
||||||
|
|
||||||
|
class StockLocationLabel(LabelTemplate):
|
||||||
|
"""
|
||||||
|
Template for printing StockLocation labels
|
||||||
|
"""
|
||||||
|
|
||||||
|
SUBDIR = "stocklocation"
|
||||||
|
|
||||||
|
def matches_stock_location(self, location):
|
||||||
|
"""
|
||||||
|
Test if this label template matches a given StockLocation object
|
||||||
|
"""
|
||||||
|
|
||||||
|
filters = validateFilterString(self.filters)
|
||||||
|
|
||||||
|
locs = StockLocation.objects.filter(**filters)
|
||||||
|
|
||||||
|
locs = locs.filter(pk=location.pk)
|
||||||
|
|
||||||
|
return locs.exists()
|
||||||
|
|
||||||
|
def get_record_data(self, locations):
|
||||||
|
"""
|
||||||
|
Generate context data for each provided StockLocation
|
||||||
|
"""
|
||||||
|
|
||||||
|
records = []
|
||||||
|
|
||||||
|
for loc in locations:
|
||||||
|
|
||||||
|
records.append({
|
||||||
|
'location': location,
|
||||||
|
})
|
||||||
|
|
||||||
|
return records
|
||||||
|
Loading…
Reference in New Issue
Block a user