Skip to content

Commit 611c592

Browse files
committed
**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.
1 parent db79832 commit 611c592

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

django_ledger/models/data_import.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ def get_queryset(self) -> StagedTransactionModelQuerySet:
643643
& Q(receipt_type__isnull=True)
644644
& Q(vendor_model__isnull=True)
645645
& Q(customer_model__isnull=True)
646-
& Q(children_count=F('children_mapped_count'))
646+
& Q(children_mapping_done=True)
647647
& Q(total_amount_split__exact=F('amount'))
648648
& Q(transaction_model__isnull=True)
649649
)
@@ -1318,9 +1318,7 @@ def has_mapped_receipt(self) -> bool:
13181318
return False
13191319

13201320
def can_unbundle(self) -> bool:
1321-
if any([
1322-
not self.is_single()
1323-
]):
1321+
if any([not self.is_single()]):
13241322
return True
13251323
return False
13261324

@@ -1341,7 +1339,8 @@ def can_split(self) -> bool:
13411339
[
13421340
self.is_single(),
13431341
self.is_parent_is_bundled_has_receipt(),
1344-
self.is_parent_is_bundled_no_receipt()
1342+
self.is_parent_is_bundled_no_receipt(),
1343+
# self.is_parent_not_bundled_no_receipt(),
13451344
]
13461345
):
13471346
return True
@@ -1452,13 +1451,15 @@ def can_migrate(self, as_split: bool = False) -> bool:
14521451
"""
14531452
ready_to_import = getattr(self, 'ready_to_import')
14541453

1455-
if not ready_to_import:
1456-
return False
1457-
14581454
if ready_to_import:
14591455
is_role_valid = self.is_role_mapping_valid(raise_exception=False)
1460-
if is_role_valid:
1461-
return True
1456+
if self.is_bundled():
1457+
return is_role_valid
1458+
else:
1459+
if all([self.has_children(), self.are_all_children_mapped()]):
1460+
return True
1461+
else:
1462+
return False
14621463

14631464
can_split_into_je = getattr(self, 'can_split_into_je')
14641465
if can_split_into_je and as_split:
@@ -1472,10 +1473,7 @@ def can_migrate_receipt(self) -> bool:
14721473
if ready_to_import:
14731474
if self.is_transfer():
14741475
return True
1475-
if any([
1476-
self.is_single_has_receipt(),
1477-
self.is_parent_is_bundled_has_receipt()
1478-
]):
1476+
if any([self.is_single_has_receipt(), self.is_parent_is_bundled_has_receipt()]):
14791477
return True
14801478
return False
14811479

@@ -1619,11 +1617,14 @@ def get_prospect_je_activity_try(
16191617
The journal entry activity if successfully retrieved or updated; otherwise,
16201618
returns the existing activity or None if no activity is present.
16211619
"""
1622-
if (
1623-
force_update
1624-
or all([self.is_children() and self.parent.has_activity(), not self.is_bundled(), not self.has_activity()])
1625-
or all([not self.has_activity(), getattr(self, 'ready_to_import')])
1626-
):
1620+
if any([
1621+
force_update,
1622+
self.is_single(),
1623+
self.is_parent_is_bundled_no_receipt(),
1624+
self.is_parent_is_bundled_has_receipt(),
1625+
self.is_child_not_bundled_has_receipt(),
1626+
self.is_child_not_bundled_no_receipt(),
1627+
]):
16271628
role_set = self.get_import_role_set()
16281629
if role_set is not None:
16291630
try:

django_ledger/templates/django_ledger/data_import/tags/data_import_job_txs_imported.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<div class="dropdown-content">
6666
<a href="{% url 'django_ledger:je-detail' entity_slug=import_job_model.entity_slug ledger_pk=imported_tx.transaction_model.journal_entry.ledger_id je_pk=imported_tx.transaction_model.journal_entry_id %}"
6767
class="dropdown-item">{% trans 'View JE' %}</a>
68-
{% if imported_tx.has_receipt %}
68+
{% if imported_tx.receipt_uuid %}
6969
<a href="{% url 'django_ledger:receipt-detail' entity_slug=import_job_model.entity_slug receipt_pk=imported_tx.receiptmodel.uuid %}"
7070
class="dropdown-item">{% trans 'View Receipt' %}</a>
7171
{% endif %}

django_ledger/templates/django_ledger/data_import/tags/data_import_job_txs_table.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
{{ txf.vendor_model }}
8181
{# {{ txf.instance.can_migrate }}#}
8282
{# {{ txf.instance.ready_to_import }}#}
83+
{# {{ txf.instance.can_have_activity }}#}
8384
</td>
8485
<td class="has-text-centered">{{ txf.tx_import }}</td>
8586
<td class="has-text-centered">{{ txf.bundle_split }}</td>

0 commit comments

Comments
 (0)