Commit graph

30 commits

Author SHA1 Message Date
Juerd Waalboer
807d255b53 Expose deltas
In preparation for future plugin
2024-11-17 01:15:18 +01:00
Juerd Waalboer
daf0077d0d Introduce ';' as command/transaction separator
There's a slight mismatch between what users experience as a command,
and how commands are defined in RevBank. Specifically, the common input
"<productid> <username>" is two separate commands: the first adds the
product to the cart, the second finalizes the transaction. This also
means that "<productid> <username> <productid> <username>" was four
separate commands, resulting in TWO transactions.

That's all fine and useful, but when using this advanced input method,
where input is split on whitespace, it lead to unexpected results if
there are insufficient arguments for the follow-up questions of a
command. For example, "take jantje 10 take pietje 10" will interpret the
second "take" as the description, then "pietje" als the first command of
a new transaction, and finally, "10" which is typically not a valid
command. It is much more likely that the user intended two separate
"take" commands and just forgot to provide the description argument, but
RevBank had no way of inferring that intent.

From this commit on, whenever the user intends to enter further input
words beyond the one that finalizes a transaction ($cart->checkout), a
';' is required. If trailing input is present, the checkout is refused
and the user gets a retry prompt.

Similarly, if the user indicates the intention of having finished a
command by inserting a ';' while there are insufficient words in the
command line to satisfy all follow-up prompts (command arguments), the
rest of the command line is rejected with a retry prompt.

There is, however, still no specific requirement for a ';' separator
after a command that does not finalize a transaction (e.g. "<productid>
<username>" or even "<productid> x2 <productid> <username>" remains
valid), or for a command that precedes a ';' to finalize a transaction
(e.g. "<productid>; <username>;" is also valid).

This change catches many, but not all, mistakes.
2023-12-26 00:21:01 +01:00
Juerd Waalboer
3470ebeb1c Explicitly use Perl 5.32
Was already implicitly required (since 59387ddb) because RevBank::Amount
uses the "isa" feature, which was introduced in Perl 5.32 (but no longer
experimental since 5.36, not 5.32 as the old comment said).

Perl 5.32 was released in June 2020, and ships with Debian bullseye
("oldstable") which was released in August 2021.
2023-12-12 00:28:17 +01:00
Juerd Waalboer
dbe75efe7f Remove references to deprecated calling convention
Deprecated 4 years ago, no longer supported since 2 years ago.
2023-11-24 05:52:04 +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
b50bbfef96 Update comment 2023-09-20 21:11:19 +02:00
Juerd Waalboer
560242a4bc Bump version to 4.0.0; change transaction ID scheme 2023-09-20 20:15:43 +02:00
Juerd Waalboer
59387ddba4 Use formerly experimental Perl features with "use experimental"
This is semantically equivalent to use feature + no warnings, but less
noisy. I've also added comments to indicate when the line can be
removed.
2023-09-10 02:13:33 +02:00
Juerd Waalboer
fffb2d72e9 Fix deduplication bug, refactor deduplication to own plugin
(Bumps version to 3.8 because admins should update the plugin list.)

Deduplication didn't work on quantified additions, i.e. if you added
"20x clubmate" when there was already clubmate in the cart, it would add
just ONE item, and have a lingering message that the next thing would be
multiplied by 20.

This old bug was especially annoying if there is a barcode "20x
clubmate" to scan 20 bottles (which is the size of a crate), and this is
repeated.

The fix also uncovered another bug: newly added entries were selected
too early. There are two hooks, hook_add_entry and hook_added_entry, and
of course the selection should happen in between, not before the former.
No entry in UPGRADING.md, because I think it is extremely unlikely that
any plugin author will have used the selection feature yet, which is
very new.
2023-02-12 17:53:14 +01:00
Juerd Waalboer
99435cef17 Highlight change; apply operators to last scanned instead of last added 2023-01-30 04:40:42 +01:00
Juerd Waalboer
f479060576 Fix bug: ->changed is getter only, not a setter 2023-01-19 05:24:50 +01:00
Juerd Waalboer
6180bf6ea5 Add new hook_checkout_prepare, rollback earlier change of hook_checkout
In hindsight, it was a bad idea to allow manipulating the cart (entries)
in hook_checkout, because that hook is used by the `log` plugin. You now
get unused entries in the log.

Although that plugin should maybe have used hook_checkout_done, existing
log file readers (including scripts) and custom plugins may depend on
the CHECKOUT items in the log being before the BALANCE items.
2023-01-16 03:52:00 +01:00
Juerd Waalboer
11ca0a86b2 Allow cart manipulation during hook_checkout 2023-01-16 03:05:03 +01:00
Juerd Waalboer
922f8dc8f6 Ensure unique transaction IDs
Long overdue :)
2022-10-31 19:00:20 +01:00
Juerd Waalboer
44d17e6ae0 Remove redundant checks
Signatures already do arity-checking.
2022-10-31 16:37:19 +01:00
Juerd Waalboer
22ca2ec61e Implement global advisory lock 2022-08-29 17:50:12 +02:00
Juerd Waalboer
65566349f6 Prepare for future removal of support for unbalanced transactions
Don't worry, that won't happen for at least months. First we'll just log
warnings for a while.
2022-06-12 21:49:22 +02:00
Juerd Waalboer
064841c25e Add cash box tracking with new plugin "cash" 2022-06-11 21:16:47 +02:00
Juerd Waalboer
441bf05fde Bump to v3.4; make all transactions balanced using hidden accounts
See UPGRADING.md for details.
2022-06-11 18:51:26 +02:00
Juerd Waalboer
ccae71021a Get 'cash' working again
Now implemented via a hidden user called '-cash'.

This also introduces the concept of hidden accounts, that begin with '+' or
'-', for result accounts and balance accounts. Future versions can further
use this for more detailed bookkeeping. The idea behind the sign is that
'-' accounts should be inverted to get the intuitive value. So if the account
'-cash' has -13.37, that means there should be +13.37 in the cash box (or,
well, once the rest of this is implemented and the initial values are then set
correctly.)
2022-06-11 16:58:20 +02:00
Juerd Waalboer
eed0db7897 Cleanup: use subroutine signatures, remove deprecated methods.
The signatures feature has been "experimental" since Perl 5.20 (May 2014), but
expected to stay. After 8 years I'm ready to take the risk :)

Have added Perl v5.28 (June 2018) as the minimum requirement, even though the
current revbank should work with 5.20, to see if this bothers any users. Perl
v5.28 is in Debian "buster", which is now oldstable.
2021-12-03 18:00:34 +01:00
Juerd Waalboer
38a0229899 Ditch floating point numbers, use cents instead; bump version to 3.2 2021-12-02 22:18:06 +01:00
Juerd Waalboer
f7a7a19d8d Fix #7 2020-03-01 06:16:08 +01:00
Juerd Waalboer
f9554ec463 Move old stuff to bottom of source file 2019-11-05 01:35:22 +01:00
Juerd Waalboer
1cbc906f1e Further update to new ledger-like internals 2019-11-05 00:57:39 +01:00
Juerd Waalboer
5a7a7184dd Refactor cart to use "entries" instead of "items" 2019-11-04 21:53:07 +01:00
Juerd Waalboer
b31b95ca37 Bugfix: 'stock' counted 1 after using 'repeat'
The 'stock' plugin uses the 'product_id' field in the cart item, but
this was not copied by the 'repeat' plugin. The confusion is caused by a
mismatch between the API for RevBank::Cart->add and the internal
representation.
2018-06-09 23:47:21 +02:00
Juerd Waalboer
4ad7129805 New hook: checkout_done 2017-05-10 22:08:33 +02:00
Juerd Waalboer
add3100401 New plugin: repeat (undocumented), new hook: "added" 2017-02-19 00:41:20 +01:00
Juerd Waalboer
b0ee7e88bf cwd is no longer in @INC in new perl versions 2017-02-18 22:31:19 +01:00
Renamed from RevBank/Cart.pm (Browse further)