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

(-)a/Koha/CirculationRules.pm (+28 lines)
Lines 605-610 sub get_effective_daysmode { Link Here
605
605
606
}
606
}
607
607
608
=head3 get_effective_expire_reserves_charge
609
610
Return the value for expire_reserves_charge defined in the circulation rules.
611
If not defined (or empty string), the value of the system preference ExpireReservesMaxPickUpDelayCharge is returned
612
613
=cut
614
615
sub get_effective_expire_reserves_charge {
616
    my ( $class, $params ) = @_;
617
618
    my $itemtype     = $params->{itemtype};
619
    my $branchcode   = $params->{branchcode};
620
    my $categorycode = $params->{categorycode};
621
622
    my $expire_reserves_charge_rule = $class->get_effective_rule(
623
        {
624
            itemtype     => $itemtype,
625
            branchcode   => $branchcode,
626
            categorycode => $categorycode,
627
            rule_name    => 'expire_reserves_charge',
628
        }
629
    );
630
631
    # return the rule value (incl. 0) if rule found so there's an object in the variable,
632
    # or return default value from sysprefs when rule wasn't found and there's undef
633
    return $expire_reserves_charge_rule ? $expire_reserves_charge_rule->rule_value : C4::Context->preference("ExpireReservesMaxPickUpDelayCharge");
634
635
}
608
636
609
=head3 type
637
=head3 type
610
638
(-)a/Koha/Hold.pm (-8 / +3 lines)
Lines 605-623 sub cancel { Link Here
605
605
606
            # and, if desired, charge a cancel fee
606
            # and, if desired, charge a cancel fee
607
            if ( $params->{'charge_cancel_fee'} ) {
607
            if ( $params->{'charge_cancel_fee'} ) {
608
                my $charge;
609
                my $item = $self->item;
608
                my $item = $self->item;
610
                my $branchcode = C4::Reserves::GetReservesControlBranch($item->unblessed, $self->borrower->unblessed);
609
                my $charge = Koha::CirculationRules->get_effective_expire_reserves_charge(
611
612
                my $rule = Koha::CirculationRules->get_effective_rule(
613
                    {
610
                    {
611
                        itemtype => $item->effective_itemtype,
612
                        branchcode => C4::Reserves::GetReservesControlBranch($item->unblessed, $self->borrower->unblessed),
614
                        categorycode => $self->borrower->categorycode,
613
                        categorycode => $self->borrower->categorycode,
615
                        itemtype     => $item->effective_itemtype,
616
                        branchcode   => $branchcode,
617
                        rule_name    => 'expire_reserves_charge',
618
                    }
614
                    }
619
                );
615
                );
620
                $charge = $rule ? $rule->rule_value : C4::Context->preference("ExpireReservesMaxPickUpDelayCharge");
621
616
622
                my $account =
617
                my $account =
623
                  Koha::Account->new( { patron_id => $self->borrowernumber } );
618
                  Koha::Account->new( { patron_id => $self->borrowernumber } );
(-)a/t/db_dependent/Koha/CirculationRules.t (-2 / +93 lines)
Lines 20-26 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Benchmark;
22
use Benchmark;
23
use Test::More tests => 7;
23
use Test::More tests => 8;
24
use Test::Deep qw( cmp_methods );
24
use Test::Deep qw( cmp_methods );
25
use Test::Exception;
25
use Test::Exception;
26
26
Lines 656-661 subtest 'get_effective_daysmode' => sub { Link Here
656
    $schema->storage->txn_rollback;
656
    $schema->storage->txn_rollback;
657
};
657
};
658
658
659
subtest 'get_effective_expire_reserves_charge' => sub {
660
    plan tests => 4;
661
662
    $schema->storage->txn_begin;
663
664
    Koha::CirculationRules->search({ rule_name => 'expire_reserves_charge' })->delete;
665
666
    t::lib::Mocks::mock_preference( 'ExpireReservesMaxPickUpDelayCharge', 10 );
667
668
    is(
669
        Koha::CirculationRules->get_effective_expire_reserves_charge(
670
            {
671
                itemtype     => undef,
672
                branchcode   => undef,
673
                categorycode => undef,
674
            }
675
        ),
676
        '10',
677
        'use the default pref value as the circ rule does not exist'
678
    );
679
680
    Koha::CirculationRules->set_rule(
681
        {
682
            branchcode   => '*',
683
            categorycode => '*',
684
            itemtype     => '*',
685
            rule_name    => 'expire_reserves_charge',
686
            rule_value   => '20'
687
        }
688
    );
689
690
    is(
691
        Koha::CirculationRules->get_effective_expire_reserves_charge(
692
            {
693
                categorycode => undef,
694
                itemtype     => undef,
695
                branchcode   => undef
696
            }
697
        ),
698
        '20',
699
        "use the value from the circ rules"
700
    );
701
702
    t::lib::Mocks::mock_preference( 'ExpireReservesMaxPickUpDelayCharge', 30 );
703
704
    Koha::CirculationRules->set_rule(
705
        {
706
            branchcode   => '*',
707
            categorycode => '*',
708
            itemtype     => '*',
709
            rule_name    => 'expire_reserves_charge',
710
            rule_value   => undef
711
        }
712
    );
713
714
    is(
715
        Koha::CirculationRules->get_effective_expire_reserves_charge(
716
            {
717
                categorycode => undef,
718
                itemtype     => undef,
719
                branchcode   => undef
720
            }
721
        ),
722
        '30',
723
        "use the default pref value for as the circ rule has undefined value"
724
    );
725
726
    Koha::CirculationRules->set_rule(
727
        {
728
            branchcode   => '*',
729
            categorycode => '*',
730
            itemtype     => '*',
731
            rule_name    => 'expire_reserves_charge',
732
            rule_value   => '0'
733
        }
734
    );
735
736
    is(
737
        Koha::CirculationRules->get_effective_expire_reserves_charge(
738
            {
739
                categorycode => undef,
740
                itemtype     => undef,
741
                branchcode   => undef
742
            }
743
        ),
744
        '0',
745
        "use the value from the circ rules for even though it's 0"
746
    );
747
748
    $schema->storage->txn_rollback;
749
};
750
659
subtest 'get_lostreturn_policy() tests' => sub {
751
subtest 'get_lostreturn_policy() tests' => sub {
660
    plan tests => 7;
752
    plan tests => 7;
661
753
662
- 

Return to bug 25711