Bug 20997: (follow-up) Add Koha::Account::Line->is_debit method

Test plan:
1) Apply this patch
2) prove t/db_dependent/Koha/Account/Lines.t
=> Test should pass

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
Josef Moravec 2018-06-26 00:22:16 +00:00 committed by Nick Clemens
parent 6f65887399
commit c659fe8076
2 changed files with 18 additions and 4 deletions

View File

@ -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

View File

@ -132,9 +132,9 @@ subtest 'total_outstanding() 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;
@ -144,6 +144,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(
{
@ -152,7 +153,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;
};