Skip to content

A local-first personal finance app

[Goals] Negate schedule amount to budget if income (#2125)

Martin Frenche589163bb75f
diff --git a/packages/loot-core/src/server/budget/goals/goalsSchedule.ts b/packages/loot-core/src/server/budget/goals/goalsSchedule.ts
index ef5bc7ee29..b311d5bcf9 100644
--- a/packages/loot-core/src/server/budget/goals/goalsSchedule.ts
+++ b/packages/loot-core/src/server/budget/goals/goalsSchedule.ts
@@ -17,6 +17,7 @@ export async function goalsSchedule(
last_month_balance,
to_budget,
errors,
+ category,
) {
if (!scheduleFlag) {
scheduleFlag = true;
@@ -34,12 +35,15 @@ export async function goalsSchedule(
const conditions = rule.serialize().conditions;
const { date: dateConditions, amount: amountCondition } =
extractScheduleConds(conditions);
+ const sign = category.is_income ? 1 : -1;
const target =
amountCondition.op === 'isbetween'
- ? -Math.round(
- amountCondition.value.num1 + amountCondition.value.num2,
- ) / 2
- : -amountCondition.value;
+ ? (sign *
+ Math.round(
+ amountCondition.value.num1 + amountCondition.value.num2,
+ )) /
+ 2
+ : sign * amountCondition.value;
const next_date_string = getNextDate(
dateConditions,
monthUtils._parse(current_month),
diff --git a/packages/loot-core/src/server/budget/goaltemplates.ts b/packages/loot-core/src/server/budget/goaltemplates.ts
index 6c71ee2a19..256053eda4 100644
--- a/packages/loot-core/src/server/budget/goaltemplates.ts
+++ b/packages/loot-core/src/server/budget/goaltemplates.ts
@@ -590,6 +590,7 @@ async function applyCategoryTemplate(
last_month_balance,
to_budget,
errors,
+ category,
);
to_budget = goalsReturn.to_budget;
errors = goalsReturn.errors;
diff --git a/upcoming-release-notes/2125.md b/upcoming-release-notes/2125.md
new file mode 100644
index 0000000000..0197a4b53a
--- /dev/null
+++ b/upcoming-release-notes/2125.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [mk-french]
+---
+
+Goals: Negate schedule amount to budget if income