Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reports #10

Merged
merged 6 commits into from Mar 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 19 additions & 9 deletions report/apps.py
Expand Up @@ -14,6 +14,7 @@
"gql_mutation_report_delete_perms": ["121004"],
}


class ReportConfig(AppConfig):
name = MODULE_NAME

Expand Down Expand Up @@ -51,19 +52,26 @@ class ReportConfig(AppConfig):

def _configure_permissions(self, cfg):
ReportConfig.gql_query_report_perms = cfg["gql_query_report_perms"]
ReportConfig.gql_mutation_report_add_perms = cfg["gql_mutation_report_add_perms"]
ReportConfig.gql_mutation_report_edit_perms = cfg["gql_mutation_report_edit_perms"]
ReportConfig.gql_mutation_report_delete_perms = cfg["gql_mutation_report_delete_perms"]
ReportConfig.gql_mutation_report_add_perms = cfg[
"gql_mutation_report_add_perms"
]
ReportConfig.gql_mutation_report_edit_perms = cfg[
"gql_mutation_report_edit_perms"
]
ReportConfig.gql_mutation_report_delete_perms = cfg[
"gql_mutation_report_delete_perms"
]

@classmethod
def get_report(cls, module_name, report_name):
def get_report(cls, report_name):
for report in cls.reports:
if report["module"] == module_name and report["name"] == report_name:
if report["name"] == report_name:
return report
return None

def ready(self):
from core.models import ModuleConfiguration

cfg = ModuleConfiguration.get_or_default(MODULE_NAME, DEFAULT_CFG)
self._configure_permissions(cfg)

Expand All @@ -72,10 +80,13 @@ def ready(self):
for app in all_apps:
try:
appreports = __import__(f"{app}.report")
if hasattr(appreports.report, "report_definitions") \
and isinstance(appreports.report.report_definitions, list):
if hasattr(appreports.report, "report_definitions") and isinstance(
appreports.report.report_definitions, list
):
self.reports += appreports.report.report_definitions
logger.debug(f"{app} {len(appreports.report.report_definitions)} reports loaded")
logger.debug(
f"{app} {len(appreports.report.report_definitions)} reports loaded"
)
except ModuleNotFoundError as exc:
# The module doesn't have a schema.py, just skip
logger.debug(f"{app} has no schema module, skipping")
Expand All @@ -85,4 +96,3 @@ def ready(self):
except Exception as exc:
logger.debug(f"{app} exception", exc)
logger.debug("done loading reports")

26 changes: 26 additions & 0 deletions report/migrations/0002_auto_20220308_1414.py
@@ -0,0 +1,26 @@
# Generated by Django 3.0.14 on 2022-03-08 14:14

import datetime
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("report", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name="reportdefinition",
name="name",
field=models.CharField(max_length=255),
),
migrations.AlterField(
model_name="reportdefinition",
name="validity_from",
field=models.DateTimeField(
blank=True, default=datetime.datetime.now, null=True
),
),
]
54 changes: 37 additions & 17 deletions report/models.py
@@ -1,29 +1,24 @@
from django.db import models
from core import models as core_models
from datetime import datetime as py_datetime


class ReportDefinition(core_models.UUIDModel):
"""
Record report (business modules) templates to be generated by the templating engine (reportbro for PDF,...)
Initial implementation only integrate ReportBro templating engine
"""

REPORT_BRO = 0
REPORT_ENGINE_CHOICES = (
(REPORT_BRO, "Report Bro - PDF"),
)
REPORT_ENGINE_CHOICES = ((REPORT_BRO, "Report Bro - PDF"),)

name = models.CharField(
max_length=255, blank=False, null=False, unique=True)
# module = models.CharField(
# max_length=255, blank=True, null=True
# )
name = models.CharField(max_length=255, blank=False, null=False)
# alternate_of = models.CharField(
# max_length=255, blank=True, null=True
# )
engine = models.IntegerField(
choices=REPORT_ENGINE_CHOICES, default=REPORT_BRO)
engine = models.IntegerField(choices=REPORT_ENGINE_CHOICES, default=REPORT_BRO)
definition = models.TextField()
validity_from = models.DateTimeField(blank=True, null=True)
validity_from = models.DateTimeField(blank=True, null=True, default=py_datetime.now)
validity_to = models.DateTimeField(blank=True, null=True)

class Meta:
Expand All @@ -34,16 +29,41 @@ class Meta:
class GeneratedReports(models.Model):
id = models.AutoField(db_column="ReportingId", primary_key=True)
reporting_date = models.TextField(db_column="ReportingDate")
location = models.ForeignKey("location.Location", models.DO_NOTHING, db_column="LocationId", related_name="+")
product = models.ForeignKey("product.Product", models.DO_NOTHING, db_column="ProdId", related_name="+")
payer = models.ForeignKey("payer.Payer", models.DO_NOTHING, db_column="PayerId", blank=True, null=True, related_name="generated_reports")
location = models.ForeignKey(
"location.Location", models.DO_NOTHING, db_column="LocationId", related_name="+"
)
product = models.ForeignKey(
"product.Product", models.DO_NOTHING, db_column="ProdId", related_name="+"
)
payer = models.ForeignKey(
"payer.Payer",
models.DO_NOTHING,
db_column="PayerId",
blank=True,
null=True,
related_name="generated_reports",
)
start_date = models.DateField(db_column="StartDate")
end_date = models.DateField(db_column="EndDate")
record_found = models.IntegerField(db_column="RecordFound")
officer = models.ForeignKey("core.Officer", on_delete=models.DO_NOTHING, db_column="OfficerID", null=True, blank=True)
officer = models.ForeignKey(
"core.Officer",
on_delete=models.DO_NOTHING,
db_column="OfficerID",
null=True,
blank=True,
)
report_type = models.IntegerField(db_column="ReportType", null=True, blank=True)
commission_rate = models.DecimalField(db_column="CommissionRate", max_digits=18, decimal_places=2, null=True, blank=True)
report_mode = models.IntegerField(db_column="ReportMode", default=0, null=True, blank=True)
commission_rate = models.DecimalField(
db_column="CommissionRate",
max_digits=18,
decimal_places=2,
null=True,
blank=True,
)
report_mode = models.IntegerField(
db_column="ReportMode", default=0, null=True, blank=True
)
scope = models.IntegerField(db_column="Scope", null=True, blank=True)

# Used by Overview of Commissions
Expand Down