From 4277f43a91189e5bbe51e82061d0ea3a81167fd7 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 4 Nov 2016 15:05:08 +0000 Subject: [PATCH] Bug 17555: Add Koha::Patron->category We need to use the DBIx::Class relationship to retrieve the patron category. It is more convenient to have a Koha::Patron->category method to retrieve the category of a given patron. Test plan: Make sure that the tests in t/db_dependent/Koha/Patron* return green Signed-off-by: Josef Moravec Signed-off-by: Kyle M Hall --- Koha/Patron.pm | 23 +++++++++++++++++------ t/db_dependent/Koha/Patrons.t | 9 ++++++++- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 9a2fd18a2c..9867aebe61 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -93,6 +93,20 @@ sub delete { return $deleted; } + +=head3 category + +my $patron_category = $patron->category + +Return the patron category for this patron + +=cut + +sub category { + my ( $self ) = @_; + return Koha::Patron::Category->_new_from_dbic( $self->_result->categorycode ); +} + =head3 guarantor Returns a Koha::Patron object for this patron's guarantor @@ -200,8 +214,7 @@ sub wants_check_for_previous_checkout { return 0 if ($self->checkprevcheckout eq 'no'); # More complex: patron inherits -> determine category preference - my $checkPrevCheckoutByCat = Koha::Patron::Categories - ->find($self->categorycode)->checkprevcheckout; + my $checkPrevCheckoutByCat = $self->category->checkprevcheckout; return 1 if ($checkPrevCheckoutByCat eq 'yes'); return 0 if ($checkPrevCheckoutByCat eq 'no'); @@ -304,8 +317,7 @@ sub renew_account { ? dt_from_string( $self->dateexpiry ) : dt_from_string; } - my $patron_category = Koha::Patron::Categories->find( $self->categorycode ); # FIXME Should be $self->category - my $expiry_date = $patron_category->get_expiry_date($date); + my $expiry_date = $self->category->get_expiry_date($date); $self->dateexpiry($expiry_date)->store; @@ -440,8 +452,7 @@ Add enrolment fee for a patron if needed. sub add_enrolment_fee_if_needed { my ($self) = @_; - my $patron_category = Koha::Patron::Categories->find( $self->categorycode ); - my $enrolment_fee = $patron_category->enrolmentfee; + my $enrolment_fee = $self->category->enrolmentfee; if ( $enrolment_fee && $enrolment_fee > 0 ) { # insert fee in patron debts C4::Accounts::manualinvoice( $self->borrowernumber, '', '', 'A', $enrolment_fee ); diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index 6b85dccb99..1775bb5ae4 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 11; +use Test::More tests => 12; use Test::Warn; use C4::Members; @@ -89,6 +89,13 @@ subtest 'guarantees' => sub { $_->delete for @guarantees; }; +subtest 'category' => sub { + plan tests => 2; + my $patron_category = $new_patron_1->category; + is( ref( $patron_category), 'Koha::Patron::Category', ); + is( $patron_category->categorycode, $category->{categorycode}, ); +}; + subtest 'siblings' => sub { plan tests => 7; my $siblings = $new_patron_1->siblings; -- 2.39.5