View | Details | Raw Unified | Return to bug 16223
Collapse All | Expand All

(-)a/Koha/Patron/Debarments.pm (-12 / +12 lines)
Lines 287-309 sub del_restrictions_after_payment { Link Here
287
    my ($params) = @_;
287
    my ($params) = @_;
288
288
289
    my $borrowernumber = $params->{'borrowernumber'};
289
    my $borrowernumber = $params->{'borrowernumber'};
290
    return unless ( $borrowernumber );
290
    return unless ($borrowernumber);
291
291
292
    my $patron_restrictions = GetDebarments( { borrowernumber => $borrowernumber } );
292
    my $patron = Koha::Patrons->find($borrowernumber);
293
    return unless ( $patron_restrictions );
293
    return unless ($patron);
294
294
295
    my $patron = Koha::Patrons->find( $borrowernumber );
295
    my $restrictions = $patron->restrictions;
296
    return unless ( $patron );
296
    return unless ( $restrictions->count );
297
297
298
    my $lines = Koha::Account::Lines->search({ borrowernumber  => $borrowernumber });
298
    my $lines =
299
      Koha::Account::Lines->search( { borrowernumber => $borrowernumber } );
299
    my $total_due = $lines->total_outstanding;
300
    my $total_due = $lines->total_outstanding;
300
301
301
    foreach my $patron_restriction (@{ $patron_restrictions }){
302
    while ( my $restriction = $restrictions->next ) {
302
        my $restriction = Koha::Patron::Restriction::Types->find({
303
        if (   $restriction->type->lift_after_payment
303
            code => $patron_restriction->{type}
304
            && $total_due <= $restriction->type->fee_limit )
304
        });
305
        {
305
        if($restriction->lift_after_payment && $total_due <= $restriction->fee_limit){
306
            DelDebarment( $restriction->borrower_debarment_id );
306
            DelDebarment($patron_restriction->{'borrower_debarment_id'});
307
        }
307
        }
308
    }
308
    }
309
}
309
}
(-)a/t/db_dependent/Patron/Borrower_Debarments.t (-14 / +12 lines)
Lines 252-272 $builder->build( Link Here
252
    }
252
    }
253
);
253
);
254
254
255
my $borrowernumber4 = Koha::Patron->new(
255
my $patron4 = Koha::Patron->new(
256
    {
256
    {
257
        firstname    => 'First',
257
        firstname    => 'First',
258
        surname      => 'Sur',
258
        surname      => 'Sur',
259
        categorycode => $patron_category->{categorycode},
259
        categorycode => $patron_category->{categorycode},
260
        branchcode   => $library->{branchcode},
260
        branchcode   => $library->{branchcode},
261
    }
261
    }
262
)->store->borrowernumber;
262
)->store;
263
263
264
my $account = Koha::Account->new({ patron_id => $borrowernumber4 });
264
my $account = $patron4->account;
265
my $line1 = $account->add_debit({ type => 'ACCOUNT', amount => 10, interface => 'commandline' });
265
my $line1 = $account->add_debit({ type => 'ACCOUNT', amount => 10, interface => 'commandline' });
266
266
267
Koha::Patron::Debarments::AddDebarment(
267
Koha::Patron::Debarments::AddDebarment(
268
    {
268
    {
269
        borrowernumber => $borrowernumber4,
269
        borrowernumber => $patron4->borrowernumber,
270
        expiration     => '9999-06-10',
270
        expiration     => '9999-06-10',
271
        type           => 'TEST',
271
        type           => 'TEST',
272
        comment        => 'Test delete'
272
        comment        => 'Test delete'
Lines 275-297 Koha::Patron::Debarments::AddDebarment( Link Here
275
275
276
Koha::Patron::Debarments::AddDebarment(
276
Koha::Patron::Debarments::AddDebarment(
277
    {
277
    {
278
        borrowernumber => $borrowernumber4,
278
        borrowernumber => $patron4->borrowernumber,
279
        expiration     => '9999-10-10',
279
        expiration     => '9999-10-10',
280
        type           => 'TEST2',
280
        type           => 'TEST2',
281
        comment        => 'Test delete again',
281
        comment        => 'Test delete again',
282
    }
282
    }
283
);
283
);
284
284
285
$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $borrowernumber4 });
285
$restrictions = $patron4->restrictions;
286
286
287
is( @$debarments, 2, "GetDebarments returns 2 debarments before payment" );
287
is( $restrictions->count, 2, "->restrictions returns 2 restrictions before payment" );
288
288
289
$account->pay({amount => 5});
289
$account->pay({amount => 5});
290
290
$restrictions = $patron4->restrictions;
291
$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $borrowernumber4 });
291
is( $restrictions->count, 1, "->restrictions returns 1 restriction after paying half of the fee" );
292
is( @$debarments, 1, "GetDebarments returns 1 debarment after paying half of the fee" );
292
is( $restrictions->next->type->code, "TEST2", "Restriction left has type value 'TEST2'" );
293
is( @$debarments[0]->{type}, "TEST2", "Debarment left has type value 'TEST2'" );
294
293
295
$account->pay({amount => 5});
294
$account->pay({amount => 5});
296
$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $borrowernumber4 });
295
$restrictions = $patron4->restrictions;
297
is( @$debarments, 0, "GetDebarments returns 0 debarments after paying all fees" );
296
is( $restrictions->count, 0, "->restrictions returns 0 restrictions after paying all fees" );
298
- 

Return to bug 16223