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

Goals: fix remaining funds calculation (#1410)

Fixes #1409. This makes the template processing not include previously
budgeted funds in the return value.
parent e7d8fdf5
No related branches found
No related tags found
No related merge requests found
......@@ -191,6 +191,10 @@ async function processTemplate(month, force, category_templates) {
].join('\n'),
),
);
let prev_budgeted = await getSheetValue(
sheetName,
`budget-${category.id}`,
);
let { amount: to_budget, errors: applyErrors } =
await applyCategoryTemplate(
category,
......@@ -200,13 +204,14 @@ async function processTemplate(month, force, category_templates) {
remainder_scale,
available_start,
available_remaining,
prev_budgeted,
force,
);
if (to_budget != null) {
num_applied++;
templateBudget.push({
category: category.id,
amount: to_budget,
amount: to_budget + prev_budgeted,
});
available_remaining -= to_budget;
}
......@@ -307,6 +312,7 @@ async function applyCategoryTemplate(
remainder_scale,
available_start,
budgetAvailable,
budgeted,
force,
) {
let current_month = `${month}-01`;
......@@ -377,10 +383,9 @@ async function applyCategoryTemplate(
});
}
let sheetName = monthUtils.sheetForMonth(month);
let budgeted = await getSheetValue(sheetName, `budget-${category.id}`);
let spent = await getSheetValue(sheetName, `sum-amount-${category.id}`);
let balance = await getSheetValue(sheetName, `leftover-${category.id}`);
let to_budget = budgeted;
let to_budget = 0;
let limit;
let hold;
let last_month_balance = balance - spent - budgeted;
......@@ -669,8 +674,8 @@ async function applyCategoryTemplate(
? Math.round(template.weight)
: Math.round(remainder_scale * template.weight);
// can over budget with the rounding, so checking that
if (to_budget >= budgetAvailable + budgeted) {
to_budget = budgetAvailable + budgeted;
if (to_budget >= budgetAvailable) {
to_budget = budgetAvailable;
// check if there is 1 cent leftover from rounding
} else if (budgetAvailable - to_budget === 1) {
to_budget = to_budget + 1;
......
---
category: Bugfix
authors: [youngcw]
---
Goals: Fix tracking of remaining funds when using priorities
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