machine icon indicating copy to clipboard operation
machine copied to clipboard

Portions 0% to 100% exclusive

Open bcspragu opened this issue 3 years ago • 6 comments

Hello there!

I've been using ledger for a personal project, which involves using variable portions to split money between accounts. Sometimes, all the money will be sent to one account (depending on the transaction initiated by the user), and so the calculated portion will end up as 0/100 or 100/100, which throws a 400 Bad Request because of [1].

This causes a bunch of pain, because it means I need to dynamically change the numscript code itself (or use different numscript files) to represent transactions with 1 recipient versus N recipients. As far as I can tell, the system should handle 0% and 100% portions fine, it already has to handle similar cases when remaining is zero.

What's the motivation for not allowing 0% or 100% to be valid portions? If there's no particular concern with it, I'd be happy to update the code and add plenty of tests to ensure the behavior is correct.

[1] https://github.com/formancehq/machine/blob/a89d5180092111f4a658238a64394576007742b6/core/portion.go#L26

bcspragu avatar Feb 09 '23 18:02 bcspragu

Somewhat related: when the send amount is zero, the ledger correctly just ignores the ~transaction~ posting, I'd expect a similar behavior for 0% portions in portioned sources and destinations

bcspragu avatar Feb 09 '23 18:02 bcspragu

Hey @bcspragu! Thanks for opening this one and the detailed case; I'll confirm this in a bit but it looks like a leftover from a pre-remaining era that we should indeed be able to change in this direction

altitude avatar Feb 09 '23 18:02 altitude

PS: confirming there's no strong blockers on this one @bcspragu! Adding it to our todo list for the coming weeks, but don't have a strong deadline yet - if you want to try your hand at the implementation we can fast-track the review and be there for help!

altitude avatar Feb 10 '23 16:02 altitude

Is blocking things on my end, but I wouldn't expect y'all to handle that :smile: I'll give it a go and see what I come up with

bcspragu avatar Feb 10 '23 17:02 bcspragu

Okay, gave it a go, was pretty straightforward to add.

The PR to add support in the Numscript machine: https://github.com/formancehq/machine/pull/59 The PR to add a test to the ledger for the new behavior: https://github.com/formancehq/ledger/pull/433

bcspragu avatar Feb 10 '23 18:02 bcspragu

Whew that was fast 🔥 @antoinegelloz @Azorlogh wanna take this one?

altitude avatar Feb 10 '23 18:02 altitude