Bug 17585: Add the Koha::Patron->get_account_lines method

Test plan:
  prove t/db_dependent/Koha/Patrons.t
should return green

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2016-11-08 13:19:39 +00:00 committed by Kyle M Hall
parent 430542ad55
commit ce92367784
2 changed files with 39 additions and 0 deletions

View File

@ -548,6 +548,18 @@ sub get_age {
return $age;
}
=head3 get_account_lines
my $fines = $patron->get_account_lines
=cut
sub get_account_lines {
my ($self) = @_;
my $account_lines = $self->_result->accountlines;
return Koha::Account::Lines->_new_from_dbic($account_lines);
}
=head3 type
=cut

View File

@ -479,9 +479,12 @@ subtest 'get_overdues' => sub {
subtest 'get_age' => sub {
plan tests => 6;
my $patron = $builder->build( { source => 'Borrower' } );
$patron = Koha::Patrons->find( $patron->{borrowernumber} );
my $today = dt_from_string;
$patron->dateofbirth( $today->clone->add( years => -12, months => -6, days => -1 ) );
is( $patron->get_age, 12, 'Patron should be 12' );
$patron->dateofbirth( $today->clone->add( years => -18, months => 0, days => 1 ) );
@ -498,6 +501,30 @@ subtest 'get_age' => sub {
$patron->delete;
};
subtest 'get_account_lines' => sub {
plan tests => 2;
my $patron = $builder->build({source => 'Borrower'});
my $accountline_1 = $builder->build({ source => 'Accountline',
value => { borrowernumber => $patron->{borrowernumber},
amount => 42,
amountoutstanding => 42 }
});
my $accountline_2 = $builder->build({ source => 'Accountline',
value => { borrowernumber => $patron->{borrowernumber},
amount => -13,
amountoutstanding => -13 }
});
$patron = Koha::Patrons->find( $patron->{borrowernumber} );
my $account_lines = $patron->get_account_lines;
is( $account_lines->count, 2, 'There should have 2 account lines for that patron' );
is( ref($account_lines), 'Koha::Account::Lines', 'get_account_lines should return a Koha::Account::Lines object' );
$patron->delete;
};
$retrieved_patron_1->delete;
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );