Add "report" app

- Define ReportTemplate model which contains a report file template
This commit is contained in:
Oliver Walters 2020-05-21 13:51:13 +10:00
parent 5018f899f7
commit 3d8c059a43
11 changed files with 111 additions and 6 deletions

View File

@ -106,12 +106,13 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
# InvenTree apps
'common.apps.CommonConfig',
'part.apps.PartConfig',
'stock.apps.StockConfig',
'company.apps.CompanyConfig',
'build.apps.BuildConfig',
'common.apps.CommonConfig',
'company.apps.CompanyConfig',
'order.apps.OrderConfig',
'part.apps.PartConfig',
'report.apps.ReportConfig',
'stock.apps.StockConfig',
# Third part add-ons
'django_filters', # Extended filter functionality

View File

14
InvenTree/report/admin.py Normal file
View File

@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib import admin
from .models import ReportTemplate
class ReportTemplateAdmin(admin.ModelAdmin):
list_display = ('template', 'description')
admin.site.register(ReportTemplate, ReportTemplateAdmin)

5
InvenTree/report/apps.py Normal file
View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class ReportConfig(AppConfig):
name = 'report'

View File

@ -0,0 +1,23 @@
# Generated by Django 3.0.5 on 2020-05-21 03:43
from django.db import migrations, models
import report.models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='ReportTemplate',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('template', models.FileField(help_text='Report template file', upload_to=report.models.rename_template)),
('description', models.CharField(help_text='Report template description', max_length=250)),
],
),
]

View File

@ -0,0 +1,20 @@
# Generated by Django 3.0.5 on 2020-05-21 03:50
import django.core.validators
from django.db import migrations, models
import report.models
class Migration(migrations.Migration):
dependencies = [
('report', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='reporttemplate',
name='template',
field=models.FileField(help_text='Report template file', upload_to=report.models.rename_template, validators=[django.core.validators.FileExtensionValidator(allowed_extensions=['html', 'tex'])]),
),
]

View File

View File

@ -0,0 +1,36 @@
"""
Report template model definitions
"""
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
from django.db import models
from django.core.validators import FileExtensionValidator
from django.utils.translation import gettext_lazy as _
def rename_template(instance, filename):
filename = os.path.basename(filename)
return os.path.join('report', 'template', filename)
class ReportTemplate(models.Model):
"""
Reporting template model.
"""
def __str__(self):
return os.path.basename(self.template.name)
template = models.FileField(
upload_to=rename_template,
help_text=_("Report template file"),
validators=[FileExtensionValidator(allowed_extensions=['html', 'tex'])],
)
description = models.CharField(max_length=250, help_text=_("Report template description"))

View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

View File

@ -51,12 +51,12 @@ style:
# Run unit tests
test:
cd InvenTree && python3 manage.py check
cd InvenTree && python3 manage.py test build common company order part stock
cd InvenTree && python3 manage.py test build common company order part report stock InvenTree
# Run code coverage
coverage:
cd InvenTree && python3 manage.py check
coverage run InvenTree/manage.py test build common company order part stock InvenTree
coverage run InvenTree/manage.py test build common company order part report stock InvenTree
coverage html
# Install packages required to generate code docs