Skip to content

Commit

Permalink
- Fix in FirstBalance Computation field if no date is supplied
Browse files Browse the repository at this point in the history
  • Loading branch information
RamezIssac committed Oct 14, 2023
1 parent b8f8f2c commit f57f9ab
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ All notable changes to this project will be documented in this file.
erp_framework.highchart.js and erp_framework.chartjs.js respectively
- Fix an issue with Crosstab when there crosstab_compute_remainder = False
- Group by and crosstab reports do not need date_field set anymore. Only time series do.
- Fix in FirstBalance Computation field if no date is supplied

## [0.7.0]

Expand Down
13 changes: 9 additions & 4 deletions slick_reporting/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,19 @@ def prepare(
**kwargs,
):
extra_filters = kwargs_filters or {}

from_date_value = extra_filters.get(f"{self.date_field}__gte")
extra_filters.pop(f"{self.date_field}__gte", None)
extra_filters[f"{self.date_field}__lt"] = from_date_value
if self.date_field:
from_date_value = extra_filters.get(f"{self.date_field}__gte")
extra_filters.pop(f"{self.date_field}__gte", None)
extra_filters[f"{self.date_field}__lt"] = from_date_value
return super(FirstBalanceField, self).prepare(
q_filters, kwargs_filters, main_queryset, group_by, prevent_group_by, **kwargs
)

def resolve(self, prepared_results, required_computation_results: dict, current_pk, current_row=None) -> float:
if not self.date_field:
return 0
return super().resolve(prepared_results, required_computation_results, current_pk, current_row)


field_registry.register(FirstBalanceField)

Expand Down
9 changes: 7 additions & 2 deletions tests/report_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,14 @@ class CrosstabOnTraversingField(ReportGenerator):

class ClientTotalBalance(ReportGenerator):
report_model = SimpleSales
date_field = "doc_date"
# date_field = "doc_date"
group_by = "client"
columns = ["slug", "name", "__balance__", "__total__"]
columns = [
"slug",
"name",
"__balance__",
ComputationField.create(Sum, "value", name="__total__", verbose_name=_("Sales")),
]


class TotalBalanceWithQueryset(ReportGenerator):
Expand Down

0 comments on commit f57f9ab

Please sign in to comment.