Skip to content

Commit b5ddcf4

Browse files
committed
Enhance filtering and account data handling in ledger.
Added support for cleared and reconciled transaction filtering in `io_core` based on kwargs with proper validation. Updated `io_context` to include a method for retrieving account data with an optional key function. Also improved form handling for datetime inputs in journal entries.
1 parent f830646 commit b5ddcf4

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

django_ledger/forms/journal_entry.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class Meta:
5353
'class': DJANGO_LEDGER_FORM_INPUT_CLASSES
5454
}),
5555
'timestamp': DateTimeInput(attrs={
56+
'type': 'datetime-local',
5657
'class': DJANGO_LEDGER_FORM_INPUT_CLASSES
5758
}),
5859
'description': Textarea(attrs={

django_ledger/io/io_context.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ def is_by_period(self) -> bool:
8989
def is_by_activity(self) -> bool:
9090
return self.IO_DATA['by_activity']
9191

92+
# Account Information
93+
def get_account_data(self, key_func=None) -> Dict:
94+
if key_func:
95+
return {
96+
key_func(acc): acc for acc in self.IO_DATA['accounts']
97+
}
98+
return {
99+
acc['account_uuid']: acc for acc in self.IO_DATA['accounts']
100+
}
101+
92102
# Balance Sheet Data...
93103
def has_balance_sheet(self) -> bool:
94104
return 'balance_sheet' in self.IO_DATA

django_ledger/io/io_core.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,28 @@ def database_digest(self,
847847
if role:
848848
txs_queryset = txs_queryset.for_roles(role_list=role)
849849

850+
# Cleared transaction filter via KWARGS....
851+
cleared_filter = kwargs.get('cleared')
852+
if cleared_filter is not None:
853+
if cleared_filter in [True, False]:
854+
txs_queryset = txs_queryset.is_cleared() if cleared_filter else txs_queryset.not_cleared()
855+
else:
856+
raise IOValidationError(
857+
message=f'Invalid value for cleared filter: {cleared_filter}. '
858+
f'Valid values are True, False'
859+
)
860+
861+
# Reconciled transaction filter via KWARGS....
862+
reconciled_filter = kwargs.get('reconciled')
863+
if reconciled_filter is not None:
864+
if reconciled_filter in [True, False]:
865+
txs_queryset = txs_queryset.is_reconciled() if reconciled_filter else txs_queryset.not_reconciled()
866+
else:
867+
raise IOValidationError(
868+
message=f'Invalid value for reconciled filter: {reconciled_filter}. '
869+
f'Valid values are True, False'
870+
)
871+
850872
if io_result.is_bounded:
851873
txs_queryset = txs_queryset.annotate(
852874
amount_io=Case(

0 commit comments

Comments
 (0)