From f136b269374ab88964906624b0eb450f5b969e18 Mon Sep 17 00:00:00 2001 From: Faheedkhan Date: Mon, 1 Sep 2025 14:22:11 +0300 Subject: [PATCH] gross profit loss---negative filter --- inventory/templatetags/custom_filters.py | 11 ++++++++++- .../dashboards/partials/financial_data_cards.html | 11 +++++++++-- templates/items/service/service_create.html | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/inventory/templatetags/custom_filters.py b/inventory/templatetags/custom_filters.py index 72f5c9f8..f096dcf0 100644 --- a/inventory/templatetags/custom_filters.py +++ b/inventory/templatetags/custom_filters.py @@ -13,7 +13,16 @@ from django.db.models import Case, Value, When, IntegerField register = template.Library() - +@register.filter +def is_negative(value): + """ + Checks if the given value is a negative number. + """ + try: + return float(value) < 0 + except (ValueError, TypeError): + return False + @register.filter def get_percentage(value, total): try: diff --git a/templates/dashboards/partials/financial_data_cards.html b/templates/dashboards/partials/financial_data_cards.html index 373b5072..e3216c64 100644 --- a/templates/dashboards/partials/financial_data_cards.html +++ b/templates/dashboards/partials/financial_data_cards.html @@ -302,9 +302,16 @@

{% trans "Gross Profit" %}

-

+ + {% if gross_profit|is_negative %} +

{{ gross_profit|floatformat:2 }} -

+ + {% else %} +

+ {{ gross_profit|floatformat:2 }} +

+ {% endif %}
diff --git a/templates/items/service/service_create.html b/templates/items/service/service_create.html index c8ff00d9..8f4dd33e 100644 --- a/templates/items/service/service_create.html +++ b/templates/items/service/service_create.html @@ -11,7 +11,7 @@ {% endif %} {% endblock %} {% block content %} -
+