From 33d66182dfa4919479ed838c86fa6ff7ecd35acb Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 5 Feb 2021 12:01:44 +1100 Subject: [PATCH 1/4] Add "revision" number to report model - Auto-increments whenever the model is saved --- InvenTree/company/tests.py | 3 +++ InvenTree/report/admin.py | 2 +- .../migrations/0009_testreport_revision.py | 18 ++++++++++++++++++ .../migrations/0010_auto_20210205_1201.py | 18 ++++++++++++++++++ InvenTree/report/models.py | 14 ++++++++++++++ 5 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 InvenTree/report/migrations/0009_testreport_revision.py create mode 100644 InvenTree/report/migrations/0010_auto_20210205_1201.py diff --git a/InvenTree/company/tests.py b/InvenTree/company/tests.py index 5229fdb045..f7bcd4e0b6 100644 --- a/InvenTree/company/tests.py +++ b/InvenTree/company/tests.py @@ -1,3 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + from django.test import TestCase from django.core.exceptions import ValidationError diff --git a/InvenTree/report/admin.py b/InvenTree/report/admin.py index 390964b590..610b32dd4c 100644 --- a/InvenTree/report/admin.py +++ b/InvenTree/report/admin.py @@ -8,7 +8,7 @@ from .models import ReportSnippet, TestReport, ReportAsset class ReportTemplateAdmin(admin.ModelAdmin): - list_display = ('name', 'description', 'template', 'filters', 'enabled') + list_display = ('name', 'description', 'template', 'filters', 'enabled', 'revision') class ReportSnippetAdmin(admin.ModelAdmin): diff --git a/InvenTree/report/migrations/0009_testreport_revision.py b/InvenTree/report/migrations/0009_testreport_revision.py new file mode 100644 index 0000000000..d78e866968 --- /dev/null +++ b/InvenTree/report/migrations/0009_testreport_revision.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.7 on 2021-02-05 00:53 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('report', '0008_auto_20210204_2100'), + ] + + operations = [ + migrations.AddField( + model_name='testreport', + name='revision', + field=models.PositiveIntegerField(default=1, help_text='Report revision number (auto-increments)', verbose_name='Revision'), + ), + ] diff --git a/InvenTree/report/migrations/0010_auto_20210205_1201.py b/InvenTree/report/migrations/0010_auto_20210205_1201.py new file mode 100644 index 0000000000..af8821032e --- /dev/null +++ b/InvenTree/report/migrations/0010_auto_20210205_1201.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.7 on 2021-02-05 01:01 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('report', '0009_testreport_revision'), + ] + + operations = [ + migrations.AlterField( + model_name='testreport', + name='revision', + field=models.PositiveIntegerField(default=1, editable=False, help_text='Report revision number (auto-increments)', verbose_name='Revision'), + ), + ] diff --git a/InvenTree/report/models.py b/InvenTree/report/models.py index 422216f9a9..b5550412e0 100644 --- a/InvenTree/report/models.py +++ b/InvenTree/report/models.py @@ -62,6 +62,13 @@ class ReportBase(models.Model): class Meta: abstract = True + def save(self, *args, **kwargs): + + # Increment revision number + self.revision += 1 + + super().save() + def __str__(self): return "{n} - {d}".format(n=self.name, d=self.description) @@ -113,6 +120,13 @@ class ReportBase(models.Model): help_text=_("Report template description") ) + revision = models.PositiveIntegerField( + default=1, + verbose_name=_("Revision"), + help_text=_("Report revision number (auto-increments)"), + editable=False, + ) + class ReportTemplateBase(ReportBase): """ From f458342e5ff40bc07d882d3d81633a65a3151cfb Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 5 Feb 2021 12:02:16 +1100 Subject: [PATCH 2/4] Add report revision information to the template context --- InvenTree/report/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/InvenTree/report/models.py b/InvenTree/report/models.py index b5550412e0..b10e2db32b 100644 --- a/InvenTree/report/models.py +++ b/InvenTree/report/models.py @@ -159,6 +159,7 @@ class ReportTemplateBase(ReportBase): context['report_name'] = self.name context['report_description'] = self.description + context['report_revision'] = self.revision context['request'] = request context['user'] = request.user context['date'] = datetime.datetime.now().date() From d686fb505700aada4424e0ca1d64e1c5b87d9f31 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 5 Feb 2021 12:31:13 +1100 Subject: [PATCH 3/4] Fix typo in js file --- InvenTree/templates/js/report.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/templates/js/report.js b/InvenTree/templates/js/report.js index 6e47706917..26907b52df 100644 --- a/InvenTree/templates/js/report.js +++ b/InvenTree/templates/js/report.js @@ -52,7 +52,7 @@ function selectTestReport(reports, items, options={}) {