Skip to content
Snippets Groups Projects
Unverified Commit 7d80c3ed authored by youngcw's avatar youngcw Committed by GitHub
Browse files

Goal Templates: add option to prevent removing funds when using "up to" in goal (#1004)

parent f7aa313a
No related branches found
No related tags found
No related merge requests found
......@@ -16,7 +16,7 @@ expr
} }
/ priority: priority? _? monthly: amount limit: limit?
{ return { type: 'simple', monthly, limit, priority: +priority } }
/ priority: priority? _? upTo _ limit: amount
/ priority: priority? _? limit: limit
{ return { type: 'simple', limit , priority: +priority } }
/ priority: priority? _? schedule _ name: name
{ return { type: 'schedule', name, priority: +priority } }
......@@ -27,7 +27,9 @@ repeat 'repeat interval'
/ 'year'i { return { annual: true } }
/ years: d _ 'years'i { return { annual: true, repeat: +years } }
limit = _ upTo? _ amount: amount { return amount }
limit = _? upTo _ amount: amount _ 'hold'i { return {amount: amount, hold: true } }
/ _? upTo _ amount: amount { return {amount: amount, hold: false } }
weekCount
= week { return null }
......
......@@ -299,6 +299,7 @@ async function applyCategoryTemplate(
let budgetAvailable = await getSheetValue(sheetName, `to-budget`);
let to_budget = budgeted;
let limit;
let hold;
let last_month_balance = balance - spent - budgeted;
let totalTarget = 0;
let totalMonths = 0;
......@@ -313,7 +314,8 @@ async function applyCategoryTemplate(
errors.push(`More than one “up to” limit found.`);
return { errors };
} else {
limit = amountToInteger(template.limit);
limit = amountToInteger(template.limit.amount);
hold = template.limit.hold;
}
}
let increment = 0;
......@@ -381,7 +383,8 @@ async function applyCategoryTemplate(
errors.push(`More than one “up to” limit found.`);
return { errors };
} else {
limit = amountToInteger(template.limit);
limit = amountToInteger(template.limit.amount);
hold = template.limit.hold;
}
}
let w = new Date(template.starting);
......@@ -548,7 +551,9 @@ async function applyCategoryTemplate(
}
if (limit != null) {
if (to_budget + last_month_balance > limit) {
if (hold && balance > limit) {
to_budget = 0;
} else if (to_budget + last_month_balance > limit) {
to_budget = limit - last_month_balance;
}
}
......
---
category: Enhancements
authors: [youngcw]
---
Add option to not remove funds when using an "up to" goal template.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment