mirror of
https://github.com/actualbudget/actual.git
synced 2026-04-27 17:48:17 -05:00
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
This commit is contained in:
committed by
GitHub
parent
d79b8c6cb2
commit
aff5bba4ec
@@ -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 scheduleAmount =
|
||||
amountCondition.op === 'isbetween'
|
||||
? Math.round(amountCondition.value.num1 + amountCondition.value.num2) /
|
||||
2
|
||||
: 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 =
|
||||
amountCondition.op === 'isbetween'
|
||||
? (sign *
|
||||
Math.round(
|
||||
amountCondition.value.num1 + amountCondition.value.num2,
|
||||
)) /
|
||||
2
|
||||
: sign * amountCondition.value;
|
||||
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');
|
||||
}
|
||||
|
||||
6
upcoming-release-notes/2652.md
Normal file
6
upcoming-release-notes/2652.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Enhancements
|
||||
authors: [jfdoming]
|
||||
---
|
||||
|
||||
Template only the relevant amount in a split-schedule category
|
||||
Reference in New Issue
Block a user