Skip to content

Commit 16a95a5

Browse files
authored
v0.8.2.3 (#293)
* **Refactored `StagedTransactionModel` logic and template conditions:** - Simplified queryset filters and refactored helpers like `can_unbundle` and `ready_to_import` for better readability. - Replaced `children_count` check with `children_mapping_done` to streamline logic. - Updated template conditional to check for `receipt_uuid` instead of `has_receipt`. - Added commented-out logic for potential future conditions in `data_import_job_txs_table.html`. ### **Summary** Refactored transaction evaluation logic and templates for clarity and maintainability. Improved existing checks and prepared room for future enhancements in transaction handling. * v0.8.2.3 - **Enhanced import handling and UI for transactions:** - Introduced clearer logic for bundled vs. unbundled transactions in `StagedTransactionModel`. - Added new fields (`imported_count`, `children_import_pending_count`) for tracking transaction states. - Improved `is_imported` and `is_pending` query handling for parent and child transactions. - Enabled staged transaction deletion with `can_delete` and pre-deletion validation to reject invalid deletes. - Updated forms to streamline `tx_import` and `bundle_split` behavior for child transactions. - **Refined receipt migration and undo-import logic:** - Modified `migrate_receipt` to handle split amounts during migration. - Enhanced undo-import to account for child transactions and ensure proper cascade delete behavior. - **Improved templating and user experience:** - Added currency formatting for transaction amounts in receipt details. - Refined dropdown actions in imported transactions list to dynamically respect transaction types. - Reorganized transaction states and validations in templates for consistency. - **Refactored import state tracking for clarity:** - Expanded staged transaction attributes for better state evaluation (`is_children`, `is_parent`, `is_bundled`). - Introduced additional parent-child relationship checks for transaction clarity. ### **Summary** Refactored `StagedTransactionModel`, forms, and templates for improved import logic and UI experience. Introduced split amount handling and * - **Simplified journal entry update logic in import process:** - Adjusted the order of `unlock` and `unpost` calls to reflect appropriate transactional sequence before deletion. - **Refined transaction actions in template:** - Updated dropdown structure to consistently display transaction actions regardless of `is_parent` or `is_bundled` status. - Improved conditional logic to dynamically manage available actions like "View JE," "View Receipt," and "Undo Import." - Enhanced template organization for better readability and maintainability. ### **Summary** Streamlined journal entry handling logic and improved dropdown action display in transaction templates for better consistency and user experience. ### **Backwards Compatibility** These changes are fully backwards compatible. No significant behavioral or structural changes to existing workflows.
1 parent db79832 commit 16a95a5

File tree

11 files changed

+289
-164
lines changed

11 files changed

+289
-164
lines changed

django_ledger/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
default_app_config = 'django_ledger.apps.DjangoLedgerConfig'
77

88
"""Django Ledger"""
9-
__version__ = '0.8.2.2'
9+
__version__ = '0.8.2.3'
1010
__license__ = 'GPLv3 License'
1111

1212
__author__ = 'Miguel Sanda'

django_ledger/forms/data_import.py

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from itertools import groupby
2+
13
from django import forms
24
from django.forms import (
35
ModelForm,
@@ -140,7 +142,7 @@ def __init__(self, base_formset_instance, *args, **kwargs):
140142
self.fields['tx_split'].disabled = True
141143

142144
if not staged_tx_model.can_unbundle():
143-
# self.fields['bundle_split'].widget = HiddenInput()
145+
self.fields['bundle_split'].widget = HiddenInput()
144146
self.fields['bundle_split'].disabled = True
145147

146148
def clean_account_model(self):
@@ -160,13 +162,42 @@ def clean_unit_model(self):
160162
def clean_tx_import(self):
161163
staged_txs_model: StagedTransactionModel = self.instance
162164
if staged_txs_model.is_children():
163-
return False
165+
parent_form = self.BASE_FORMSET_INSTANCE.FORMS_BY_ID[staged_txs_model.parent_id]
166+
if all(
167+
[
168+
any(
169+
[
170+
staged_txs_model.is_child_not_bundled_has_receipt(),
171+
staged_txs_model.is_child_not_bundled_no_receipt(),
172+
]
173+
),
174+
parent_form.cleaned_data['tx_import'] is True,
175+
]
176+
):
177+
return True
164178
return self.cleaned_data['tx_import']
165179

180+
def clean_bundle_split(self):
181+
staged_txs_model: StagedTransactionModel = self.instance
182+
if staged_txs_model.is_single():
183+
return True
184+
if staged_txs_model.is_children():
185+
parent_form = self.BASE_FORMSET_INSTANCE.FORMS_BY_ID[staged_txs_model.parent.uuid]
186+
return parent_form.cleaned_data['bundle_split']
187+
return self.cleaned_data['bundle_split']
188+
166189
def clean(self):
167190
if self.cleaned_data['tx_import'] and self.cleaned_data['tx_split']:
168191
raise ValidationError(message=_('Cannot import and split at the same time'))
169192

193+
def has_changed(self):
194+
has_changed = super().has_changed()
195+
staged_txs_model: StagedTransactionModel = self.instance
196+
if not has_changed and staged_txs_model.is_children():
197+
parent_form = self.BASE_FORMSET_INSTANCE.FORMS_BY_ID[staged_txs_model.parent.uuid]
198+
return parent_form.has_changed()
199+
return has_changed
200+
170201
class Meta:
171202
model = StagedTransactionModel
172203
fields = [
@@ -244,15 +275,24 @@ def __init__(
244275
self.unit_model_qs = entity_model.entityunitmodel_set.all()
245276
self.UNIT_MODEL_CHOICES = [(None, '----')] + [(u.uuid, u) for i, u in enumerate(self.unit_model_qs)]
246277

247-
self.VENDOR_MODEL_QS = entity_model.vendormodel_set.visible()
248-
self.CUSTOMER_MODEL_QS = entity_model.customermodel_set.visible()
278+
self.VENDOR_MODEL_QS = entity_model.vendormodel_set.visible().order_by('vendor_name')
279+
self.CUSTOMER_MODEL_QS = entity_model.customermodel_set.visible().order_by('customer_name')
249280

250281
self.VENDOR_CHOICES = [(None, '-----')] + [(str(v.uuid), v) for v in self.VENDOR_MODEL_QS]
251282
self.CUSTOMER_CHOICES = [(None, '-----')] + [(str(c.uuid), c) for c in self.CUSTOMER_MODEL_QS]
252283

253284
self.VENDOR_MAP = dict(self.VENDOR_CHOICES)
254285
self.CUSTOMER_MAP = dict(self.CUSTOMER_CHOICES)
255286

287+
self.FORMS_BY_ID = {
288+
f.instance.uuid: f for f in self.forms if getattr(f, 'instance', None) and getattr(f.instance, 'uuid', None)
289+
}
290+
291+
form_children = [(f.instance.parent_id, f.instance.uuid) for f in self.forms if f.instance.parent_id]
292+
form_children.sort(key=lambda f: f[0])
293+
294+
self.FORM_CHILDREN = {g: list(j[1] for j in p) for g, p in groupby(form_children, key=lambda i: i[0])}
295+
256296
def get_form_kwargs(self, index):
257297
return {
258298
'base_formset_instance': self,

django_ledger/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
from django_ledger.models.purchase_order import *
1616
from django_ledger.models.closing_entry import *
1717
from django_ledger.models.entity import *
18+
1819
from django_ledger.models.data_import import *
1920
from django_ledger.models.receipt import *

0 commit comments

Comments
 (0)