Skip to content

Commit

Permalink
Merge branch 'release/0.6.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramez Ashraf committed Feb 20, 2023
2 parents cdf8d8b + 4638961 commit f1608a4
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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]

Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions slick_reporting/__init__.py
Original file line number Diff line number Diff line change
@@ -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'
12 changes: 8 additions & 4 deletions slick_reporting/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
7 changes: 5 additions & 2 deletions slick_reporting/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit f1608a4

Please sign in to comment.