Skip to content

Commit

Permalink
Update app version, improve context date handling, and adjust I/O dig…
Browse files Browse the repository at this point in the history
…est parameters. (#207)

This commit introduces a version increase from 0.6.1 to 0.6.2 and a significant overhaul of the date handling in context. The handling of 'from_date' and 'to_date' in context across different MixIn classes has been refactored using the new ContextFromToDateMixin. The I/O digest parameters in DigestContextMixIn were adjusted, with process_ratios and process_roles set to True. Unnecessary spacing in the balance_sheet_statement.html template was also cleaned up.
  • Loading branch information
elarroba committed May 22, 2024
1 parent 7348491 commit 9281f08
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 27 deletions.
2 changes: 1 addition & 1 deletion django_ledger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
default_app_config = 'django_ledger.apps.DjangoLedgerConfig'

"""Django Ledger"""
__version__ = '0.6.1'
__version__ = '0.6.2'
__license__ = 'GPLv3 License'

__author__ = 'Miguel Sanda'
Expand Down
4 changes: 2 additions & 2 deletions django_ledger/io/io_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def database_digest(self,
Returns results aggregated by accounting if needed. Defaults to False.
by_unit: bool
Returns results aggregated by unit if needed. Defaults to False.
use_closing_entry: bool
use_closing_entries: bool
Overrides the DJANGO_LEDGER_USE_CLOSING_ENTRIES setting.
Returns
-------
Expand Down Expand Up @@ -587,7 +587,7 @@ def python_digest(self,
signs: bool
Changes the balance of an account to negative if it represents a "negative" for display purposes.
(i.e. Expense accounts will show balance as negative and Income accounts as positive.)
force_closing_entry_use: bool
use_closing_entries: bool
Forces the use of closing entries if DJANGO_LEDGER_USE_CLOSING_ENTRIES setting is set to False.
force_queryset_sorting: bool
Forces sorting of the TransactionModelQuerySet before aggregation balances.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<div class="table-container">
<table class="table is-fullwidth is-narrow is-striped">
<tbody>

{% for bs_role, bs_role_data in tx_digest.balance_sheet.items %}
{% if bs_role_data.is_block %}
<tr>
Expand Down
2 changes: 1 addition & 1 deletion django_ledger/templatetags/django_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def cash_flow_statement(context, io_model):

@register.inclusion_tag('django_ledger/financial_statements/tags/income_statement.html', takes_context=True)
def income_statement_table(context, io_model, from_date=None, to_date=None):
user_model: EntityUnitModel = context['user']
user_model = context['user']
activity = context['request'].GET.get('activity')
activity = validate_activity(activity, raise_404=True)
entity_slug = context['view'].kwargs.get('entity_slug')
Expand Down
4 changes: 2 additions & 2 deletions django_ledger/views/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ class EntityModelDetailBaseView(DjangoLedgerSecurityMixIn,
FETCH_UNPAID_BILLS = True
FETCH_UNPAID_INVOICES = True

IO_DIGEST = True
IO_DIGEST_EQUITY = True
IO_DIGEST_UNBOUNDED = True
IO_DIGEST_BOUNDED = True

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
Expand Down
59 changes: 40 additions & 19 deletions django_ledger/views/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,18 @@
from django_ledger.settings import DJANGO_LEDGER_PDF_SUPPORT_ENABLED, DJANGO_LEDGER_AUTHORIZED_SUPERUSER


class YearlyReportMixIn(YearMixin, EntityModelFiscalPeriodMixIn):
class ContextFromToDateMixin:
FROM_DATE_CONTEXT_NAME = 'from_date'
TO_DATE_CONTEXT_NAME = 'to_date'

def get_from_date_context_name(self) -> str:
return self.FROM_DATE_CONTEXT_NAME

def get_to_date_context_name(self) -> str:
return self.TO_DATE_CONTEXT_NAME


class YearlyReportMixIn(YearMixin, ContextFromToDateMixin, EntityModelFiscalPeriodMixIn):

def get_from_date(self, year: int = None, fy_start: int = None, **kwargs) -> date:
return self.get_year_start_date(year, fy_start)
Expand Down Expand Up @@ -58,16 +69,16 @@ def get_context_data(self, **kwargs):
context['year_start'] = year_start
context['year_end'] = year_end

if 'from_date' not in context:
context['from_date'] = year_start
if 'to_date' not in context:
context['to_date'] = year_end
if self.get_from_date_context_name() not in context:
context[self.get_from_date_context_name()] = year_start
if self.get_to_date_context_name() not in context:
context[self.get_to_date_context_name()] = year_end

context['has_year'] = True
return context


class QuarterlyReportMixIn(YearMixin, EntityModelFiscalPeriodMixIn):
class QuarterlyReportMixIn(YearMixin, ContextFromToDateMixin, EntityModelFiscalPeriodMixIn):
quarter = None
quarter_url_kwarg = 'quarter'

Expand Down Expand Up @@ -137,10 +148,10 @@ def get_context_data(self, **kwargs) -> dict:
context['quarter_start'] = quarter_start
context['quarter_end'] = quarter_end

if 'from_date' not in context:
context['from_date'] = quarter_start
if 'to_date' not in context:
context['to_date'] = quarter_end
if self.get_from_date_context_name() not in context:
context[self.get_from_date_context_name()] = quarter_start
if self.get_to_date_context_name() not in context:
context[self.get_to_date_context_name()] = quarter_end

context['has_quarter'] = True
return context
Expand All @@ -154,7 +165,7 @@ def get_previous_quarter(self, quarter) -> int:
return quarter - 1


class MonthlyReportMixIn(YearlyReportMixIn, MonthMixin):
class MonthlyReportMixIn(YearlyReportMixIn, ContextFromToDateMixin, MonthMixin):

def get_from_date(self, month: int = None, year: int = None, **kwargs) -> date:
return self.get_month_start_date(month=month, year=year)
Expand Down Expand Up @@ -206,13 +217,17 @@ def get_context_data(self, **kwargs):
month_end = self.get_month_end_date(year=year, month=month)
context['month_start'] = month_start
context['month_end'] = month_end
context['from_date'] = month_start
context['to_date'] = month_end

if self.get_from_date_context_name() not in context:
context[self.get_from_date_context_name()] = month_start
if self.get_to_date_context_name() not in context:
context[self.get_to_date_context_name()] = month_end

context['has_month'] = True
return context


class DateReportMixIn(MonthlyReportMixIn, DayMixin):
class DateReportMixIn(MonthlyReportMixIn, ContextFromToDateMixin, DayMixin):

def get_context_data(self, **kwargs):
context = super(MonthlyReportMixIn, self).get_context_data(**kwargs)
Expand All @@ -221,8 +236,12 @@ def get_context_data(self, **kwargs):
context['next_day'] = view_date + timedelta(days=1)
context['previous_day'] = view_date - timedelta(days=1)
context['view_date'] = view_date
context['from_date'] = view_date
context['to_date'] = view_date

if self.get_from_date_context_name() not in context:
context[self.get_from_date_context_name()] = view_date
if self.get_to_date_context_name() not in context:
context[self.get_to_date_context_name()] = view_date

return context

def get_date(self) -> date:
Expand All @@ -243,7 +262,8 @@ def get_from_to_dates(self, month: int = None, year: int = None, **kwargs) -> Tu
return dt, dt


class FromToDatesMixIn:
# todo: need to incorporate in base view...
class FromToDatesParseMixIn:
DJL_FROM_DATE_PARAM: str = 'from_date'
DJL_TO_DATE_PARAM: str = 'to_date'
DJL_NO_FROM_DATE_RAISE_404: bool = True
Expand Down Expand Up @@ -369,6 +389,7 @@ def get_context_data(self, **kwargs):


class DigestContextMixIn:

IO_DIGEST_UNBOUNDED = False
IO_DIGEST_BOUNDED = False

Expand Down Expand Up @@ -435,8 +456,8 @@ def get_io_digest(self,
from_date=from_date,
unit_slug=unit_slug,
by_period=True if by_period else False,
process_ratios=False,
process_roles=False,
process_ratios=True,
process_roles=True,
process_groups=True)

context[self.get_io_manager_bounded_context_name()] = io_digest_equity
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "django-ledger"
version = "0.6.1"
version = "0.6.2"
readme = "README.md"
requires-python = ">=3.10"
description = "Double entry accounting system built on the Django Web Framework."
Expand Down

0 comments on commit 9281f08

Please sign in to comment.