Bump to v3.4; make all transactions balanced using hidden accounts
See UPGRADING.md for details.
This commit is contained in:
parent
e3a04a0e36
commit
441bf05fde
14 changed files with 116 additions and 40 deletions
|
@ -66,11 +66,7 @@ sub checkout($self, $user) {
|
|||
return;
|
||||
}
|
||||
|
||||
if ($user =~ /^[-+]/) {
|
||||
# Hidden internal accounts
|
||||
my $canonical = RevBank::Users::parse_user($user);
|
||||
$user = $canonical // RevBank::Users::create($user);
|
||||
}
|
||||
$user = RevBank::Users::assert_user($user);
|
||||
|
||||
my $entries = $self->{entries};
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ sub new($class, $amount, $description, $attributes = {}) {
|
|||
|
||||
sub add_contra($self, $user, $amount, $description) {
|
||||
$amount = RevBank::Amount->parse_string($amount) if not ref $amount;
|
||||
$user = RevBank::Users::assert_user($user);
|
||||
|
||||
$description =~ s/\$you/$self->{user}/g if defined $self->{user};
|
||||
|
||||
|
@ -84,7 +85,7 @@ sub as_printable($self) {
|
|||
push @s, sprintf "%8s %s", $self->{amount}->string_flipped, $self->{description};
|
||||
|
||||
for my $c ($self->contras) {
|
||||
next if RevBank::Users::is_hidden($c->{user});
|
||||
next if RevBank::Users::is_hidden($c->{user}) and not $ENV{REVBANK_DEBUG};
|
||||
|
||||
push @s, sprintf(
|
||||
"%11s %s %s",
|
||||
|
|
|
@ -55,7 +55,7 @@ sub hook_reject($class, $plugin, $reason, $abort, @) {
|
|||
}
|
||||
|
||||
sub hook_user_balance($class, $username, $old, $delta, $new, @) {
|
||||
return if hidden $username;
|
||||
return if hidden $username and not $ENV{REVBANK_DEBUG};
|
||||
|
||||
my $sign = $delta->cents >= 0 ? '+' : '-';
|
||||
my $rood = $new->cents < 0 ? '31;' : '';
|
||||
|
@ -67,7 +67,7 @@ sub hook_user_balance($class, $username, $old, $delta, $new, @) {
|
|||
}
|
||||
|
||||
sub hook_user_created($class, $username, @) {
|
||||
return if hidden $username;
|
||||
return if hidden $username and not $ENV{REVBANK_DEBUG};
|
||||
|
||||
say "New account '$username' created.";
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ no warnings qw(experimental::signatures);
|
|||
|
||||
use RevBank::Global;
|
||||
use RevBank::Plugins;
|
||||
use Carp ();
|
||||
|
||||
my $filename = "revbank.accounts";
|
||||
|
||||
|
@ -77,16 +78,30 @@ sub update($username, $delta, $transaction_id) {
|
|||
);
|
||||
}
|
||||
|
||||
sub parse_user($username) {
|
||||
my $users = _read();
|
||||
return undef if not exists $users->{ lc $username };
|
||||
return $users->{ lc $username }->[0];
|
||||
}
|
||||
|
||||
sub is_hidden($username) {
|
||||
return $username =~ /^[-+]/;
|
||||
}
|
||||
|
||||
sub parse_user($username) {
|
||||
return undef if is_hidden($username);
|
||||
|
||||
my $users = _read();
|
||||
return exists $users->{ lc $username }
|
||||
? $users->{ lc $username }->[0]
|
||||
: undef;
|
||||
}
|
||||
|
||||
sub assert_user($username) {
|
||||
my $users = _read();
|
||||
|
||||
return exists $users->{ lc $username }
|
||||
? $users->{ lc $username }->[0]
|
||||
: (is_hidden($username)
|
||||
? create($username)
|
||||
: Carp::croak("Account '$username' does not exist")
|
||||
);
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue