Skip to content
Snippets Groups Projects
Unverified Commit aff5bba4 authored by Julian Dominguez-Schatz's avatar Julian Dominguez-Schatz Committed by GitHub
Browse files

Template only the relevant amount in a split-schedule category (#2652)

* Template only the relevant amount in a split-schedule category

* Add release notes

* Adjust sign correctly depending on category type
parent d79b8c6c
No related branches found
No related tags found
No related merge requests found
......@@ -673,17 +673,16 @@ export class Rule {
});
}
execActions(object) {
execActions<T>(object: T): Partial<T> {
const result = execActions(this.actions, {
...object,
subtransactions: object.subtransactions,
});
const changes = Object.keys(result).reduce((prev, cur) => {
if (result[cur] !== object[cur]) {
prev[cur] = result[cur];
}
return prev;
}, {});
}, {} as T);
return changes;
}
......
......@@ -22,15 +22,28 @@ async function createScheduleList(template, current_month, category) {
const conditions = rule.serialize().conditions;
const { date: dateConditions, amount: amountCondition } =
extractScheduleConds(conditions);
const sign = category.is_income ? 1 : -1;
const target =
const scheduleAmount =
amountCondition.op === 'isbetween'
? (sign *
Math.round(
amountCondition.value.num1 + amountCondition.value.num2,
)) /
? Math.round(amountCondition.value.num1 + amountCondition.value.num2) /
2
: sign * amountCondition.value;
: amountCondition.value;
const { amount: postRuleAmount, subtransactions } = rule.execActions({
amount: scheduleAmount,
category: category.id,
subtransactions: [],
});
const categorySubtransactions = subtransactions?.filter(
t => t.category === category.id,
);
// Unless the current category is relevant to the schedule, target the post-rule amount.
const sign = category.is_income ? 1 : -1;
const target =
sign *
(categorySubtransactions?.length
? categorySubtransactions.reduce((acc, t) => acc + t.amount, 0)
: postRuleAmount ?? scheduleAmount);
const next_date_string = getNextDate(
dateConditions,
monthUtils._parse(current_month),
......
......@@ -107,7 +107,7 @@ export function getNextDate(
return null;
}
export async function getRuleForSchedule(id) {
export async function getRuleForSchedule(id: string | null): Promise<Rule> {
if (id == null) {
throw new Error('Schedule not attached to a rule');
}
......
---
category: Enhancements
authors: [jfdoming]
---
Template only the relevant amount in a split-schedule category
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