chnage the custome filter logic for the Transaction bills

This commit is contained in:
Faheedkhan 2025-06-18 20:41:15 +03:00
parent 0859bb3255
commit 9d6bd24937
9 changed files with 28 additions and 11 deletions

View File

@ -8,6 +8,7 @@ from django.forms import ValidationError
from django.utils.formats import number_format
from django_ledger.io.io_core import get_localdate,validate_activity
from django_ledger.models import InvoiceModel, JournalEntryModel, BillModel
from django.db.models import Case, Value, When, IntegerField
register = template.Library()
@ -398,9 +399,23 @@ def bill_item_formset_table(context, item_formset):
def transactions_table(object_type: Union[JournalEntryModel, BillModel, InvoiceModel], style='detail'):
if isinstance(object_type, JournalEntryModel):
transaction_model_qs = object_type.transactionmodel_set.all().with_annotated_details().order_by(
'-timestamp')
'-timestamp',
)
elif isinstance(object_type, BillModel):
transaction_model_qs = object_type.get_transaction_queryset(annotated=True).order_by('-timestamp')
# Specific ordering for BillModel (timestamp ascending, then debit before credit)
qs = object_type.get_transaction_queryset(annotated=True)
transaction_model_qs = qs.annotate(
debit_credit_sort_order=Case(
When(tx_type='debit', then=Value(0)), # Debits will get sort order 0
When(tx_type='credit', then=Value(1)), # Credits will get sort order 1
default=Value(2), # Fallback for any other tx_type, if applicable
output_field=IntegerField()
)
).order_by(
'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):
transaction_model_qs = object_type.get_transaction_queryset(annotated=True).order_by('-timestamp')
else:

View File

@ -17,7 +17,9 @@
</tr>
</thead>
<tbody class="fs-9">
{% for transaction_model in transaction_model_qs %}
<tr>
<td class=" white-space-nowrap align-middle ps-2" scope="col" >{{ transaction_model.timestamp }}</td>
<td class=" white-space-nowrap align-middle" scope="col">{{ transaction_model.account_code }}</td>

View File

@ -3,8 +3,8 @@
{% block title %}{{ _('Leads')|capfirst }}{% endblock title %}
{% block content %}
<div class="row g-3">
<h2 class="mb-4">{{ _("Leads")|capfirst }}</h2>
<div class="row g-3 mt-4">
<h2 class="mb-2">{{ _("Leads")|capfirst }}</h2>
<!-- Action Tracking Modal -->
{% include "crm/leads/partials/update_action.html" %}

View File

@ -2,7 +2,7 @@
{% load i18n static humanize %}
{% block title %}{{ _("Opportunity Detail") }}{% endblock title %}
{% block content %}
<div class="row align-items-center justify-content-between g-3 mb-4">
<div class="row align-items-center justify-content-between g-3 mb-4 mt-4">
<div class="col-12 col-md-auto">
<h2 class="mb-0">{{ _("Opportunity details")}}</h2>
</div>

View File

@ -3,7 +3,7 @@
{% load custom_filters %}
{% block title %}{{ _("Opportunities") }}{% endblock title %}
{% block content %}
<div class="row g-3">
<div class="row g-3 mt-4">
<div class="col-12">
<h2 class="mb-3">{{ _("Opportunities") }}</h2>
</div>

View File

@ -5,8 +5,8 @@
{% block vendors %}<a class="nav-link active">{{ _("Customers")|capfirst }}</a>{% endblock %}
{% block content %}
<div class="row">
<h4 class="mb-4">{{ _("Customers")|capfirst }}</h4>
<div class="row g-3 mt-4">
<h2 class="mb-2">{{ _("Customers")|capfirst }}</h2>
<div class="row g-3 justify-content-between mb-4">
<div class="col-auto">
<div class="d-md-flex justify-content-between">

View File

@ -53,7 +53,7 @@
</tr>
{% empty %}
<tr>
<td colspan="6" class="text-center">{% trans "No Quotations Found" %}</td>
<td colspan="6" class="text-center">{% trans "No Quotation Found" %}</td>
</tr>
{% endfor %}
</tbody>

View File

@ -37,7 +37,7 @@
</tr>
{% empty %}
<tr>
<td colspan="6" class="text-center">{% trans "No Quotations Found" %}</td>
<td colspan="6" class="text-center">{% trans "No journal entry Found" %}</td>
</tr>
{% endfor %}
</tbody>

View File

@ -46,7 +46,7 @@
</tr>
{% empty %}
<tr>
<td colspan="6" class="text-center">{% trans "No Quotations Found" %}</td>
<td colspan="6" class="text-center">{% trans "No Order Found" %}</td>
</tr>
{% endfor %}
</tbody>