From 4f49c4ff80d27c608b62fc886da5538db2a606c7 Mon Sep 17 00:00:00 2001 From: Ramez Ashraf Date: Thu, 18 May 2023 09:09:58 +0300 Subject: [PATCH 1/8] Enhance names and translations --- slick_reporting/fields.py | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/slick_reporting/fields.py b/slick_reporting/fields.py index 267369f..67becfa 100644 --- a/slick_reporting/fields.py +++ b/slick_reporting/fields.py @@ -376,7 +376,7 @@ def get_time_series_field_verbose_name(cls, date_period, index, dates, pattern): class FirstBalanceField(SlickReportField): name = "__fb__" - verbose_name = _("first balance") + verbose_name = _("opening balance") def prepare(self, q_filters=None, extra_filters=None, **kwargs): extra_filters = extra_filters or {} @@ -401,7 +401,7 @@ class TotalReportField(SlickReportField): class BalanceReportField(SlickReportField): name = "__balance__" - verbose_name = _("Cumulative Total") + verbose_name = _("Closing Total") requires = ["__fb__"] def final_calculation(self, debit, credit, dep_dict): @@ -439,6 +439,7 @@ def final_calculation(self, debit, credit, dep_dict): field_registry.register(CreditReportField) +@field_registry.register class DebitReportField(SlickReportField): name = "__debit__" verbose_name = _("Debit") @@ -447,7 +448,24 @@ def final_calculation(self, debit, credit, dep_dict): return debit -field_registry.register(DebitReportField) +@field_registry.register +class CreditQuantityReportField(SlickReportField): + name = "__credit_quantity__" + verbose_name = _("Credit QTY") + is_summable = False + + def final_calculation(self, debit, credit, dep_dict): + return credit + + +@field_registry.register +class DebitQuantityReportField(SlickReportField): + name = "__debit_quantity__" + verbose_name = _("Debit QTY") + is_summable = False + + def final_calculation(self, debit, credit, dep_dict): + return debit class TotalQTYReportField(SlickReportField): @@ -461,8 +479,8 @@ class TotalQTYReportField(SlickReportField): class FirstBalanceQTYReportField(FirstBalanceField): - name = "__fb_quan__" - verbose_name = _("starting QTY") + name = "__fb_quantity__" + verbose_name = _("Opening QTY") calculation_field = "quantity" is_summable = False @@ -472,14 +490,14 @@ class FirstBalanceQTYReportField(FirstBalanceField): class BalanceQTYReportField(SlickReportField): name = "__balance_quantity__" - verbose_name = _("Cumulative QTY") + verbose_name = _("Closing QTY") calculation_field = "quantity" - requires = ["__fb_quan__"] + requires = ["__fb_quantity__"] is_summable = False def final_calculation(self, debit, credit, dep_dict): # Use `get` so it fails loud if its not there - fb = dep_dict.get("__fb_quan__") + fb = dep_dict.get("__fb_quantity__") fb = fb or 0 return fb + debit - credit From 22b25b5858616cf671556e362714d1617127f59e Mon Sep 17 00:00:00 2001 From: Ramez Ashraf Date: Fri, 19 May 2023 21:55:51 +0300 Subject: [PATCH 2/8] Add time series documentation --- docs/source/index.rst | 1 + docs/source/time_series_options.rst | 62 +++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 docs/source/time_series_options.rst diff --git a/docs/source/index.rst b/docs/source/index.rst index eb8d6f2..e96b64f 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -75,6 +75,7 @@ Next step :ref:`structure` concept the_view + time_series_options report_generator computation_field diff --git a/docs/source/time_series_options.rst b/docs/source/time_series_options.rst new file mode 100644 index 0000000..d56aaea --- /dev/null +++ b/docs/source/time_series_options.rst @@ -0,0 +1,62 @@ +Time Series Reports +================== + + +Here is a quick recipe to what you want to do + +.. code-block:: python + + from django.utils.translation import gettext_lazy as _ + from django.db.models import Sum + from slick_reporting.views import SlickReportView + + class MyReport(SlickReportView): + + time_series_pattern = "monthly" + # options are : "daily", "weekly", "monthly", "yearly", "custom" + + # if time_series_pattern is "custom", then you can specify the dates like so + # time_series_custom_dates = [ + # (datetime.date(2020, 1, 1), datetime.date(2020, 1, 14)), + # (datetime.date(2020, 2, 1), datetime.date(2020, 2, 14)), + # (datetime.date(2020, 3, 1), datetime.date(2020, 3,14)), + ] + + + time_series_columns = [ + SlickReportField.create(Sum, "value", verbose_name=_("Value")), + ] + # These columns will be calculated for each period in the time series. + + + + columns = ['some_optional_field', + '__time_series__', + # You can customize where the time series columns are displayed in relation to the other columns + + SlickReportField.create(Sum, "value", verbose_name=_("Value")), + # This is the same as the time_series_columns, but this one will be on the whole set + + ] + + + + + time_series_selector = True + # This will display a selector to change the time series pattern + + # settings for the time series selector + # ---------------------------------- + + time_series_selector_choices=None # A list Choice tuple [(value, label), ...] + time_series_selector_default = "monthly" # The initial value for the time series selector + time_series_selector_label = _("Period Pattern) # The label for the time series selector + time_series_selector_allow_empty = False # Allow the user to select an empty time series + + + +Links to demo +------------- + +Time series Selector pattern Demo `Demo `_ +and here is the `Code on github `_ for the report. From e43605fad27cdd8e44b794d4ef037c25f13aa5b0 Mon Sep 17 00:00:00 2001 From: Ramez Ashraf Date: Tue, 23 May 2023 18:28:19 +0300 Subject: [PATCH 3/8] Fix in quantity reports --- slick_reporting/fields.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/slick_reporting/fields.py b/slick_reporting/fields.py index 67becfa..10a3c57 100644 --- a/slick_reporting/fields.py +++ b/slick_reporting/fields.py @@ -452,6 +452,7 @@ def final_calculation(self, debit, credit, dep_dict): class CreditQuantityReportField(SlickReportField): name = "__credit_quantity__" verbose_name = _("Credit QTY") + calculation_field = "quantity" is_summable = False def final_calculation(self, debit, credit, dep_dict): @@ -461,6 +462,7 @@ def final_calculation(self, debit, credit, dep_dict): @field_registry.register class DebitQuantityReportField(SlickReportField): name = "__debit_quantity__" + calculation_field = "quantity" verbose_name = _("Debit QTY") is_summable = False From 2fbc32efc786d1ae807eeabbea13fb3d23c07dfe Mon Sep 17 00:00:00 2001 From: Ramez Ashraf Date: Sat, 27 May 2023 14:53:46 +0300 Subject: [PATCH 4/8] Renaming following django-erp-framework --- .../{ra.chartsjs.js => erp_framework.chartsjs.js} | 0 .../{ra.highchart.js => erp_framework.highchart.js} | 0 slick_reporting/templates/slick_reporting/base.html | 2 +- .../templates/slick_reporting/simple_report.html | 10 +++++----- 4 files changed, 6 insertions(+), 6 deletions(-) rename slick_reporting/static/slick_reporting/{ra.chartsjs.js => erp_framework.chartsjs.js} (100%) rename slick_reporting/static/slick_reporting/{ra.highchart.js => erp_framework.highchart.js} (100%) diff --git a/slick_reporting/static/slick_reporting/ra.chartsjs.js b/slick_reporting/static/slick_reporting/erp_framework.chartsjs.js similarity index 100% rename from slick_reporting/static/slick_reporting/ra.chartsjs.js rename to slick_reporting/static/slick_reporting/erp_framework.chartsjs.js diff --git a/slick_reporting/static/slick_reporting/ra.highchart.js b/slick_reporting/static/slick_reporting/erp_framework.highchart.js similarity index 100% rename from slick_reporting/static/slick_reporting/ra.highchart.js rename to slick_reporting/static/slick_reporting/erp_framework.highchart.js diff --git a/slick_reporting/templates/slick_reporting/base.html b/slick_reporting/templates/slick_reporting/base.html index c3de1c9..950ba91 100644 --- a/slick_reporting/templates/slick_reporting/base.html +++ b/slick_reporting/templates/slick_reporting/base.html @@ -14,7 +14,7 @@ - Python Slick Reporting + Django Slick Reporting
diff --git a/slick_reporting/templates/slick_reporting/simple_report.html b/slick_reporting/templates/slick_reporting/simple_report.html index d4a8c09..6e2efd3 100644 --- a/slick_reporting/templates/slick_reporting/simple_report.html +++ b/slick_reporting/templates/slick_reporting/simple_report.html @@ -60,13 +60,13 @@

Results

{% block extrajs %} {{ block.super }} - - + + - +