diff --git a/inventory/templatetags/custom_filters.py b/inventory/templatetags/custom_filters.py index 9d91344b..965ac3ca 100644 --- a/inventory/templatetags/custom_filters.py +++ b/inventory/templatetags/custom_filters.py @@ -412,8 +412,8 @@ def transactions_table(object_type: Union[JournalEntryModel, BillModel, InvoiceM output_field=IntegerField() ) ).order_by( - 'timestamp', # Primary sort: chronological (oldest first) - 'debit_credit_sort_order', # Secondary sort: Debits (0) before Credits (1) + '-timestamp', # Primary sort: chronological (oldest first) + '-debit_credit_sort_order', # Secondary sort: Debits (0) before Credits (1) 'pk' # Optional: Tie-breaker for consistent order ) elif isinstance(object_type, InvoiceModel): @@ -529,4 +529,5 @@ def get_vehicle_type_name(car_serie): elif 'liftback' in serie_lower: return 'liftback' else: - return 'sedan' \ No newline at end of file + return 'sedan' + \ No newline at end of file diff --git a/inventory/views.py b/inventory/views.py index 8c653a3b..8927a6a8 100644 --- a/inventory/views.py +++ b/inventory/views.py @@ -67,6 +67,7 @@ from django.views.generic import ( ArchiveIndexView, ) +from django.db.models import Case, Value, IntegerField, When # Django Ledger from django_ledger.io import roles @@ -8123,6 +8124,7 @@ class JournalEntryListView(LoginRequiredMixin, ListView): model = JournalEntryModel context_object_name = "journal_entries" template_name = "ledger/journal_entry/journal_entry_list.html" + ordering=['-timestamp'] def get_queryset(self): qs = super().get_queryset() @@ -8229,11 +8231,17 @@ def JournalEntryTransactionsView(request, pk): :rtype: django.http.HttpResponse """ journal = JournalEntryModel.objects.filter(pk=pk).first() - transactions = ( - TransactionModel.objects.filter(journal_entry=journal) - .order_by("account__code") - .all() - ) + # transactions = ( + # TransactionModel.objects.filter(journal_entry=journal) + # .order_by("account__code") + # .all() + # ) + qs=TransactionModel.objects.filter(journal_entry=journal).all() + transactions=qs.annotate( + debit_credit_sort_order=Case(When(tx_type='debit',then=Value(0)), + When(tx_type='credit',then=Value(1)), + output_field=IntegerField()) + ).order_by('debit_credit_sort_order') return render( request, "ledger/journal_entry/journal_entry_transactions.html", diff --git a/templates/account/user_settings.html b/templates/account/user_settings.html index 366114f2..9842c9bb 100644 --- a/templates/account/user_settings.html +++ b/templates/account/user_settings.html @@ -9,9 +9,9 @@