mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-11 20:44:32 -05:00
correctly ignore hidden categories when using "Set Average Budget" (#5239)
* fixed setAverage functions to ignore hidden categories * Add logic to ignore hidden categories in budget actions * Modify SQL statements in setAverage functions to also exclude categoryGroups and change DbViewCategory type definition to include hidden flag of the group a category belongs to * [autofix.ci] apply automated fixes * Revert setZero functionality to set all budget categories and category groups to zero, including hidden ones * Add new type DbViewCategoryWithGroupHidden which includes a flag for whether the group a category belongs to is hidden or not, and have setAvg functions use that type instead --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -261,8 +261,13 @@ export async function set3MonthAvg({
|
||||
}: {
|
||||
month: string;
|
||||
}): Promise<void> {
|
||||
const categories = await db.all<db.DbViewCategory>(
|
||||
'SELECT * FROM v_categories WHERE tombstone = 0',
|
||||
const categories = await db.all<db.DbViewCategoryWithGroupHidden>(
|
||||
`
|
||||
SELECT c.*
|
||||
FROM categories c
|
||||
LEFT JOIN category_groups g ON c.cat_group = g.id
|
||||
WHERE c.tombstone = 0 AND c.hidden = 0 AND g.hidden = 0
|
||||
`,
|
||||
);
|
||||
|
||||
const prevMonth1 = monthUtils.prevMonth(month);
|
||||
@@ -304,8 +309,13 @@ export async function set12MonthAvg({
|
||||
}: {
|
||||
month: string;
|
||||
}): Promise<void> {
|
||||
const categories = await db.all<db.DbViewCategory>(
|
||||
'SELECT * FROM v_categories WHERE tombstone = 0',
|
||||
const categories = await db.all<db.DbViewCategoryWithGroupHidden>(
|
||||
`
|
||||
SELECT c.*
|
||||
FROM categories c
|
||||
LEFT JOIN category_groups g ON c.cat_group = g.id
|
||||
WHERE c.tombstone = 0 AND c.hidden = 0 AND g.hidden = 0
|
||||
`,
|
||||
);
|
||||
|
||||
await batchMessages(async () => {
|
||||
@@ -323,8 +333,13 @@ export async function set6MonthAvg({
|
||||
}: {
|
||||
month: string;
|
||||
}): Promise<void> {
|
||||
const categories = await db.all<db.DbViewCategory>(
|
||||
'SELECT * FROM v_categories WHERE tombstone = 0',
|
||||
const categories = await db.all<db.DbViewCategoryWithGroupHidden>(
|
||||
`
|
||||
SELECT c.*
|
||||
FROM categories c
|
||||
LEFT JOIN category_groups g ON c.cat_group = g.id
|
||||
WHERE c.tombstone = 0 AND c.hidden = 0 AND g.hidden = 0
|
||||
`,
|
||||
);
|
||||
|
||||
await batchMessages(async () => {
|
||||
|
||||
@@ -286,6 +286,17 @@ export type DbViewCategory = {
|
||||
tombstone: DbCategory['tombstone'];
|
||||
};
|
||||
|
||||
export type DbViewCategoryWithGroupHidden = {
|
||||
id: DbCategory['id'];
|
||||
name: DbCategory['name'];
|
||||
is_income: DbCategory['is_income'];
|
||||
hidden: DbCategory['hidden'];
|
||||
group: DbCategoryGroup['id'];
|
||||
group_hidden: DbCategoryGroup['hidden'];
|
||||
sort_order: DbCategory['sort_order'];
|
||||
tombstone: DbCategory['tombstone'];
|
||||
};
|
||||
|
||||
export type DbViewPayee = {
|
||||
id: DbPayee['id'];
|
||||
name: DbAccount['name'] | DbPayee['name'];
|
||||
|
||||
6
upcoming-release-notes/5239.md
Normal file
6
upcoming-release-notes/5239.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Bugfix
|
||||
authors: [lougeorge]
|
||||
---
|
||||
|
||||
Fixed the functions to set budget targets based on past averages to correctly ignore hidden categories. Further work is required to handle hidden category groups, including potentially creating new views or migrations to expose relevant information to the target setting functions.
|
||||
Reference in New Issue
Block a user