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

(-)a/C4/SIP/ILS/Patron.pm (-8 / +10 lines)
Lines 77-93 sub new { Link Here
77
    $dexpiry and $dexpiry =~ s/-//g;    # YYYYMMDD
77
    $dexpiry and $dexpiry =~ s/-//g;    # YYYYMMDD
78
78
79
    # Get fines and add fines for guarantees (depends on preference NoIssuesChargeGuarantees)
79
    # Get fines and add fines for guarantees (depends on preference NoIssuesChargeGuarantees)
80
    my $fines_amount = $flags->{CHARGES}->{amount}; #TODO Replace with $patron->account->non_issues_charges
80
    my $fines_amount = ($patron->account->balance > 0) ? $patron->account->non_issues_charges : 0;
81
    $fines_amount = ($fines_amount and $fines_amount > 0) ? $fines_amount : 0;
81
    my $fee_limit = _fee_limit();
82
    if ( C4::Context->preference('NoIssuesChargeGuarantorsWithGuarantees') ) {
82
    my $fine_blocked = $fines_amount > $fee_limit;
83
    my $noissueschargeguarantorswithguarantees = C4::Context->preference('NoIssuesChargeGuarantorsWithGuarantees');
84
    my $noissueschargeguarantees = C4::Context->preference('NoIssuesChargeGuarantees');
85
    if ( $noissueschargeguarantorswithguarantees ) {
83
        $fines_amount += $patron->relationships_debt({ include_guarantors => 1, only_this_guarantor => 0, include_this_patron => 0 });
86
        $fines_amount += $patron->relationships_debt({ include_guarantors => 1, only_this_guarantor => 0, include_this_patron => 0 });
84
    } else {
87
        $fine_blocked ||= $fines_amount > $noissueschargeguarantorswithguarantees;
85
        my $guarantees_fines_amount = $flags->{CHARGES_GUARANTEES} ? $flags->{CHARGES_GUARANTEES}->{amount} : 0; #TODO: Replace with $patron->relationships_debt
88
    } elsif ( $noissueschargeguarantees ) {
86
        $fines_amount += $guarantees_fines_amount;
89
        $fines_amount += $patron->relationships_debt({ include_guarantors => 0, only_this_guarantor => 0, include_this_patron => 0 });
90
        $fine_blocked ||= $fines_amount > $noissueschargeguarantees;
87
    }
91
    }
88
92
89
    my $fee_limit = _fee_limit();
90
    my $fine_blocked = $fines_amount > $fee_limit;
91
    my $circ_blocked =( C4::Context->preference('OverduesBlockCirc') ne "noblock" &&  defined $flags->{ODUES}->{itemlist} ) ? 1 : 0;
93
    my $circ_blocked =( C4::Context->preference('OverduesBlockCirc') ne "noblock" &&  defined $flags->{ODUES}->{itemlist} ) ? 1 : 0;
92
    {
94
    {
93
    no warnings;    # any of these $kp->{fields} being concat'd could be undef
95
    no warnings;    # any of these $kp->{fields} being concat'd could be undef
(-)a/t/db_dependent/SIP/Patron.t (-3 / +55 lines)
Lines 4-10 Link Here
4
# This needs to be extended! Your help is appreciated..
4
# This needs to be extended! Your help is appreciated..
5
5
6
use Modern::Perl;
6
use Modern::Perl;
7
use Test::More tests => 9;
7
use Test::More tests => 10;
8
8
9
use t::lib::Mocks;
9
use t::lib::Mocks;
10
use t::lib::TestBuilder;
10
use t::lib::TestBuilder;
Lines 274-282 subtest "fine_items tests" => sub { Link Here
274
274
275
$schema->storage->txn_rollback;
275
$schema->storage->txn_rollback;
276
276
277
subtest "NoIssuesChargeGuarantees tests" => sub {
278
279
    plan tests => 4;
280
281
    t::lib::Mocks::mock_preference( 'borrowerRelationship', 'parent' );
282
283
    $schema->storage->txn_begin;
284
285
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
286
    my $child  = $builder->build_object({ class => 'Koha::Patrons' });
287
    $child->add_guarantor({ guarantor_id => $patron->borrowernumber, relationship => 'parent' });
288
289
    t::lib::Mocks::mock_preference('NoIssuesChargeGuarantees', 1);
290
291
    my $fee1 = $builder->build_object(
292
        {
293
            class => 'Koha::Account::Lines',
294
            value  => {
295
                borrowernumber => $patron->borrowernumber,
296
                amountoutstanding => 11,
297
            }
298
        }
299
    )->store;
300
301
    my $fee2 = $builder->build_object(
302
        {
303
            class => 'Koha::Account::Lines',
304
            value  => {
305
                borrowernumber => $child->borrowernumber,
306
                amountoutstanding => 0.11,
307
            }
308
        }
309
    )->store;
310
311
    my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
312
313
    is( $sip_patron->fines_amount, 11.11,"Guarantor fines correctly included");
314
    ok( !$sip_patron->charge_ok, "Guarantor blocked");
315
316
    $sip_patron = C4::SIP::ILS::Patron->new( $child->cardnumber );
317
318
    is( $sip_patron->fines_amount, 0.11,"Guarantee only fines correctly counted");
319
    ok( $sip_patron->charge_ok, "Guarantee not blocked by guarantor fines");
320
321
    $schema->storage->txn_rollback;
322
};
323
277
subtest "NoIssuesChargeGuarantorsWithGuarantees tests" => sub {
324
subtest "NoIssuesChargeGuarantorsWithGuarantees tests" => sub {
278
325
279
    plan tests => 1;
326
    plan tests => 4;
280
327
281
    t::lib::Mocks::mock_preference( 'borrowerRelationship', 'parent' );
328
    t::lib::Mocks::mock_preference( 'borrowerRelationship', 'parent' );
282
329
Lines 311-316 subtest "NoIssuesChargeGuarantorsWithGuarantees tests" => sub { Link Here
311
    my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
358
    my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
312
359
313
    is( $sip_patron->fines_amount, 11.11,"Guarantee fines correctly included");
360
    is( $sip_patron->fines_amount, 11.11,"Guarantee fines correctly included");
361
    ok( !$sip_patron->charge_ok, "Guarantor blocked");
362
363
    $sip_patron = C4::SIP::ILS::Patron->new( $child->cardnumber );
364
365
    is( $sip_patron->fines_amount, 11.11,"Guarantor fines correctly included");
366
    ok( !$sip_patron->charge_ok, "Guarantee blocked");
314
367
315
    $schema->storage->txn_rollback;
368
    $schema->storage->txn_rollback;
316
};
369
};
317
- 

Return to bug 29755