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

(-)a/Koha/CirculationRules.pm (+28 lines)
Lines 668-673 sub get_effective_daysmode { Link Here
668
668
669
}
669
}
670
670
671
=head3 get_effective_expire_reserves_charge
672
673
Return the value for expire_reserves_charge defined in the circulation rules.
674
If not defined (or empty string), the value of the system preference ExpireReservesMaxPickUpDelayCharge is returned
675
676
=cut
677
678
sub get_effective_expire_reserves_charge {
679
    my ( $class, $params ) = @_;
680
681
    my $itemtype     = $params->{itemtype};
682
    my $branchcode   = $params->{branchcode};
683
    my $categorycode = $params->{categorycode};
684
685
    my $expire_reserves_charge_rule = $class->get_effective_rule(
686
        {
687
            itemtype     => $itemtype,
688
            branchcode   => $branchcode,
689
            categorycode => $categorycode,
690
            rule_name    => 'expire_reserves_charge',
691
        }
692
    );
693
694
    # return the rule value (incl. 0) if rule found so there's an object in the variable,
695
    # or return default value from sysprefs when rule wasn't found and there's undef
696
    return $expire_reserves_charge_rule ? $expire_reserves_charge_rule->rule_value : C4::Context->preference("ExpireReservesMaxPickUpDelayCharge");
697
698
}
671
699
672
=head3 type
700
=head3 type
673
701
(-)a/Koha/Hold.pm (-8 / +3 lines)
Lines 697-715 sub cancel { Link Here
697
697
698
            # and, if desired, charge a cancel fee
698
            # and, if desired, charge a cancel fee
699
            if ( $params->{'charge_cancel_fee'} ) {
699
            if ( $params->{'charge_cancel_fee'} ) {
700
                my $charge;
701
                my $item = $self->item;
700
                my $item = $self->item;
702
                my $branchcode = C4::Reserves::GetReservesControlBranch($item->unblessed, $self->borrower->unblessed);
701
                my $charge = Koha::CirculationRules->get_effective_expire_reserves_charge(
703
704
                my $rule = Koha::CirculationRules->get_effective_rule(
705
                    {
702
                    {
703
                        itemtype => $item->effective_itemtype,
704
                        branchcode => C4::Reserves::GetReservesControlBranch($item->unblessed, $self->borrower->unblessed),
706
                        categorycode => $self->borrower->categorycode,
705
                        categorycode => $self->borrower->categorycode,
707
                        itemtype     => $item->effective_itemtype,
708
                        branchcode   => $branchcode,
709
                        rule_name    => 'expire_reserves_charge',
710
                    }
706
                    }
711
                );
707
                );
712
                $charge = $rule ? $rule->rule_value : C4::Context->preference("ExpireReservesMaxPickUpDelayCharge");
713
708
714
                my $account =
709
                my $account =
715
                  Koha::Account->new( { patron_id => $self->borrowernumber } );
710
                  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