@@ -, +, @@ method --- Koha/Account/Line.pm | 14 +++++++++++++- t/db_dependent/Koha/Account/Lines.t | 8 +++++--- 2 files changed, 18 insertions(+), 4 deletions(-) --- a/Koha/Account/Line.pm +++ a/Koha/Account/Line.pm @@ -144,7 +144,7 @@ sub apply { ); } - unless ( !$debit->is_credit ) { + unless ( $debit->is_debit ) { Koha::Exceptions::Account::IsNotDebit->throw( error => 'Account line ' . $debit->id . 'is not a debit' ); @@ -202,6 +202,18 @@ sub is_credit { return ( $self->amount < 0 ); } +=head3 is_debit + + my $bool = $line->is_debit; + +=cut + +sub is_debit { + my ($self) = @_; + + return !$self->is_credit; +} + =head2 Internal methods =cut --- a/t/db_dependent/Koha/Account/Lines.t +++ a/t/db_dependent/Koha/Account/Lines.t @@ -65,9 +65,9 @@ subtest 'item() tests' => sub { $schema->storage->txn_rollback; }; -subtest 'is_credit() tests' => sub { +subtest 'is_credit() and is_debit() tests' => sub { - plan tests => 2; + plan tests => 4; $schema->storage->txn_begin; @@ -77,6 +77,7 @@ subtest 'is_credit() tests' => sub { my $credit = $account->add_credit({ amount => 100, user_id => $patron->id }); ok( $credit->is_credit, 'is_credit detects credits' ); + ok( !$credit->is_debit, 'is_debit detects credits' ); my $debit = Koha::Account::Line->new( { @@ -85,7 +86,8 @@ subtest 'is_credit() tests' => sub { amount => 10, })->store; - ok( !$debit->is_credit, 'is_credit() detects debits' ); + ok( !$debit->is_credit, 'is_credit detects debits' ); + ok( $debit->is_debit, 'is_debit detects debits'); $schema->storage->txn_rollback; }; --