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

(-)a/C4/Reserves.pm (-4 / +8 lines)
Lines 764-782 SELECT COUNT(*) FROM reserves WHERE biblionumber=? AND borrowernumber<>? Link Here
764
    my $dbh = C4::Context->dbh;
764
    my $dbh = C4::Context->dbh;
765
    my ( $fee ) = $dbh->selectrow_array( $borquery, undef, ($borrowernumber) );
765
    my ( $fee ) = $dbh->selectrow_array( $borquery, undef, ($borrowernumber) );
766
    my $hold_fee_mode = C4::Context->preference('HoldFeeMode') || 'not_always';
766
    my $hold_fee_mode = C4::Context->preference('HoldFeeMode') || 'not_always';
767
    if( $fee and $fee > 0 and $hold_fee_mode eq 'not_always' ) {
767
    if( $fee and $fee > 0 and ( $hold_fee_mode eq 'not_always' or $hold_fee_mode eq 'issued_or_reserved' ) ) {
768
        # This is a reconstruction of the old code:
768
        # This is a reconstruction of the old code:
769
        # Compare number of items with items issued, and optionally check holds
769
        # Compare number of items with items issued, and optionally check holds
770
        # If not all items are issued and there are no holds: charge no fee
770
        # not_always = If not all items are issued and there are no holds: charge no fee
771
        # issued_or_reserved = If all items are issued, OR there are holds: charge fee
771
        # NOTE: Lost, damaged, not-for-loan, etc. are just ignored here
772
        # NOTE: Lost, damaged, not-for-loan, etc. are just ignored here
772
        my ( $notissued, $reserved );
773
        my ( $notissued, $reserved );
773
        ( $notissued ) = $dbh->selectrow_array( $issue_qry, undef,
774
        ( $notissued ) = $dbh->selectrow_array( $issue_qry, undef,
774
            ( $biblionumber ) );
775
            ( $biblionumber ) );
775
        if( $notissued == 0 ) {
776
        if( $notissued == 0 or $hold_fee_mode eq 'issued_or_reserved' ) {
776
            # all items are issued
777
            # all items are issued
777
            ( $reserved ) = $dbh->selectrow_array( $holds_qry, undef,
778
            ( $reserved ) = $dbh->selectrow_array( $holds_qry, undef,
778
                ( $biblionumber, $borrowernumber ) );
779
                ( $biblionumber, $borrowernumber ) );
779
            $fee = 0 if $reserved == 0;
780
            if ( $reserved == 0 and $hold_fee_mode eq 'not_always' ) {
781
                # no reserves are placed
782
                $fee = 0;
783
            }
780
        } else {
784
        } else {
781
            $fee = 0;
785
            $fee = 0;
782
        }
786
        }
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (+1 lines)
Lines 1124-1129 Circulation: Link Here
1124
              choices:
1124
              choices:
1125
                  any_time_is_placed: "any time a hold is placed."
1125
                  any_time_is_placed: "any time a hold is placed."
1126
                  not_always: "only if all items are checked out and the record has at least one hold already."
1126
                  not_always: "only if all items are checked out and the record has at least one hold already."
1127
                  issued_or_reserved: "either if all items are checked out, or the record has at least one hold already."
1127
                  any_time_is_collected: "any time a hold is collected."
1128
                  any_time_is_collected: "any time a hold is collected."
1128
        -
1129
        -
1129
            - pref: useDefaultReplacementCost
1130
            - pref: useDefaultReplacementCost
(-)a/t/db_dependent/Reserves/GetReserveFee.t (-5 / +32 lines)
Lines 84-98 my $item2 = $builder->build_sample_item( Link Here
84
);
84
);
85
85
86
subtest 'GetReserveFee' => sub {
86
subtest 'GetReserveFee' => sub {
87
    plan tests => 5;
87
    plan tests => 7;
88
88
89
    C4::Circulation::AddIssue( $patron1, $item1->barcode, '2015-12-31', 0, undef, 0, {} ); # the date does not really matter
89
    C4::Circulation::AddIssue( $patron1, $item1->barcode, '2015-12-31', 0, undef, 0, {} ); # the date does not really matter
90
    C4::Circulation::AddIssue( $patron3, $item2->barcode, '2015-12-31', 0, undef, 0, {} ); # the date does not really matter
91
    my $acc2 = acctlines( $patron2->{borrowernumber} );
90
    my $acc2 = acctlines( $patron2->{borrowernumber} );
92
    my $res1 = addreserve( $patron1->{borrowernumber} );
91
    my $res1 = addreserve( $patron1->{borrowernumber} );
93
92
94
    t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
93
    t::lib::Mocks::mock_preference('HoldFeeMode', 'issued_or_reserved');
95
    my $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->biblionumber );
94
    my $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->biblionumber );
95
    is( int($fee), 2, 'HoldFeeMode=issued_or_reserved, Patron 2 should be charged' );
96
97
    t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
98
    $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->biblionumber );
99
    is( $fee, 0, 'HoldFeeMode=issued_or_reserved, Patron 2 should not be charged' );
100
101
    C4::Circulation::AddIssue( $patron3, $item2->barcode, '2015-12-31', 0, undef, 0, {} ); # the date does not really matter
102
    $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->biblionumber );
96
    is( $fee > 0, 1, 'Patron 2 should be charged cf GetReserveFee' );
103
    is( $fee > 0, 1, 'Patron 2 should be charged cf GetReserveFee' );
97
    C4::Reserves::ChargeReserveFee( $patron2->{borrowernumber}, $fee, $biblio->title );
104
    C4::Reserves::ChargeReserveFee( $patron2->{borrowernumber}, $fee, $biblio->title );
98
    is( acctlines( $patron2->{borrowernumber} ), $acc2 + 1, 'Patron 2 has been charged by ChargeReserveFee' );
105
    is( acctlines( $patron2->{borrowernumber} ), $acc2 + 1, 'Patron 2 has been charged by ChargeReserveFee' );
Lines 139-145 subtest 'Integration with AddReserve' => sub { Link Here
139
    };
146
    };
140
147
141
    subtest 'Items are issued' => sub {
148
    subtest 'Items are issued' => sub {
142
        plan tests => 4;
149
        plan tests => 7;
143
150
144
        $dbh->do( "DELETE FROM issues       WHERE itemnumber=?", undef, $item1->itemnumber);
151
        $dbh->do( "DELETE FROM issues       WHERE itemnumber=?", undef, $item1->itemnumber);
145
        $dbh->do( "DELETE FROM issues       WHERE itemnumber=?", undef, $item2->itemnumber);
152
        $dbh->do( "DELETE FROM issues       WHERE itemnumber=?", undef, $item2->itemnumber);
Lines 151-156 subtest 'Integration with AddReserve' => sub { Link Here
151
        addreserve( $patron1->{borrowernumber} );
158
        addreserve( $patron1->{borrowernumber} );
152
        is( acctlines( $patron1->{borrowernumber} ), 0, 'not_always - Patron should not be charged if items are not all checked out' );
159
        is( acctlines( $patron1->{borrowernumber} ), 0, 'not_always - Patron should not be charged if items are not all checked out' );
153
160
161
        t::lib::Mocks::mock_preference('HoldFeeMode', 'issued_or_reserved');
162
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
163
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
164
        addreserve( $patron1->{borrowernumber} );
165
        is( acctlines( $patron1->{borrowernumber} ), 1, 'issued_or_reserved - Patron should be charged if all the items are not checked out because 1 hold is placed' );
166
167
        t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
154
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
168
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
155
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
169
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
156
        addreserve( $patron3->{borrowernumber} );
170
        addreserve( $patron3->{borrowernumber} );
Lines 163-173 subtest 'Integration with AddReserve' => sub { Link Here
163
        addreserve( $patron1->{borrowernumber} );
177
        addreserve( $patron1->{borrowernumber} );
164
        is( acctlines( $patron1->{borrowernumber} ), 0, 'not_always - Patron should not be charged if all items are checked out but no holds are placed' );
178
        is( acctlines( $patron1->{borrowernumber} ), 0, 'not_always - Patron should not be charged if all items are checked out but no holds are placed' );
165
179
180
        t::lib::Mocks::mock_preference('HoldFeeMode', 'issued_or_reserved');
181
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
182
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
183
        addreserve( $patron1->{borrowernumber} );
184
        is( acctlines( $patron1->{borrowernumber} ), 1, 'issued_or_reserved - Patron should be charged if all items are checked out but no holds are placed' );
185
186
        t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
166
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
187
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
167
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
188
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
168
        addreserve( $patron3->{borrowernumber} );
189
        addreserve( $patron3->{borrowernumber} );
169
        addreserve( $patron1->{borrowernumber} );
190
        addreserve( $patron1->{borrowernumber} );
170
        is( acctlines( $patron1->{borrowernumber} ), 1, 'not_always - Patron should only be charged if all items are checked out and at least 1 hold is already placed' );
191
        is( acctlines( $patron1->{borrowernumber} ), 1, 'not_always - Patron should only be charged if all items are checked out and at least 1 hold is already placed' );
192
193
        t::lib::Mocks::mock_preference('HoldFeeMode', 'issued_or_reserved');
194
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?", undef, $biblio->biblionumber );
195
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->{borrowernumber} );
196
        addreserve( $patron3->{borrowernumber} );
197
        addreserve( $patron1->{borrowernumber} );
198
        is( acctlines( $patron1->{borrowernumber} ), 1, 'issued_or_reserved - Patron should be charged if all items are checked out and at least 1 hold is already placed' );
171
    };
199
    };
172
};
200
};
173
201
174
- 

Return to bug 32142