Commit graph

252 commits

Author SHA1 Message Date
Juerd Waalboer
f16e406063 Revert "Handle huge numbers better"
This reverts commit ef0039bc33.

Abysmal performance: revbank2beancount went from 0.7 to 11 seconds for
revspace's 2024 .revbank.log to date.
2024-08-28 06:41:02 +02:00
Juerd Waalboer
ef0039bc33 Handle huge numbers better
A sufficiently big number, i.e. longer than a long long, had interesting
effects. Perl would promote it to a float, and format it as -1 in
sprintf, which RevBank::Amount didn't handle correctly. In extreme cases
the number got rounded to Inf and would no longer round-trip.

As a result, numbers returned by RevBank::Amount are now Math::BigInt
and Math::BigFloat objects. Those should be transparent to all existing
code. It's amazing to see the unit tests pass.

I don't think there is any actual use case in RevBank for numbers this
large and I don't think anyone will have actually encountered the
aforementioned weird effects. Mostly, the input would be parsed with
parse_amount which refuses any number greater than 99900 anyway. Only
where parse_string was used directly, such large numbers could actually
have been used, but in stock RevBank that is only done when reading the
accounts file.

This change also introduces a new global function parse_any_amount that
is like parse_amount but doesn't complain about negative or large
numbers, to further improve the adduser plugin (see previous commit) in
insane edge cases. It differs from RevBank::Amount->parse_string in that
it does support addition and subtraction operators.
2024-08-28 05:19:02 +02:00
Juerd Waalboer
f6f5d66bdc adduser: improve error message for large numeric input
Old message was not as intended:

> Name for the new account: 123123123123
> That's way too much money. Enter 'abort' to abort.

Fixed:

> Name for the new account: 123123123123
Sorry, that's too numeric to be a user name. Enter 'abort' to abort.
2024-08-28 03:35:19 +02:00
Juerd Waalboer
1c9c35d535 v6.1.3: fix grandtotal for invalid balances
This somehow escaped change with the introduction of RevBank::Amount in
v3.2 in 2021, which only now became relevant due to the recent change in
v6.1.0 which turns invalid account balances into a feature.
2024-04-25 01:34:47 +02:00
Juerd Waalboer
f2d09b4da5 v6.1.1: Feature: warning messages for invalid accounts 2024-04-25 01:08:15 +02:00
Juerd Waalboer
33b08f99ea v6.1.0: improve handling of invalid balance in revbank.accounts
This small change makes it possible to reserve an account name by just
giving it an invalid balance in `revbank.accounts`.
2024-04-25 01:08:15 +02:00
Peter
f044be2215
Update deposit_iban_qr message about supported banks
ASN and N26 tested, SNS assumed (since it's mostly the same app as ASN)
2024-03-10 13:03:16 +01:00
Juerd Waalboer
b416c7be3e statiegeld: fix warning for undef $input on ^D 2024-02-11 04:14:05 +01:00
Juerd Waalboer
1105fbc3b2 v6.0.3: add warning for duplicates in revbank.products 2024-02-07 23:15:57 +01:00
Juerd Waalboer
cb463ba415 Fix #tag without value
This is weird. I'm sure I did test valueless tags. But apparently
between that and committing, the `?` quantifier in the regex got lost,
and I don't know how that happened.
2024-01-21 02:48:33 +01:00
Juerd Waalboer
55a83d9ceb v6.0.0: big revbank.products syntax change
Rationale in UPGRADING.md

It's a big change technically, but converting the format won't be hard
for admins.

There's a compatibility mode with loud warnings in case the file isn't
converted.
2024-01-20 03:50:10 +01:00
Juerd Waalboer
6aa33beedb statiegeld: fix warning 2024-01-18 18:16:26 +01:00
Juerd Waalboer
0db3e0ed81 Remove special cases for undef input
It's too buggy; in some edge cases it results in an infinite input loop
with 100% cpu. If you want to restart, use 'restart' instead of eof'ing
the input with ^D.
2024-01-05 23:44:32 +01:00
Juerd Waalboer
98af489386 Limit character set for new usernames 2023-12-26 16:22:11 +01:00
Juerd Waalboer
09411bb6c0 give: Don't do checkout with description as username
Originally, this command didn't have a description parameter. Foo would
use `give xyzzy 10 foo`. Then, a description parameter was added. For
backwards compatibility, if you would enter a username (like `foo` in
this example) in the place of the description, it would finalize the
transaction using that.

However, as the user base grows, several reasonable descriptions exist as
user account names, and that would finalize the transaction under the
wrong user.

It's time to break backward compatibility. If you don't want to leave a
message (it's still optional), that can be done with `x` (like the
`donate` command), or in advanced mode, with `""`.

Because it's likely that people are still very much used to just leaving
the description out, if you enter something that happens to match an
existing username, the input will be rejected.

The current equivalent command line would be `give xyzzy 10 ""; foo` or
`give xyzzy 10 x; foo`. If the `;` (new since v5.0.0) is left out, the
trailing `foo` has to be confirmed with a second press of the enter key.
2023-12-26 05:47:29 +01:00
Juerd Waalboer
243b34e295 take: Improve error message
First arg must be a username, so "and not a valid amount" is misleading.
2023-12-26 05:47:29 +01:00
Juerd Waalboer
f4d3b7fd5c undo: assert undoability instead of rolling back invalid undo
Making use of other recent changes, like that it's now safe to throw
exceptions during hook_checkout_prepare to abort the transaction.
2023-12-26 02:10:34 +01:00
Juerd Waalboer
6b04ecc256 undo: deal with checkout exception
The ancient decision to let undo perform the checkout by itself still
makes sense from a UX perspective, but keeps requiring specific handling
of edge cases.

In this case, the easiest way to deal with trailing input is to just
abort entirely.

Also: updated lib/RevBank/Plugins.pm to import 'isa' and get up to 5.32
level.
2023-12-26 02:08:24 +01:00
Juerd Waalboer
52749df5f3 Ignore all hook exceptions except in hook_checkout_prepare
A space had a custom plugin that died during hook_checkout, which caused
the CHECKOUT lines to be logged without the corresponding BALANCE, and
indeed no account balances were updated. While the plugin had a bug, it
should not cause a half transaction in RevBank.

After some hesitation, I went with ON ERROR RESUME NEXT because if a
hook throws an exception, that should not interfere with other plugins
(the hook can return ABORT if this it was intentional), including the
calling plugin. An error message is printed (but not logged... TODO: add
hook_plugin_fail to plugins/log) but the show must go on.

During hook_checkout_prepare, however, nothing is set in stone yet, so
this could be used for something that might die, and this instance of
call_hooks() is now the one place where a failing hook should result in
the transaction getting aborted. For this, call_hooks() now returns a
success status boolean. Maybe it would make sense in more places, but I
didn't identify any such calls yet.

RevBank::Cart->checkout used to return a success status boolean, but it
could just as well just die (indirectly, to abort the transaction) since
it can't be called a second time within the same transaction anyway
(because ->set_user must be called exactly once), so continuing with the
same transaction can't result in anything useful anyway.

In some places, error messages were slightly improved to contain a bit
more information.
2023-11-24 05:15:22 +01:00
Juerd Waalboer
d54428b092 Add support for user-accessible accounts that are excluded from grandtotal 2023-11-02 05:33:33 +01:00
Juerd Waalboer
df8c84672d tail/users: fix warning when used with old log files 2023-11-02 04:45:03 +01:00
Juerd Waalboer
0f5cdca0f9 users: add missing tab completion for 'log' command 2023-11-02 03:58:02 +01:00
Juerd Waalboer
78d9cd916f adduser: use tab completion lists to catch some more clashes 2023-11-02 03:57:46 +01:00
Juerd Waalboer
63b4144799 split: remove irrelevant tab completions
`split` was refactored out from `take`, and this was apparently left over
from the copy/paste.
2023-11-02 03:52:32 +01:00
Juerd Waalboer
8956d8a483 Move :Tab introspection from main:: to RevBank::Plugin
- Exposes the introspection as a public method.
- Removes undocumented support for NOABORT special-case.
2023-11-02 03:16:55 +01:00
Juerd Waalboer
4f0954b2dc restart: only suppress warnings of the 'exec' category
"Statement unlikely to be reached" is the expected warning here.
2023-11-02 03:12:26 +01:00
Juerd Waalboer
4664245b8b Add plugin 'sighup' 2023-11-02 03:12:17 +01:00
Juerd Waalboer
3ca6db357d New plugin: adduser_note 2023-09-20 20:12:42 +02:00
Juerd Waalboer
f6338fe9fc gtin: fix spamurl, support element string without parentheses
The spam url has uppercase letters.
2023-09-20 00:06:12 +02:00
Juerd Waalboer
827a600f8e vat: remove unused variable 2023-09-18 15:30:00 +02:00
Juerd Waalboer
5a160fcff0 vat: match accounts case insensitively, show VAT for non-hidden accounts
Also fixed unintended masking of $vat variable.
2023-09-18 15:09:03 +02:00
Juerd Waalboer
e979c695c4 Document vat plugin 2023-09-18 15:08:55 +02:00
Juerd Waalboer
ac519c05c8 VAT plugin
No hackerspace probably needs this, but I just realised that
implementing VAT support would be very easy, so why not.
2023-09-18 05:15:13 +02:00
Juerd Waalboer
e6746afde5 Add rant 2023-09-18 01:57:37 +02:00
Juerd Waalboer
8f781dae6c Add simple GS1 "Digital Link" and "Element String" support
Also has a regex for some known promotional URLs that don't adhere to
the Digital Link standard.
2023-09-18 01:37:35 +02:00
Juerd Waalboer
0dcacfc659 Upstream support for angel-foo input as alias for foo.
This replaces the revspace_angel plugin at RevSpace.
2023-09-18 01:35:11 +02:00
Juerd Waalboer
0245f80961 url: Print line but don't skip "no such product/..." error message 2023-09-18 01:33:35 +02:00
Juerd Waalboer
b3cd3833f1 products: clear products cache before reading products list
Fixes bug where a product would remain available if it is removed from
revbank.products during runtime.
2023-09-18 00:04:00 +02:00
Juerd Waalboer
0202ab38ac users: color negative balance red 2023-07-11 22:41:39 +02:00
Juerd Waalboer
acb47457c1 tail: Reformat output
Similar to the previous commit to plugins/users, with the additional
change of dynamically sizing the username column.

I believe this is the last place where GAIN/LOSE was displayed to end
users.
2023-07-11 04:00:50 +02:00
Juerd Waalboer
be204b9ad8 users: reformat user log view
Shaves 7 characters off for most lines, and gets rid of infamous
GAIN/LOSE display.

The terms "GAIN" and "LOSE" were originally introduced because having
negative numbers everywhere would look too, er, negative, and having a
"+" for positive numbers would get hard to notice in a right aligned
list. The visibility of the "+" was fixed a while ago, simply by adding
a space between the sign and the number, and now the same style is
applied to the user log view.

Old:
2023-07-05 06:24:54 LOSE   2   1.80 Example [2x 0.90]
2023-07-07 20:55:53 GAIN   1  20.00 Received from someone (example)

New:
2023-07-05 06:24:54     1.80 2x Example [2x 0.90]
2023-07-07 20:55:53  + 20.00 Received from someone (example)
2023-07-11 03:37:09 +02:00
Juerd Waalboer
338ea37127 statiegeld: fix typo in ansi escape 2023-06-10 22:26:21 +02:00
Juerd Waalboer
194ba4990c idle: use underline instead of dim/faint
Was always intended as underline. Our old IBM terminal renders 2 as
underline. Other things interpret it as dim/faint though...
2023-06-10 22:24:14 +02:00
Juerd Waalboer
a00384bb0e statiegeld: repeat color code on 2nd line of prompt
Found in interaction with `idle` plugin, which causes redraw.
2023-06-10 22:23:31 +02:00
Juerd Waalboer
701f9541cd Fix bug: statiegeld_ignore would stay true for market products 2023-05-13 01:12:11 +02:00
Juerd Waalboer
d194cb8dfa statiegeld_tokens: Fix data loss on undo
Wrote one big line because of missing \n.
2023-04-14 21:01:01 +02:00
Juerd Waalboer
c71455fb0a Broaden assertion
abundance of caution etc
2023-04-13 23:10:51 +02:00
Juerd Waalboer
615ba66655 Add message to donate command 2023-04-12 16:19:04 +02:00
Juerd Waalboer
dd5b77ce47 Update limit 19.84 -> 22.00 2023-04-11 23:53:55 +02:00
Juerd Waalboer
d33cc1fa18 Spelling 2023-04-09 22:40:35 +02:00