Skip to content

Commit

Permalink
[Goals] Negate schedule amount to budget if income (actualbudget#2125)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mk-french authored Jan 3, 2024
1 parent d2b86d1 commit e589163
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/loot-core/src/server/budget/goals/goalsSchedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export async function goalsSchedule(
last_month_balance,
to_budget,
errors,
category,
) {
if (!scheduleFlag) {
scheduleFlag = true;
Expand All @@ -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),
Expand Down
1 change: 1 addition & 0 deletions packages/loot-core/src/server/budget/goaltemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ async function applyCategoryTemplate(
last_month_balance,
to_budget,
errors,
category,
);
to_budget = goalsReturn.to_budget;
errors = goalsReturn.errors;
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/2125.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [mk-french]
---

Goals: Negate schedule amount to budget if income

0 comments on commit e589163

Please sign in to comment.