From dbaa0fc300909aa0b3a95bac2a7ab637a9cdbf84 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 6 Feb 2021 17:11:20 +1100 Subject: [PATCH 1/4] Add default page size for reports - A4 / Legal / Letter - Use this for the default page size for InvenTree reports --- InvenTree/common/models.py | 11 +++++++++++ InvenTree/report/models.py | 10 +++++----- .../templates/report/inventree_report_base.html | 12 ++++++------ InvenTree/templates/InvenTree/settings/report.html | 1 + 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index a81d06ed25..5785d8eb7a 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -174,6 +174,17 @@ class InvenTreeSetting(models.Model): 'validator': bool, }, + 'REPORT_DEFAULT_PAGE_SIZE': { + 'name': _('Page Size'), + 'description': _('Default page size for PDF reports'), + 'default': 'A4', + 'choices': [ + ('A4', 'A4'), + ('Legal', 'Legal'), + ('Letter', 'Letter') + ], + }, + 'REPORT_ENABLE_TEST_REPORT': { 'name': _('Test Reports'), 'description': _('Enable generation of test reports'), diff --git a/InvenTree/report/models.py b/InvenTree/report/models.py index 0c77f4d19a..0d8d8365dd 100644 --- a/InvenTree/report/models.py +++ b/InvenTree/report/models.py @@ -18,6 +18,7 @@ from django.core.files.storage import FileSystemStorage from django.core.validators import FileExtensionValidator import stock.models +import common.models from InvenTree.helpers import validateFilterString @@ -186,15 +187,14 @@ class ReportTemplateBase(ReportBase): context = self.get_context_data(request) - context['media'] = settings.MEDIA_ROOT - - context['report_name'] = self.name + context['date'] = datetime.datetime.now().date() + context['datetime'] = datetime.datetime.now() + context['default_page_size'] = common.models.InvenTreeSetting.get_setting('REPORT_DEFAULT_PAGE_SIZE') context['report_description'] = self.description + context['report_name'] = self.name context['report_revision'] = self.revision context['request'] = request context['user'] = request.user - context['date'] = datetime.datetime.now().date() - context['datetime'] = datetime.datetime.now() # Render HTML template to PDF wp = WeasyprintReportMixin( diff --git a/InvenTree/report/templates/report/inventree_report_base.html b/InvenTree/report/templates/report/inventree_report_base.html index 084b100cab..7c2cff8b4a 100644 --- a/InvenTree/report/templates/report/inventree_report_base.html +++ b/InvenTree/report/templates/report/inventree_report_base.html @@ -3,14 +3,12 @@