diff --git a/CHANGELOG.md b/CHANGELOG.md index 90f0258..ef88c9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog All notable changes to this project will be documented in this file. +## [0.6.7] + +- Fix issue with `ReportField` when it has a `requires` in time series and crosstab reports / ## [0.6.6] diff --git a/docs/source/conf.py b/docs/source/conf.py index 605721c..553d67a 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -27,7 +27,7 @@ master_doc = 'index' # The full version, including alpha/beta/rc tags -release = '0.6.6' +release = '0.6.7' # -- General configuration --------------------------------------------------- diff --git a/slick_reporting/__init__.py b/slick_reporting/__init__.py index 5c250d2..4821423 100644 --- a/slick_reporting/__init__.py +++ b/slick_reporting/__init__.py @@ -1,5 +1,5 @@ default_app_config = 'slick_reporting.apps.ReportAppConfig' -VERSION = (0, 6, 6) +VERSION = (0, 6, 7) -__version__ = '0.6.6' +__version__ = '0.6.7' diff --git a/slick_reporting/fields.py b/slick_reporting/fields.py index 1e86eab..bdd0e48 100644 --- a/slick_reporting/fields.py +++ b/slick_reporting/fields.py @@ -130,6 +130,7 @@ def init_preparation(self, q_filters=None, kwargs_filters=None, **kwargs): debit_results, credit_results = self.prepare(q_filters, kwargs_filters, **kwargs) self._cache = debit_results, credit_results, dep_values + return self._cache def prepare(self, q_filters=None, kwargs_filters=None, **kwargs): """ @@ -188,7 +189,8 @@ def _prepare_dependencies(self, q_filters=None, extra_filters=None, ): for dep_class in self._require_classes: dep = dep_class(self.plus_side_q, self.minus_side_q, self.report_model, date_field=self.date_field, group_by=self.group_by) - values[dep.name] = {'results': dep.init_preparation(q_filters, extra_filters), + results = dep.init_preparation(q_filters, extra_filters) + values[dep.name] = {'results': results, 'instance': dep} return values @@ -216,17 +218,19 @@ def get_dependency_value(self, current_obj, name=None): :return: a dict containing dependencies names as keys and their calculation as values or a specific value if name is specified. """ - values = self._resolve_dependencies(current_obj) + values = self._resolve_dependencies(current_obj, name=None) if name: return values.get(name) return values - def _resolve_dependencies(self, current_obj): + def _resolve_dependencies(self, current_obj, name=None): dep_results = {} cached_debit, cached_credit, dependencies_value = self._cache dependencies_value = dependencies_value or {} for d in dependencies_value.keys(): + if name and d != name: + continue d_instance = dependencies_value[d]['instance'] dep_results[d] = d_instance.resolve(current_obj) return dep_results @@ -382,7 +386,7 @@ class PercentageToBalance(SlickReportField): def final_calculation(self, debit, credit, dep_dict): obj_balance = dep_dict.get('__balance__') total = debit - credit - return (obj_balance/total) * 100 + return (obj_balance / total) * 100 class CreditReportField(SlickReportField): diff --git a/slick_reporting/generator.py b/slick_reporting/generator.py index 411a692..00f812c 100644 --- a/slick_reporting/generator.py +++ b/slick_reporting/generator.py @@ -306,8 +306,11 @@ def _prepare_report_dependencies(self): if isclass(klass) and issubclass(klass, SlickReportField): dependencies_names = klass.get_full_dependency_list() - # check if any of this dependencies is on the report - fields_on_report = [x for x in window_cols if x['ref'] in dependencies_names] + # check if any of these dependencies is on the report, if found we call the child to + # resolve the value for its parent avoiding extra database call + fields_on_report = [x for x in window_cols if x['ref'] in dependencies_names + and ((window == 'time_series' and x.get('start_date', '') == col_data.get('start_date', '') and x.get('end_date') == col_data.get('end_date')) or + window == 'crosstab' and x.get('id') == col_data.get('id'))] for field in fields_on_report: self._report_fields_dependencies[window][field['name']] = col_data['name'] for col_data in window_cols: diff --git a/tests/tests.py b/tests/tests.py index 246dec8..c7dbf82 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -172,6 +172,14 @@ def test_client_client_sales_monthly(self): self.assertEqual(data[0]['__total__TS%s0301' % year], 100) self.assertEqual(data[0]['__total__TS%s0201' % year], 100) + self.assertEqual(data[0]['__debit__TS%s0401' % year], 100) + self.assertEqual(data[0]['__debit__TS%s0301' % year], 100) + self.assertEqual(data[0]['__debit__TS%s0201' % year], 100) + + self.assertEqual(data[2]['__debit__TS%s0401' % year], 300) + self.assertEqual(data[2]['__debit__TS%s0301' % year], 300) + self.assertEqual(data[2]['__debit__TS%s0201' % year], 300) + # todo add __fb__ to time series and check the balance def test_client_statement_detail(self):