A local-first personal finance app
correctly ignore hidden categories when using "Set Average Budget" (#5239)
lougeorge979fa43c4a3d
diff --git a/packages/loot-core/src/server/budget/actions.ts b/packages/loot-core/src/server/budget/actions.tsindex 50142538a6..234e217f07 100644--- a/packages/loot-core/src/server/budget/actions.ts+++ b/packages/loot-core/src/server/budget/actions.ts@@ -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 () => {diff --git a/packages/loot-core/src/server/db/types/index.ts b/packages/loot-core/src/server/db/types/index.tsindex c6accb44f0..4358620540 100644--- a/packages/loot-core/src/server/db/types/index.ts+++ b/packages/loot-core/src/server/db/types/index.ts@@ -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'];diff --git a/upcoming-release-notes/5239.md b/upcoming-release-notes/5239.mdnew file mode 100644index 0000000000..6af17332fd--- /dev/null+++ b/upcoming-release-notes/5239.md@@ -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.