Skip to content

Commit

Permalink
Revising Computation Fields
Browse files Browse the repository at this point in the history
  • Loading branch information
RamezIssac committed Oct 1, 2023
1 parent 3e0ed3b commit 03207ad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
15 changes: 6 additions & 9 deletions slick_reporting/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,28 +325,25 @@ def do_resolve(self, current_obj, current_row=None):
prepared_result = self._cache
return self.resolve(prepared_result, current_obj, current_row)

def get_dependency_value(self, current_obj, name=None):
def get_dependency_value(self, current_obj, name):
"""
Get the values of the ReportFields specified in `requires`
:param current_obj: the current object which we want the calculation for
:param name: Optional, the name of the specific dependency you want.
:param name: the name of the specific dependency you want.
: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, name=None)
if name:
return values.get(name)
return values
values = self._resolve_dependencies(current_obj, name=name)
return values.get(name)

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
needed_values = [name] if name else dependencies_value.keys()
for d in needed_values:
d_instance = dependencies_value[d]["instance"]
dep_results[d] = d_instance.do_resolve(current_obj)
return dep_results
Expand Down
1 change: 1 addition & 0 deletions slick_reporting/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ def _get_record_data(self, obj, columns):

if source:
computation_class = self.report_fields_classes[source]
# the computation field is being asked from another computation field that requires it.
value = computation_class.get_dependency_value(group_by_val, col_data["ref"].name)
else:
try:
Expand Down

0 comments on commit 03207ad

Please sign in to comment.