From c659fe807671912e7e5636110e586ea23df65b69 Mon Sep 17 00:00:00 2001 From: Josef Moravec Date: Tue, 26 Jun 2018 00:22:16 +0000 Subject: [PATCH] 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 Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart Signed-off-by: Nick Clemens --- Koha/Account/Line.pm | 14 +++++++++++++- t/db_dependent/Koha/Account/Lines.t | 8 +++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Koha/Account/Line.pm b/Koha/Account/Line.pm index f339b37f13..1962c7de1c 100644 --- a/Koha/Account/Line.pm +++ b/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 diff --git a/t/db_dependent/Koha/Account/Lines.t b/t/db_dependent/Koha/Account/Lines.t index da09ef552c..4a666e5833 100755 --- a/t/db_dependent/Koha/Account/Lines.t +++ b/t/db_dependent/Koha/Account/Lines.t @@ -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; }; -- 2.39.5