From 55f064ee7c93a7619df30ec6480976bf5d1252ab Mon Sep 17 00:00:00 2001 From: Herculino Trotta Date: Sun, 8 Nov 2026 20:16:13 -0300 Subject: [PATCH] feat(distribution): bracket projected + current segments with their sum Remove the unused exchanged branch from calculate_percentage_distribution; nothing read it and it mixed up income_current with expense_projected. --- app/apps/transactions/utils/calculations.py | 67 +------------------ .../cotton/ui/percentage_distribution.html | 20 +++++- 2 files changed, 22 insertions(+), 65 deletions(-) diff --git a/app/apps/transactions/utils/calculations.py b/app/apps/transactions/utils/calculations.py index 0597544b..0a6b3907 100644 --- a/app/apps/transactions/utils/calculations.py +++ b/app/apps/transactions/utils/calculations.py @@ -377,70 +377,9 @@ def calculate_percentage_distribution(currency_totals): "expense_projected": 0, } - # If there's exchanged data, calculate percentages for that too - if "exchanged" in data: - exchanged_total = sum( - [ - abs(data.get("exchanged", {}).get("income_current", Decimal("0"))), - abs( - data.get("exchanged", {}).get("income_projected", Decimal("0")) - ), - abs(data.get("exchanged", {}).get("expense_current", Decimal("0"))), - abs(data.get("exchanged", {}).get("income_current", Decimal("0"))), - ] - ) - - percentages[currency_id]["exchanged"] = { - "currency": data["exchanged"]["currency"], - "percentages": {}, - } - - if exchanged_total > 0: - percentages[currency_id]["exchanged"]["percentages"] = { - "income_current": ( - abs( - data.get("exchanged", {}).get( - "income_current", Decimal("0") - ) - ) - / exchanged_total - ) - * 100, - "income_projected": ( - abs( - data.get("exchanged", {}).get( - "income_projected", Decimal("0") - ) - ) - / exchanged_total - ) - * 100, - "expense_current": ( - abs( - data.get("exchanged", {}).get( - "expense_current", Decimal("0") - ) - ) - / exchanged_total - ) - * 100, - "expense_projected": ( - abs( - data.get("exchanged", {}).get( - "income_current", Decimal("0") - ) - ) - / exchanged_total - ) - * 100, - } - else: - percentages[currency_id]["exchanged"]["percentages"] = { - "income_current": 0, - "income_projected": 0, - "expense_current": 0, - "expense_projected": 0, - } + p = percentages[currency_id]["percentages"] + p["income_total"] = p["income_current"] + p["income_projected"] + p["expense_total"] = p["expense_current"] + p["expense_projected"] return percentages diff --git a/app/templates/cotton/ui/percentage_distribution.html b/app/templates/cotton/ui/percentage_distribution.html index c28a331a..64855698 100644 --- a/app/templates/cotton/ui/percentage_distribution.html +++ b/app/templates/cotton/ui/percentage_distribution.html @@ -54,4 +54,22 @@ aria-valuemin="0" aria-valuemax="100"> - \ No newline at end of file + +{% with p=percentage.percentages %} +{% if p.income_projected > 0 and p.income_current > 0 or p.expense_projected > 0 and p.expense_current > 0 %} + +{% endif %} +{% endwith %} \ No newline at end of file