From e589163bb75fcb33becde79c628f26f2e11110fc Mon Sep 17 00:00:00 2001 From: Martin French Date: Wed, 3 Jan 2024 22:02:07 +0800 Subject: [PATCH] [Goals] Negate schedule amount to budget if income (#2125) * Negate schedule amount to budget if income * Release notes * Determine sign at initial calc To ensure no unintended impact to remainder calcs etc. * Lint fixes --- .../src/server/budget/goals/goalsSchedule.ts | 12 ++++++++---- .../loot-core/src/server/budget/goaltemplates.ts | 1 + upcoming-release-notes/2125.md | 6 ++++++ 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 upcoming-release-notes/2125.md diff --git a/packages/loot-core/src/server/budget/goals/goalsSchedule.ts b/packages/loot-core/src/server/budget/goals/goalsSchedule.ts index ef5bc7ee290..b311d5bcf9e 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 6c71ee2a191..256053eda4a 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 00000000000..0197a4b53a3 --- /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