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

[Goals]: fully skip budgeted categories when only applying (#2099)

* remove budgeted categories from list when only applying

* cleanup

* speed up the category removal

* note
parent 9ea8e86b
No related branches found
No related tags found
No related merge requests found
...@@ -151,12 +151,12 @@ async function processTemplate( ...@@ -151,12 +151,12 @@ async function processTemplate(
): Promise<Notification> { ): Promise<Notification> {
let num_applied = 0; let num_applied = 0;
let errors = []; let errors = [];
let originalCategoryBalance = [];
const idealTemplate = []; const idealTemplate = [];
const setToZero = []; const setToZero = [];
let priority_list = []; let priority_list = [];
const categories = await getCategories(); const categories = await getCategories();
const categories_remove = [];
//clears templated categories //clears templated categories
for (let c = 0; c < categories.length; c++) { for (let c = 0; c < categories.length; c++) {
...@@ -176,20 +176,29 @@ async function processTemplate( ...@@ -176,20 +176,29 @@ async function processTemplate(
} }
} }
if (budgeted) { if (budgeted) {
originalCategoryBalance.push({ if (!force) {
category: category.id, // save index of category to remove
amount: budgeted, categories_remove.push(c);
isIncome: category.is_income, } else {
isTemplate: template ? true : false, // if we are overwritting add this category to list to zero
}); setToZero.push({
setToZero.push({ category: category.id,
category: category.id, amount: 0,
amount: 0, isIncome: category.is_income,
isIncome: category.is_income, isTemplate: template ? true : false,
isTemplate: template ? true : false, });
}); }
} }
} }
// remove the categories we are skipping
// Go backwards through the list so the indexes don't change
// on the categories we need
for (let i = categories_remove.length - 1; i >= 0; i--) {
categories.splice(categories_remove[i], 1);
}
// zero out the categories that need it
await setGoalBudget({ await setGoalBudget({
month, month,
templateBudget: setToZero.filter(f => f.isTemplate === true), templateBudget: setToZero.filter(f => f.isTemplate === true),
...@@ -339,33 +348,6 @@ async function processTemplate( ...@@ -339,33 +348,6 @@ async function processTemplate(
await setGoalBudget({ month, templateBudget }); await setGoalBudget({ month, templateBudget });
} }
await setCategoryTargets({ month, idealTemplate }); await setCategoryTargets({ month, idealTemplate });
if (!force) {
//if overwrite is not preferred, set cell to original value;
originalCategoryBalance = originalCategoryBalance.filter(
c => c.isIncome === 0 && c.isTemplate,
);
for (let l = 0; l < originalCategoryBalance.length; l++) {
await setBudget({
category: originalCategoryBalance[l].category,
month,
amount: originalCategoryBalance[l].amount,
});
//if overwrite is not preferred, remove template errors for category
let j = errors.length;
for (let k = 0; k < j; k++) {
if (
errors[k].includes(
categories.filter(
c => c.id === originalCategoryBalance[l].category,
)[0].name,
)
) {
errors.splice(k, 1);
j--;
}
}
}
}
if (num_applied === 0) { if (num_applied === 0) {
if (errors.length) { if (errors.length) {
return { return {
......
---
category: Bugfix
authors: [youngcw]
---
[Goals]: Fix over budget condition with using apply instead of overwrite
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