Skip to content
Snippets Groups Projects
Unverified Commit 12719e30 authored by lelemm's avatar lelemm Committed by GitHub
Browse files

FIX: For Report Budget, the income categories are negative when using 'Set...

FIX: For Report Budget, the income categories are negative when using 'Set budgets to 3 month average' (#2862)

* FIX: For Report Budget, the income categories are negative when using 'Set budgets to 3 month average'. This fix solves this issue

* added 2862.md

* Ajustments for category menu not closing properly and fix to negative values for income category copy budget

* fix lint

* changed variable name without changing references after lint ajust

* retrigger checks

* smaller 2862.md
parent e178d991
No related branches found
No related tags found
No related merge requests found
......@@ -228,6 +228,7 @@ export const CategoryMonth = memo(function CategoryMonth({
onBudgetAction?.(month, 'copy-single-last', {
category: category.id,
});
setMenuOpen(false);
}}
onSetMonthsAverage={numberOfMonths => {
if (
......@@ -241,11 +242,13 @@ export const CategoryMonth = memo(function CategoryMonth({
onBudgetAction?.(month, `set-single-${numberOfMonths}-avg`, {
category: category.id,
});
setMenuOpen(false);
}}
onApplyBudgetTemplate={() => {
onBudgetAction?.(month, 'apply-single-category-template', {
category: category.id,
});
setMenuOpen(false);
}}
/>
</Popover>
......
......@@ -258,8 +258,13 @@ export async function set3MonthAvg({
'sum-amount-' + cat.id,
);
const avg = Math.round((spent1 + spent2 + spent3) / 3);
setBudget({ category: cat.id, month, amount: -avg });
let avg = Math.round((spent1 + spent2 + spent3) / 3);
if (cat.is_income === 0) {
avg *= -1;
}
setBudget({ category: cat.id, month, amount: avg });
}
});
}
......@@ -273,6 +278,11 @@ export async function setNMonthAvg({
N: number;
category: string;
}): Promise<void> {
const categoryFromDb = await db.first(
'SELECT is_income FROM v_categories WHERE id = ?',
[category],
);
let prevMonth = monthUtils.prevMonth(month);
let sumAmount = 0;
for (let l = 0; l < N; l++) {
......@@ -283,8 +293,13 @@ export async function setNMonthAvg({
prevMonth = monthUtils.prevMonth(prevMonth);
}
await batchMessages(async () => {
const avg = Math.round(sumAmount / N);
setBudget({ category, month, amount: -avg });
let avg = Math.round(sumAmount / N);
if (categoryFromDb.is_income === 0) {
avg *= -1;
}
setBudget({ category, month, amount: avg });
});
}
......
---
category: Bugfix
authors: [lelemm]
---
For Report Budget, income categories were incorrectly showing as negative when using 'Set budgets to 3 month average'.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment