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

(-)a/Koha/CirculationRules.pm (+28 lines)
Lines 747-752 sub get_effective_daysmode { Link Here
747
747
748
}
748
}
749
749
750
=head3 get_effective_expire_reserves_charge
751
752
Return the value for expire_reserves_charge defined in the circulation rules.
753
If not defined (or empty string), the value of the system preference ExpireReservesMaxPickUpDelayCharge is returned
754
755
=cut
756
757
sub get_effective_expire_reserves_charge {
758
    my ( $class, $params ) = @_;
759
760
    my $itemtype     = $params->{itemtype};
761
    my $branchcode   = $params->{branchcode};
762
    my $categorycode = $params->{categorycode};
763
764
    my $expire_reserves_charge_rule = $class->get_effective_rule(
765
        {
766
            itemtype     => $itemtype,
767
            branchcode   => $branchcode,
768
            categorycode => $categorycode,
769
            rule_name    => 'expire_reserves_charge',
770
        }
771
    );
772
773
    # return the rule value (incl. 0) if rule found so there's an object in the variable,
774
    # or return default value from sysprefs when rule wasn't found and there's undef
775
    return $expire_reserves_charge_rule ? $expire_reserves_charge_rule->rule_value : C4::Context->preference("ExpireReservesMaxPickUpDelayCharge");
776
777
}
750
778
751
=head3 type
779
=head3 type
752
780
(-)a/Koha/Hold.pm (-8 / +3 lines)
Lines 740-758 sub cancel { Link Here
740
740
741
            # and, if desired, charge a cancel fee
741
            # and, if desired, charge a cancel fee
742
            if ( $params->{'charge_cancel_fee'} ) {
742
            if ( $params->{'charge_cancel_fee'} ) {
743
                my $charge;
744
                my $item = $self->item;
743
                my $item = $self->item;
745
                my $branchcode = C4::Reserves::GetReservesControlBranch($item->unblessed, $self->borrower->unblessed);
744
                my $charge = Koha::CirculationRules->get_effective_expire_reserves_charge(
746
747
                my $rule = Koha::CirculationRules->get_effective_rule(
748
                    {
745
                    {
746
                        itemtype => $item->effective_itemtype,
747
                        branchcode => C4::Reserves::GetReservesControlBranch($item->unblessed, $self->borrower->unblessed),
749
                        categorycode => $self->borrower->categorycode,
748
                        categorycode => $self->borrower->categorycode,
750
                        itemtype     => $item->effective_itemtype,
751
                        branchcode   => $branchcode,
752
                        rule_name    => 'expire_reserves_charge',
753
                    }
749
                    }
754
                );
750
                );
755
                $charge = $rule ? $rule->rule_value : C4::Context->preference("ExpireReservesMaxPickUpDelayCharge");
756
751
757
                my $account =
752
                my $account =
758
                  Koha::Account->new( { patron_id => $self->borrowernumber } );
753
                  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 729-734 subtest 'get_effective_daysmode' => sub { Link Here
729
    $schema->storage->txn_rollback;
729
    $schema->storage->txn_rollback;
730
};
730
};
731
731
732
subtest 'get_effective_expire_reserves_charge' => sub {
733
    plan tests => 4;
734
735
    $schema->storage->txn_begin;
736
737
    Koha::CirculationRules->search({ rule_name => 'expire_reserves_charge' })->delete;
738
739
    t::lib::Mocks::mock_preference( 'ExpireReservesMaxPickUpDelayCharge', 10 );
740
741
    is(
742
        Koha::CirculationRules->get_effective_expire_reserves_charge(
743
            {
744
                itemtype     => undef,
745
                branchcode   => undef,
746
                categorycode => undef,
747
            }
748
        ),
749
        '10',
750
        'use the default pref value as the circ rule does not exist'
751
    );
752
753
    Koha::CirculationRules->set_rule(
754
        {
755
            branchcode   => '*',
756
            categorycode => '*',
757
            itemtype     => '*',
758
            rule_name    => 'expire_reserves_charge',
759
            rule_value   => '20'
760
        }
761
    );
762
763
    is(
764
        Koha::CirculationRules->get_effective_expire_reserves_charge(
765
            {
766
                categorycode => undef,
767
                itemtype     => undef,
768
                branchcode   => undef
769
            }
770
        ),
771
        '20',
772
        "use the value from the circ rules"
773
    );
774
775
    t::lib::Mocks::mock_preference( 'ExpireReservesMaxPickUpDelayCharge', 30 );
776
777
    Koha::CirculationRules->set_rule(
778
        {
779
            branchcode   => '*',
780
            categorycode => '*',
781
            itemtype     => '*',
782
            rule_name    => 'expire_reserves_charge',
783
            rule_value   => undef
784
        }
785
    );
786
787
    is(
788
        Koha::CirculationRules->get_effective_expire_reserves_charge(
789
            {
790
                categorycode => undef,
791
                itemtype     => undef,
792
                branchcode   => undef
793
            }
794
        ),
795
        '30',
796
        "use the default pref value for as the circ rule has undefined value"
797
    );
798
799
    Koha::CirculationRules->set_rule(
800
        {
801
            branchcode   => '*',
802
            categorycode => '*',
803
            itemtype     => '*',
804
            rule_name    => 'expire_reserves_charge',
805
            rule_value   => '0'
806
        }
807
    );
808
809
    is(
810
        Koha::CirculationRules->get_effective_expire_reserves_charge(
811
            {
812
                categorycode => undef,
813
                itemtype     => undef,
814
                branchcode   => undef
815
            }
816
        ),
817
        '0',
818
        "use the value from the circ rules for even though it's 0"
819
    );
820
821
    $schema->storage->txn_rollback;
822
};
823
732
subtest 'get_lostreturn_policy() tests' => sub {
824
subtest 'get_lostreturn_policy() tests' => sub {
733
    plan tests => 7;
825
    plan tests => 7;
734
826
735
- 

Return to bug 25711