fix(insights:category-explorer): wrong sums

This commit is contained in:
Herculino Trotta
2025-02-19 16:01:53 -03:00
parent 5c9db10710
commit b228e4ec26
3 changed files with 28 additions and 34 deletions

View File

@@ -14,8 +14,7 @@ def get_category_sums_by_account(queryset, category=None):
current_income=Coalesce(
Sum(
Case(
When(type="IN", then="amount"),
When(is_paid=True, then="amount"),
When(type="IN", is_paid=True, then="amount"),
default=Value(0),
output_field=DecimalField(max_digits=42, decimal_places=30),
)
@@ -26,8 +25,7 @@ def get_category_sums_by_account(queryset, category=None):
current_expense=Coalesce(
Sum(
Case(
When(type="EX", then=-F("amount")),
When(is_paid=True, then="amount"),
When(type="EX", is_paid=True, then=-F("amount")),
default=Value(0),
output_field=DecimalField(max_digits=42, decimal_places=30),
)
@@ -38,8 +36,7 @@ def get_category_sums_by_account(queryset, category=None):
projected_income=Coalesce(
Sum(
Case(
When(type="IN", then="amount"),
When(is_paid=False, then="amount"),
When(type="IN", is_paid=False, then="amount"),
default=Value(0),
output_field=DecimalField(max_digits=42, decimal_places=30),
)
@@ -50,8 +47,7 @@ def get_category_sums_by_account(queryset, category=None):
projected_expense=Coalesce(
Sum(
Case(
When(type="EX", then=-F("amount")),
When(is_paid=False, then="amount"),
When(type="EX", is_paid=False, then=-F("amount")),
default=Value(0),
output_field=DecimalField(max_digits=42, decimal_places=30),
)
@@ -97,8 +93,7 @@ def get_category_sums_by_currency(queryset, category=None):
current_income=Coalesce(
Sum(
Case(
When(type="IN", then="amount"),
When(is_paid=True, then="amount"),
When(type="IN", is_paid=True, then="amount"),
default=Value(0),
output_field=DecimalField(max_digits=42, decimal_places=30),
)
@@ -109,8 +104,7 @@ def get_category_sums_by_currency(queryset, category=None):
current_expense=Coalesce(
Sum(
Case(
When(type="EX", then=-F("amount")),
When(is_paid=True, then="amount"),
When(type="EX", is_paid=True, then=-F("amount")),
default=Value(0),
output_field=DecimalField(max_digits=42, decimal_places=30),
)
@@ -121,8 +115,7 @@ def get_category_sums_by_currency(queryset, category=None):
projected_income=Coalesce(
Sum(
Case(
When(type="IN", then="amount"),
When(is_paid=False, then="amount"),
When(type="IN", is_paid=False, then="amount"),
default=Value(0),
output_field=DecimalField(max_digits=42, decimal_places=30),
)
@@ -133,8 +126,7 @@ def get_category_sums_by_currency(queryset, category=None):
projected_expense=Coalesce(
Sum(
Case(
When(type="EX", then=-F("amount")),
When(is_paid=False, then="amount"),
When(type="EX", is_paid=False, then=-F("amount")),
default=Value(0),
output_field=DecimalField(max_digits=42, decimal_places=30),
)

View File

@@ -57,9 +57,9 @@
labels: accountData.labels,
datasets: [
{
label: "{% trans 'Current Income' %}",
data: accountData.datasets[0].data,
backgroundColor: '#4dde80',
label: "{% trans 'Projected Expenses' %}",
data: accountData.datasets[3].data,
backgroundColor: '#f8717180', // Added transparency
stack: 'stack0'
},
{
@@ -68,18 +68,19 @@
backgroundColor: '#f87171',
stack: 'stack0'
},
{
label: "{% trans 'Current Income' %}",
data: accountData.datasets[0].data,
backgroundColor: '#4dde80',
stack: 'stack0'
},
{
label: "{% trans 'Projected Income' %}",
data: accountData.datasets[2].data,
backgroundColor: '#4dde8080', // Added transparency
stack: 'stack0'
},
{
label: "{% trans 'Projected Expenses' %}",
data: accountData.datasets[3].data,
backgroundColor: '#f8717180', // Added transparency
stack: 'stack0'
}
]
},
options: {

View File

@@ -57,9 +57,9 @@
labels: currencyData.labels,
datasets: [
{
label: "{% trans 'Current Income' %}",
data: currencyData.datasets[0].data,
backgroundColor: '#4dde80',
label: "{% trans 'Projected Expenses' %}",
data: currencyData.datasets[3].data,
backgroundColor: '#f8717180', // Added transparency
stack: 'stack0'
},
{
@@ -68,18 +68,19 @@
backgroundColor: '#f87171',
stack: 'stack0'
},
{
label: "{% trans 'Current Income' %}",
data: currencyData.datasets[0].data,
backgroundColor: '#4dde80',
stack: 'stack0'
},
{
label: "{% trans 'Projected Income' %}",
data: currencyData.datasets[2].data,
backgroundColor: '#4dde8080', // Added transparency
stack: 'stack0'
},
{
label: "{% trans 'Projected Expenses' %}",
data: currencyData.datasets[3].data,
backgroundColor: '#f8717180', // Added transparency
stack: 'stack0'
}
]
},
options: chartOptions