mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-11 12:43:09 -05:00
Fix rounding of split rules (#4190)
* Fix rounding of split rules * Add release notes * PR feedback
This commit is contained in:
committed by
GitHub
parent
eb31071043
commit
705985a8df
@@ -677,6 +677,43 @@ describe('Rule', () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('remainder rounds correctly and only if necessary', () => {
|
||||
const rule = new Rule({
|
||||
conditionsOp: 'and',
|
||||
conditions: [{ op: 'is', field: 'imported_payee', value: 'James' }],
|
||||
actions: [
|
||||
{
|
||||
op: 'set-split-amount',
|
||||
field: 'amount',
|
||||
options: { splitIndex: 1, method: 'remainder' },
|
||||
},
|
||||
{
|
||||
op: 'set-split-amount',
|
||||
field: 'amount',
|
||||
options: { splitIndex: 2, method: 'remainder' },
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(
|
||||
rule.exec({ imported_payee: 'James', amount: -2397 }),
|
||||
).toMatchObject({
|
||||
subtransactions: [{ amount: -1198 }, { amount: -1199 }],
|
||||
});
|
||||
|
||||
expect(rule.exec({ imported_payee: 'James', amount: 123 })).toMatchObject(
|
||||
{
|
||||
subtransactions: [{ amount: 62 }, { amount: 61 }],
|
||||
},
|
||||
);
|
||||
|
||||
expect(rule.exec({ imported_payee: 'James', amount: 100 })).toMatchObject(
|
||||
{
|
||||
subtransactions: [{ amount: 50 }, { amount: 50 }],
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test('generate errors when fixed amounts exceed the total', () => {
|
||||
expect(
|
||||
fixedAmountRule.exec({ imported_payee: 'James', amount: 100 }),
|
||||
|
||||
@@ -753,7 +753,7 @@ function execSplitActions(actions: Action[], transaction) {
|
||||
});
|
||||
|
||||
// The last remainder split will be adjusted for any leftovers from rounding.
|
||||
newTransactions[lastNonFixedTransactionIndex].amount -=
|
||||
newTransactions[lastNonFixedTransactionIndex].amount +=
|
||||
getSplitRemainder(newTransactions);
|
||||
}
|
||||
|
||||
|
||||
6
upcoming-release-notes/4190.md
Normal file
6
upcoming-release-notes/4190.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Bugfix
|
||||
authors: [jfdoming]
|
||||
---
|
||||
|
||||
Fix rounding of split rules
|
||||
Reference in New Issue
Block a user