Skip to content
Snippets Groups Projects
Unverified Commit adf205db authored by shall0pass's avatar shall0pass Committed by GitHub
Browse files

Allow goal template 'by' matches to compound (#860)

I believe this change allows for having multiple 'by' rules in the same
category. It seems to be working well for my purposes, but I would
appreciate further testing to assure there aren't regressions.

Example:

#template 300 by 2023-06
#template 3000 by 2023-08

Before this PR, having these two lines in the notes would only budget
funds for the earliest of the two strings and ignore the 3000 funding
target. With this PR, the sum of the two funding targets will be
respected.
parent f9a1b094
No related branches found
No related tags found
No related merge requests found
......@@ -131,7 +131,6 @@ async function applyCategoryTemplate(category, template_lines, month, force) {
let current_month = new Date(`${month}-01`);
// remove lines for past dates, calculate repeating dates
let got_by = false;
template_lines = template_lines.filter(template => {
switch (template.type) {
case 'by':
......@@ -175,29 +174,16 @@ async function applyCategoryTemplate(category, template_lines, month, force) {
});
if (template_lines.length > 1) {
template_lines = template_lines
.sort((a, b) => {
if (a.type === 'by' && !a.annual) {
return differenceInCalendarMonths(
new Date(`${a.month}-01`),
new Date(`${b.month}-01`),
);
} else {
return a.type.localeCompare(b.type);
}
})
.filter(el => {
if (el.type === 'by') {
if (!got_by) {
got_by = true;
return el;
} else {
return null;
}
} else {
return el;
}
});
template_lines = template_lines.sort((a, b) => {
if (a.type === 'by' && !a.annual) {
return differenceInCalendarMonths(
new Date(`${a.month}-01`),
new Date(`${b.month}-01`),
);
} else {
return a.type.localeCompare(b.type);
}
});
}
let to_budget = 0;
......
---
category: Enhancement
authors: [shall0pass]
---
Allow goal template 'by' matches to compound
\ No newline at end of file
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