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

(-)a/Koha/CirculationRules.pm (+28 lines)
Lines 579-584 sub get_effective_daysmode { Link Here
579
579
580
}
580
}
581
581
582
=head3 get_effective_expire_reserves_charge
583
584
Return the value for expire_reserves_charge defined in the circulation rules.
585
If not defined (or empty string), the value of the system preference ExpireReservesMaxPickUpDelayCharge is returned
586
587
=cut
588
589
sub get_effective_expire_reserves_charge {
590
    my ( $class, $params ) = @_;
591
592
    my $itemtype     = $params->{itemtype};
593
    my $branchcode   = $params->{branchcode};
594
    my $categorycode = $params->{categorycode};
595
596
    my $expire_reserves_charge_rule = $class->get_effective_rule(
597
        {
598
            itemtype     => $itemtype,
599
            branchcode   => $branchcode,
600
            categorycode => $categorycode,
601
            rule_name    => 'expire_reserves_charge',
602
        }
603
    );
604
605
    # return the rule value (incl. 0) if rule found so there's an object in the variable,
606
    # or return default value from sysprefs when rule wasn't found and there's undef
607
    return $expire_reserves_charge_rule ? $expire_reserves_charge_rule->rule_value : C4::Context->preference("ExpireReservesMaxPickUpDelayCharge");
608
609
}
582
610
583
=head3 type
611
=head3 type
584
612
(-)a/Koha/Hold.pm (-8 / +3 lines)
Lines 553-571 sub cancel { Link Here
553
553
554
            # and, if desired, charge a cancel fee
554
            # and, if desired, charge a cancel fee
555
            if ( $params->{'charge_cancel_fee'} ) {
555
            if ( $params->{'charge_cancel_fee'} ) {
556
                my $charge;
557
                my $item = $self->item;
556
                my $item = $self->item;
558
                my $branchcode = C4::Reserves::GetReservesControlBranch($item->unblessed, $self->borrower->unblessed);
557
                my $charge = Koha::CirculationRules->get_effective_expire_reserves_charge(
559
560
                my $rule = Koha::CirculationRules->get_effective_rule(
561
                    {
558
                    {
559
                        itemtype => $item->effective_itemtype,
560
                        branchcode => C4::Reserves::GetReservesControlBranch($item->unblessed, $self->borrower->unblessed),
562
                        categorycode => $self->borrower->categorycode,
561
                        categorycode => $self->borrower->categorycode,
563
                        itemtype     => $item->effective_itemtype,
564
                        branchcode   => $branchcode,
565
                        rule_name    => 'expire_reserves_charge',
566
                    }
562
                    }
567
                );
563
                );
568
                $charge = $rule ? $rule->rule_value : C4::Context->preference("ExpireReservesMaxPickUpDelayCharge");
569
564
570
                my $account =
565
                my $account =
571
                  Koha::Account->new( { patron_id => $self->borrowernumber } );
566
                  Koha::Account->new( { patron_id => $self->borrowernumber } );
(-)a/t/db_dependent/Koha/CirculationRules.t (-2 / +93 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 4;
22
use Test::More tests => 5;
23
use Test::Exception;
23
use Test::Exception;
24
24
25
use Koha::CirculationRules;
25
use Koha::CirculationRules;
Lines 297-302 subtest 'get_effective_daysmode' => sub { Link Here
297
    $schema->storage->txn_rollback;
297
    $schema->storage->txn_rollback;
298
};
298
};
299
299
300
subtest 'get_effective_expire_reserves_charge' => sub {
301
    plan tests => 4;
302
303
    $schema->storage->txn_begin;
304
305
    Koha::CirculationRules->search({ rule_name => 'expire_reserves_charge' })->delete;
306
307
    t::lib::Mocks::mock_preference( 'ExpireReservesMaxPickUpDelayCharge', 10 );
308
309
    is(
310
        Koha::CirculationRules->get_effective_expire_reserves_charge(
311
            {
312
                itemtype     => undef,
313
                branchcode   => undef,
314
                categorycode => undef,
315
            }
316
        ),
317
        '10',
318
        'use the default pref value as the circ rule does not exist'
319
    );
320
321
    Koha::CirculationRules->set_rule(
322
        {
323
            branchcode   => '*',
324
            categorycode => '*',
325
            itemtype     => '*',
326
            rule_name    => 'expire_reserves_charge',
327
            rule_value   => '20'
328
        }
329
    );
330
331
    is(
332
        Koha::CirculationRules->get_effective_expire_reserves_charge(
333
            {
334
                categorycode => undef,
335
                itemtype     => undef,
336
                branchcode   => undef
337
            }
338
        ),
339
        '20',
340
        "use the value from the circ rules"
341
    );
342
343
    t::lib::Mocks::mock_preference( 'ExpireReservesMaxPickUpDelayCharge', 30 );
344
345
    Koha::CirculationRules->set_rule(
346
        {
347
            branchcode   => '*',
348
            categorycode => '*',
349
            itemtype     => '*',
350
            rule_name    => 'expire_reserves_charge',
351
            rule_value   => undef
352
        }
353
    );
354
355
    is(
356
        Koha::CirculationRules->get_effective_expire_reserves_charge(
357
            {
358
                categorycode => undef,
359
                itemtype     => undef,
360
                branchcode   => undef
361
            }
362
        ),
363
        '30',
364
        "use the default pref value for as the circ rule has undefined value"
365
    );
366
367
    Koha::CirculationRules->set_rule(
368
        {
369
            branchcode   => '*',
370
            categorycode => '*',
371
            itemtype     => '*',
372
            rule_name    => 'expire_reserves_charge',
373
            rule_value   => '0'
374
        }
375
    );
376
377
    is(
378
        Koha::CirculationRules->get_effective_expire_reserves_charge(
379
            {
380
                categorycode => undef,
381
                itemtype     => undef,
382
                branchcode   => undef
383
            }
384
        ),
385
        '0',
386
        "use the value from the circ rules for even though it's 0"
387
    );
388
389
    $schema->storage->txn_rollback;
390
};
391
300
subtest 'get_lostreturn_policy() tests' => sub {
392
subtest 'get_lostreturn_policy() tests' => sub {
301
    plan tests => 7;
393
    plan tests => 7;
302
394
303
- 

Return to bug 25711