From cba9824e6d53fc77e75a041ab8e529e3717e4ba6 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 11 Nov 2022 09:49:50 +0000 Subject: [PATCH] Bug 16223: (QA follow-up) Remove GetDebarments We remove the GetDebarments routine in 31095. Signed-off-by: Martin Renvoize Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi --- Koha/Patron/Debarments.pm | 24 ++++++++++---------- t/db_dependent/Patron/Borrower_Debarments.t | 25 ++++++++++----------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/Koha/Patron/Debarments.pm b/Koha/Patron/Debarments.pm index ca6e27c2ee..f8c5ca0cf7 100644 --- a/Koha/Patron/Debarments.pm +++ b/Koha/Patron/Debarments.pm @@ -287,23 +287,23 @@ sub del_restrictions_after_payment { my ($params) = @_; my $borrowernumber = $params->{'borrowernumber'}; - return unless ( $borrowernumber ); + return unless ($borrowernumber); - my $patron_restrictions = GetDebarments( { borrowernumber => $borrowernumber } ); - return unless ( $patron_restrictions ); + my $patron = Koha::Patrons->find($borrowernumber); + return unless ($patron); - my $patron = Koha::Patrons->find( $borrowernumber ); - return unless ( $patron ); + my $restrictions = $patron->restrictions; + return unless ( $restrictions->count ); - my $lines = Koha::Account::Lines->search({ borrowernumber => $borrowernumber }); + my $lines = + Koha::Account::Lines->search( { borrowernumber => $borrowernumber } ); my $total_due = $lines->total_outstanding; - foreach my $patron_restriction (@{ $patron_restrictions }){ - my $restriction = Koha::Patron::Restriction::Types->find({ - code => $patron_restriction->{type} - }); - if($restriction->lift_after_payment && $total_due <= $restriction->fee_limit){ - DelDebarment($patron_restriction->{'borrower_debarment_id'}); + while ( my $restriction = $restrictions->next ) { + if ( $restriction->type->lift_after_payment + && $total_due <= $restriction->type->fee_limit ) + { + DelDebarment( $restriction->borrower_debarment_id ); } } } diff --git a/t/db_dependent/Patron/Borrower_Debarments.t b/t/db_dependent/Patron/Borrower_Debarments.t index 86fe952f2b..e97ef48a5e 100755 --- a/t/db_dependent/Patron/Borrower_Debarments.t +++ b/t/db_dependent/Patron/Borrower_Debarments.t @@ -252,21 +252,21 @@ $builder->build( } ); -my $borrowernumber4 = Koha::Patron->new( +my $patron4 = Koha::Patron->new( { firstname => 'First', surname => 'Sur', categorycode => $patron_category->{categorycode}, branchcode => $library->{branchcode}, } -)->store->borrowernumber; +)->store; -my $account = Koha::Account->new({ patron_id => $borrowernumber4 }); +my $account = $patron4->account; my $line1 = $account->add_debit({ type => 'ACCOUNT', amount => 10, interface => 'commandline' }); Koha::Patron::Debarments::AddDebarment( { - borrowernumber => $borrowernumber4, + borrowernumber => $patron4->borrowernumber, expiration => '9999-06-10', type => 'TEST', comment => 'Test delete' @@ -275,23 +275,22 @@ Koha::Patron::Debarments::AddDebarment( Koha::Patron::Debarments::AddDebarment( { - borrowernumber => $borrowernumber4, + borrowernumber => $patron4->borrowernumber, expiration => '9999-10-10', type => 'TEST2', comment => 'Test delete again', } ); -$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $borrowernumber4 }); +$restrictions = $patron4->restrictions; -is( @$debarments, 2, "GetDebarments returns 2 debarments before payment" ); +is( $restrictions->count, 2, "->restrictions returns 2 restrictions before payment" ); $account->pay({amount => 5}); - -$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $borrowernumber4 }); -is( @$debarments, 1, "GetDebarments returns 1 debarment after paying half of the fee" ); -is( @$debarments[0]->{type}, "TEST2", "Debarment left has type value 'TEST2'" ); +$restrictions = $patron4->restrictions; +is( $restrictions->count, 1, "->restrictions returns 1 restriction after paying half of the fee" ); +is( $restrictions->next->type->code, "TEST2", "Restriction left has type value 'TEST2'" ); $account->pay({amount => 5}); -$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $borrowernumber4 }); -is( @$debarments, 0, "GetDebarments returns 0 debarments after paying all fees" ); +$restrictions = $patron4->restrictions; +is( $restrictions->count, 0, "->restrictions returns 0 restrictions after paying all fees" ); -- 2.39.5