Merge remote-tracking branch 'inventree/master'

This commit is contained in:
Oliver Walters 2021-01-19 11:06:31 +11:00
commit 8cb6b7d8d4
3 changed files with 59 additions and 10 deletions

View File

@ -7,7 +7,7 @@ import django
import common.models
INVENTREE_SW_VERSION = "0.1.5 pre"
INVENTREE_SW_VERSION = "0.1.6 pre"
def inventreeInstanceName():

View File

@ -0,0 +1,35 @@
# Generated by Django 3.0.7 on 2021-01-18 21:15
import django.core.validators
from django.db import migrations, models
import report.models
class Migration(migrations.Migration):
dependencies = [
('report', '0004_auto_20200823_1104'),
]
operations = [
migrations.AlterField(
model_name='testreport',
name='description',
field=models.CharField(help_text='Report template description', max_length=250, verbose_name='Description'),
),
migrations.AlterField(
model_name='testreport',
name='filters',
field=models.CharField(blank=True, help_text='Part query filters (comma-separated list of key=value pairs)', max_length=250, validators=[report.models.validate_stock_item_report_filters], verbose_name='Filters'),
),
migrations.AlterField(
model_name='testreport',
name='name',
field=models.CharField(help_text='Template name', max_length=100, unique=True, verbose_name='Name'),
),
migrations.AlterField(
model_name='testreport',
name='template',
field=models.FileField(help_text='Report template file', upload_to=report.models.rename_template, validators=[django.core.validators.FileExtensionValidator(allowed_extensions=['html', 'htm', 'tex'])], verbose_name='Template'),
),
]

View File

@ -57,6 +57,11 @@ def rename_template(instance, filename):
return os.path.join('report', 'report_template', instance.getSubdir(), filename)
def validate_stock_item_report_filters(filters):
return validateFilterString(filters, model=stock.models.StockItem)
class WeasyprintReportMixin(WeasyTemplateResponseMixin):
"""
Class for rendering a HTML template to a PDF.
@ -144,29 +149,28 @@ class ReportTemplateBase(models.Model):
name = models.CharField(
blank=False, max_length=100,
verbose_name=_('Name'),
help_text=_('Template name'),
unique=True,
)
template = models.FileField(
upload_to=rename_template,
verbose_name=_('Template'),
help_text=_("Report template file"),
validators=[FileExtensionValidator(allowed_extensions=['html', 'htm', 'tex'])],
)
description = models.CharField(max_length=250, help_text=_("Report template description"))
description = models.CharField(
max_length=250,
verbose_name=_('Description'),
help_text=_("Report template description")
)
enabled = models.BooleanField(
default=True,
verbose_name=_('Enabled'),
help_text=_('Report template is enabled'),
verbose_name=_('Enabled')
)
filters = models.CharField(
blank=True,
max_length=250,
help_text=_("Part query filters (comma-separated list of key=value pairs)"),
validators=[validateFilterString]
)
class Meta:
@ -184,6 +188,16 @@ class TestReport(ReportTemplateBase):
# Requires a stock_item object to be given to it before rendering
stock_item = None
filters = models.CharField(
blank=True,
max_length=250,
verbose_name=_('Filters'),
help_text=_("Part query filters (comma-separated list of key=value pairs)"),
validators=[
validate_stock_item_report_filters
]
)
def matches_stock_item(self, item):
"""
Test if this report template matches a given StockItem objects